This commit is contained in:
2025-02-02 13:26:44 +02:00
parent d2a32d35f4
commit 2e8c61f3e3
24 changed files with 589 additions and 565 deletions

View File

@@ -1,6 +1,7 @@
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using survey_beta.DTOs.Response; using survey_beta.DTOs.Response;
using survey_beta.Models;
namespace survey_beta.Controllers namespace survey_beta.Controllers
{ {
@@ -16,7 +17,7 @@ namespace survey_beta.Controllers
} }
[HttpPost("add")] [HttpPost("add")]
public IActionResult AddResponse([FromBody] CreatorResponseDto request) public IActionResult AddResponse([FromBody] ResponseDto request)
{ {
try try
{ {

View File

@@ -50,7 +50,7 @@ public class SurveyController : ControllerBase
return Ok(result); return Ok(result);
} }
[Authorize] //[Authorize]
[HttpPost] [HttpPost]
public async Task<ActionResult<Survey>> CreateSurvey([FromBody] CreateSurveyDto request) public async Task<ActionResult<Survey>> CreateSurvey([FromBody] CreateSurveyDto request)
{ {
@@ -65,7 +65,7 @@ public class SurveyController : ControllerBase
} }
} }
[Authorize] //[Authorize]
[HttpPut] [HttpPut]
public async Task<IActionResult> UpdateSurvey([FromBody] UpdateSurveyDto request) public async Task<IActionResult> UpdateSurvey([FromBody] UpdateSurveyDto request)
{ {
@@ -74,7 +74,7 @@ public class SurveyController : ControllerBase
return NoContent(); return NoContent();
} }
[Authorize] //[Authorize]
[HttpPatch("publish/{id}")] [HttpPatch("publish/{id}")]
public async Task<IActionResult> PublishSurvey(string id) public async Task<IActionResult> PublishSurvey(string id)
{ {
@@ -83,7 +83,7 @@ public class SurveyController : ControllerBase
return NoContent(); return NoContent();
} }
[Authorize] //[Authorize]
[HttpPatch("unpublish/{id}")] [HttpPatch("unpublish/{id}")]
public async Task<IActionResult> UnpublishSurvey(string id) public async Task<IActionResult> UnpublishSurvey(string id)
{ {
@@ -92,7 +92,7 @@ public class SurveyController : ControllerBase
return NoContent(); return NoContent();
} }
[Authorize] //[Authorize]
[HttpDelete("{id}")] [HttpDelete("{id}")]
public async Task<IActionResult> DeleteSurvey(string id) public async Task<IActionResult> DeleteSurvey(string id)
{ {

View File

@@ -41,7 +41,7 @@ public class UserController : ControllerBase
return Unauthorized(ex.Message); return Unauthorized(ex.Message);
} }
} }
[Authorize] //[Authorize]
[HttpGet("{id}")] [HttpGet("{id}")]
public async Task<IActionResult> GetUserById(string id) public async Task<IActionResult> GetUserById(string id)
{ {
@@ -55,7 +55,7 @@ public class UserController : ControllerBase
return NotFound(new { message = ex.Message }); return NotFound(new { message = ex.Message });
} }
} }
[Authorize] //[Authorize]
[HttpGet("by-username/{username}")] [HttpGet("by-username/{username}")]
public async Task<IActionResult> GetUserByUsername(string username) public async Task<IActionResult> GetUserByUsername(string username)
{ {
@@ -69,7 +69,7 @@ public class UserController : ControllerBase
return NotFound(new { message = ex.Message }); return NotFound(new { message = ex.Message });
} }
} }
[Authorize] //[Authorize]
[HttpGet("All-Users")] [HttpGet("All-Users")]
public async Task<IActionResult> GetAllUsers() public async Task<IActionResult> GetAllUsers()
{ {

View File

@@ -4,7 +4,7 @@
{ {
public string IpAddress { get; set; } public string IpAddress { get; set; }
public string SurveyId { get; set; } public string SurveyId { get; set; }
public string Id { get; set; } public string Id { get; set; } = Guid.NewGuid().ToString();
public string? Answer { get; set; } public string? Answer { get; set; }
} }
} }

View File

@@ -2,6 +2,7 @@
{ {
public class AnswerDto public class AnswerDto
{ {
public string Id { get; set; } = Guid.NewGuid().ToString();
public string Question { get; set; } public string Question { get; set; }
public string AnswerText { get; set; } public string AnswerText { get; set; }
public string ResponseId { get; set; } public string ResponseId { get; set; }

View File

@@ -2,7 +2,7 @@
{ {
public class QuestionDto public class QuestionDto
{ {
public string Id { get; set; } public string Id { get; set; } = Guid.NewGuid().ToString();
public string Content { get; set; } public string Content { get; set; }
public string SurveyId { get; set; } public string SurveyId { get; set; }
public List<ChoiceDto> Choices { get; set; } public List<ChoiceDto> Choices { get; set; }

View File

@@ -2,7 +2,7 @@
{ {
public class ResponseDto public class ResponseDto
{ {
public string Id { get; set; } public string Id { get; set; } = Guid.NewGuid().ToString();
public string IpAddress { get; set; } public string IpAddress { get; set; }
public string SurveyId { get; set; } public string SurveyId { get; set; }
public string Answer { get; set; } public string Answer { get; set; }

View File

@@ -2,7 +2,7 @@
{ {
public class SurveyDto public class SurveyDto
{ {
public string Id { get; set; } public string Id { get; set; } = Guid.NewGuid().ToString();
public string Title { get; set; } public string Title { get; set; }
public string Description { get; set; } public string Description { get; set; }
public string Category { get; set; } public string Category { get; set; }

View File

@@ -3,8 +3,8 @@ namespace survey_beta.DTOs.Response
public class CreatorResponseDto public class CreatorResponseDto
{ {
public string Id { get; set; } public string Id { get; set; }
public string IpAddress { get; set; } // public string? IpAddress { get; set; }
public string SurveyId { get; set; } public string SurveyId { get; set; }
public List<AnswerRequest> Answers { get; set; } //public List<AnswerRequest> Answers { get; set; }
} }
} }

View File

@@ -5,5 +5,6 @@
public string Id { get; set; } public string Id { get; set; }
public string IpAddress { get; set; } public string IpAddress { get; set; }
public string SurveyId { get; set; } public string SurveyId { get; set; }
public string Response { get; set; }
} }
} }

View File

@@ -2,9 +2,9 @@
{ {
public class SurveyStats public class SurveyStats
{ {
public string SurveyId { get; set; } public string? SurveyId { get; set; }
public int TotalResponses { get; set; } public int TotalResponses { get; set; }
public Dictionary<string, int> AnswerFrequency { get; set; } public Dictionary<string, int>? AnswerFrequency { get; set; }
public Dictionary<string, int> QuestionFrequency { get; set; } public Dictionary<string, int>? QuestionFrequency { get; set; }
} }
} }

View File

@@ -11,7 +11,7 @@ namespace survey_beta.Mappers
return new ResponseDto return new ResponseDto
{ {
Id = response.Id, Id = response.Id,
IpAddress = response.IpAddress, // IpAddress = response.IpAddress,
SurveyId = response.SurveyId SurveyId = response.SurveyId
}; };
} }
@@ -21,7 +21,7 @@ namespace survey_beta.Mappers
return new Response return new Response
{ {
Id = Guid.NewGuid().ToString(), Id = Guid.NewGuid().ToString(),
IpAddress = dto.IpAddress, //IpAddress = dto.IpAddress,
SurveyId = dto.SurveyId SurveyId = dto.SurveyId
}; };
} }

View File

@@ -1,6 +0,0 @@
namespace survey_beta.Mappers
{
public class UserInfoDto
{
}
}

View File

@@ -1,509 +1 @@
// <auto-generated /> 
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using survey_beta.DataBaseContext;
#nullable disable
namespace survey_beta.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250131221823_responses")]
partial class responses
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ChoiceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ResponseId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ChoiceId");
b.HasIndex("QuestionId");
b.HasIndex("ResponseId");
b.ToTable("Answers");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Letter")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("QuestionId");
b.ToTable("Choices");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Text")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Questions");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Responses");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("AuthorId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Category")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime?>("ExpirationDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.ToTable("Surveys");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("Fullname")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.HasOne("survey_beta.Models.Choice", "Choice")
.WithMany()
.HasForeignKey("ChoiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany()
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Response", "Response")
.WithMany("Answers")
.HasForeignKey("ResponseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Choice");
b.Navigation("Question");
b.Navigation("Response");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany("Choices")
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Question");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Questions")
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany()
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.HasOne("survey_beta.Models.User", "Author")
.WithMany("Surveys")
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Author");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Navigation("Choices");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Navigation("Answers");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Navigation("Questions");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Navigation("Surveys");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,491 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using survey_beta.DataBaseContext;
#nullable disable
namespace survey_beta.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250202101403_reomveIp")]
partial class reomveIp
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "9.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ChoiceId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("QuestionId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ResponseId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ChoiceId");
b.HasIndex("QuestionId");
b.HasIndex("ResponseId");
b.ToTable("Answers");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.HasColumnType("text");
b.Property<string>("Letter")
.HasColumnType("text");
b.Property<string>("QuestionId")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("QuestionId");
b.ToTable("Choices");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("Content")
.HasColumnType("text");
b.Property<string>("SurveyId")
.HasColumnType("text");
b.Property<string>("Text")
.HasColumnType("text");
b.Property<string>("Type")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Questions");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("SurveyId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("SurveyId");
b.ToTable("Responses");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("AuthorId")
.HasColumnType("text");
b.Property<string>("Category")
.HasColumnType("text");
b.Property<string>("Description")
.HasColumnType("text");
b.Property<DateTime?>("ExpirationDate")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsPublished")
.HasColumnType("boolean");
b.Property<string>("Title")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.ToTable("Surveys");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("Fullname")
.IsRequired()
.HasColumnType("text");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("survey_beta.Models.User", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("survey_beta.Models.Answer", b =>
{
b.HasOne("survey_beta.Models.Choice", "Choice")
.WithMany()
.HasForeignKey("ChoiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany()
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("survey_beta.Models.Response", "Response")
.WithMany("Answers")
.HasForeignKey("ResponseId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Choice");
b.Navigation("Question");
b.Navigation("Response");
});
modelBuilder.Entity("survey_beta.Models.Choice", b =>
{
b.HasOne("survey_beta.Models.Question", "Question")
.WithMany("Choices")
.HasForeignKey("QuestionId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Question");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany("Questions")
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.HasOne("survey_beta.Models.Survey", "Survey")
.WithMany()
.HasForeignKey("SurveyId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Survey");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.HasOne("survey_beta.Models.User", "Author")
.WithMany("Surveys")
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade);
b.Navigation("Author");
});
modelBuilder.Entity("survey_beta.Models.Question", b =>
{
b.Navigation("Choices");
});
modelBuilder.Entity("survey_beta.Models.Response", b =>
{
b.Navigation("Answers");
});
modelBuilder.Entity("survey_beta.Models.Survey", b =>
{
b.Navigation("Questions");
});
modelBuilder.Entity("survey_beta.Models.User", b =>
{
b.Navigation("Surveys");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace survey_beta.Migrations
{
/// <inheritdoc />
public partial class reomveIp : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IpAddress",
table: "Responses");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "IpAddress",
table: "Responses",
type: "text",
nullable: false,
defaultValue: "");
}
}
}

View File

@@ -235,10 +235,6 @@ namespace survey_beta.Migrations
b.Property<DateTime>("CreatedAt") b.Property<DateTime>("CreatedAt")
.HasColumnType("timestamp with time zone"); .HasColumnType("timestamp with time zone");
b.Property<string>("IpAddress")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurveyId") b.Property<string>("SurveyId")
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasColumnType("text");

View File

@@ -4,12 +4,12 @@ namespace survey_beta.Models
{ {
public class Answer public class Answer
{ {
public string Id { get; set; } = Guid.NewGuid().ToString(); public string? Id { get; set; } = Guid.NewGuid().ToString();
public string ResponseId { get; set; } public string? ResponseId { get; set; }
public Response Response { get; set; } public Response? Response { get; set; }
public string QuestionId { get; set; } public string? QuestionId { get; set; }
public Question Question { get; set; } public Question? Question { get; set; }
public string ChoiceId { get; set; } public string? ChoiceId { get; set; }
public Choice Choice { get; set; } public Choice? Choice { get; set; }
} }
} }

View File

@@ -6,9 +6,9 @@ namespace survey_beta.Models
public class Response public class Response
{ {
public string Id { get; set; } = Guid.NewGuid().ToString(); public string Id { get; set; } = Guid.NewGuid().ToString();
public string IpAddress { get; set; } //public string IpAddress { get; set; }
public string SurveyId { get; set; } public string? SurveyId { get; set; }
public Survey Survey { get; set; } public Survey? Survey { get; set; }
public DateTime CreatedAt { get; set; } = DateTime.UtcNow; public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
public ICollection<Answer> Answers { get; set; } = new List<Answer>(); public ICollection<Answer> Answers { get; set; } = new List<Answer>();
} }

View File

@@ -13,6 +13,6 @@ namespace survey_beta.Models
public bool IsPublished { get; set; } public bool IsPublished { get; set; }
public string? AuthorId { get; set; } public string? AuthorId { get; set; }
public User? Author { get; set; } public User? Author { get; set; }
public ICollection<Question> Questions { get; set; } public ICollection<Question>? Questions { get; set; }
} }
} }

View File

@@ -23,7 +23,7 @@
"commandName": "Project", "commandName": "Project",
"dotnetRunMessages": true, "dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
"launchUrl": "weatherforecast", "launchUrl": "swagger",
"applicationUrl": "https://localhost:7002;http://localhost:5036", "applicationUrl": "https://localhost:7002;http://localhost:5036",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"

View File

@@ -1,13 +1,9 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using survey_beta.DataBaseContext; using survey_beta.DataBaseContext;
using survey_beta.DTOs.Default;
using survey_beta.DTOs.Response; using survey_beta.DTOs.Response;
using survey_beta.Models; using survey_beta.Models;
using System;
using System.Collections.Generic;
using System.Linq;
public class ResponsesService public class ResponsesService
{ {
private readonly AppDbContext _context; private readonly AppDbContext _context;
private readonly AnalyticsServices _analyticsService; private readonly AnalyticsServices _analyticsService;
@@ -17,23 +13,27 @@ public class ResponsesService
_context = context; _context = context;
_analyticsService = analyticsService; _analyticsService = analyticsService;
} }
public void AddResponse(CreatorResponseDto request)
public void AddResponse(ResponseDto request)
{ {
var answers = request.Answers.Select(a => new AnswerDto
{
Question = a.Question,
AnswerText = a.AnswerText
}).ToList();
var response = new Response var response = new Response
{ {
SurveyId = request.SurveyId, SurveyId = request.SurveyId,
Id = request.Id, Id = request.Id,
CreatedAt = DateTime.UtcNow CreatedAt = DateTime.UtcNow,
// CreatedAt = DateTime.UtcNow,
//IpAddress= request.IpAddress
//Answers = request.Answers.Select(a => new Answer
//{
// }).ToList()
}; };
_context.Responses.Add(response); _context.Responses.Add(response);
_context.SaveChanges(); _context.SaveChanges();
} }
public List<Response> GetSurveyResponses(string surveyId) public List<Response> GetSurveyResponses(string surveyId)
{ {
return _context.Responses return _context.Responses

View File

@@ -1,7 +1,10 @@
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using survey_beta.DataBaseContext; using survey_beta.DataBaseContext;
using survey_beta.DTOs.Create; using survey_beta.DTOs.Create;
using survey_beta.DTOs.Default;
using survey_beta.DTOs.Response;
using survey_beta.DTOs.Update; using survey_beta.DTOs.Update;
using survey_beta.Models; using survey_beta.Models;
using System.Security.Claims; using System.Security.Claims;
@@ -9,10 +12,12 @@ using System.Security.Claims;
public class SurveyService public class SurveyService
{ {
private readonly AppDbContext _context; private readonly AppDbContext _context;
private readonly ResponsesService _responsesService;
public SurveyService(AppDbContext context) public SurveyService(AppDbContext context, ResponsesService responsesService)
{ {
_context = context; _context = context;
_responsesService = responsesService;
} }
public async Task<Survey> GetSurveyByIdAsync(string id) public async Task<Survey> GetSurveyByIdAsync(string id)
@@ -89,4 +94,18 @@ public class SurveyService
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return true; return true;
} }
public async Task<bool> SubmitSurveyResponseAsync(string surveyId, survey_beta.DTOs.Response.ResponseDto responseDto)
{
var survey = await _context.Surveys
.Include(s => s.Questions)
.FirstOrDefaultAsync(s => s.Id == surveyId);
if (survey == null)
{
return false;
}
_responsesService.AddResponse(responseDto);
return true;
}
} }

View File

@@ -6,6 +6,6 @@
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"ConnectionStrings": { "ConnectionStrings": {
"DefaultConnection": "Host=localhost;Database=SurveyBeta;Username=postgres;Password=MAJEDali645" "DefaultConnection": "Host=localhost;Database=SurveyBeta;Username=postgres;Password=102030"
} }
} }