From 63db34572906971014fa497b8102a31dd842ac18 Mon Sep 17 00:00:00 2001 From: Vitalick Kovalenko Date: Sat, 23 Dec 2023 15:08:00 +0300 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CyberBoom/Controllers/UserController.cs | 21 +++++----- CyberBoom/DbContext/User.cs | 53 ++++++++++++++++--------- CyberBoom/appsettings.json | 1 - 3 files changed, 46 insertions(+), 29 deletions(-) diff --git a/CyberBoom/Controllers/UserController.cs b/CyberBoom/Controllers/UserController.cs index a2a3121..65304c9 100644 --- a/CyberBoom/Controllers/UserController.cs +++ b/CyberBoom/Controllers/UserController.cs @@ -137,7 +137,7 @@ public class MeetingsController : ControllerBase } [HttpGet] - public async Task Get(int id) + public async Task Get(string id) { var meeting = await _applicationContext.Meetings.FirstOrDefaultAsync(s => s.Id == id); @@ -203,7 +203,7 @@ public class ReviewsController : ControllerBase } [HttpGet] - public async Task Get(int id) + public async Task Get(string id) { var review = await _applicationContext.Reviews .Include(c => c.User) @@ -243,14 +243,15 @@ public class QuestionsController : ControllerBase [HttpPost] - public async Task Post([FromBody] Question question) + public async Task Post([FromBody] PostQuestionDto question) { - await _applicationContext.Questions.AddAsync(question); + var dbWr = question.Adapt(); + await _applicationContext.Questions.AddAsync(dbWr); await _applicationContext.SaveChangesAsync(); return Ok(new { - question.Id + dbWr.Id }); } @@ -268,7 +269,7 @@ public class QuestionsController : ControllerBase } [HttpGet] - public async Task Get(int id) + public async Task Get(string id) { var question = await _applicationContext.Questions .FirstAsync(s => s.Id == id); @@ -320,7 +321,7 @@ public class ReactionsController : ControllerBase } [HttpDelete] - public async Task Delete(long id) + public async Task Delete(string id) { var fReview = await _applicationContext.Reactions.FirstAsync(r => r.Id == id); @@ -335,7 +336,7 @@ public class ReactionsController : ControllerBase } [HttpGet] - public async Task Get(int id) + public async Task Get(string id) { var review = await _applicationContext.Reviews .Include(c => c.User) @@ -391,7 +392,7 @@ public class UserWriteToMetingController : ControllerBase } [HttpDelete] - public async Task Delete(long id) + public async Task Delete(string id) { var fReview = await _applicationContext.UserWriteToMetings.FirstAsync(r => r.Id == id); @@ -406,7 +407,7 @@ public class UserWriteToMetingController : ControllerBase } [HttpGet] - public async Task Get(int id) + public async Task Get(string id) { var review = await _applicationContext.UserWriteToMetings .FirstAsync(s => s.Id == id); diff --git a/CyberBoom/DbContext/User.cs b/CyberBoom/DbContext/User.cs index 7fc3c5b..7e702a0 100644 --- a/CyberBoom/DbContext/User.cs +++ b/CyberBoom/DbContext/User.cs @@ -1,6 +1,8 @@ using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations.Schema; + public class User : IdentityUser { @@ -63,25 +65,26 @@ public class PostMeetingDto public class UserWriteToMeting { - public long Id { get; set; } + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public String Id { get; set; } = null!; - public string UserId { get; set; } = null!; + public String UserId { get; set; } = null!; - public long MeetingId { get; set; } + public String MeetingId { get; set; } = null!; } public class PostUserWriteToMetingDto { - public string UserId { get; set; } = null!; + public String UserId { get; set; } = null!; - public long MeetingId { get; set; } + public String MeetingId { get; set; } = null!; } public class PutMeetingDto { - public long Id { get; set; } + public String Id { get; set; } = null!; public DateTime Time { get; set; } @@ -116,7 +119,8 @@ public class PutMeetingDto public class Meeting { - public long Id { get; set; } + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public String Id { get; set; } = null!; public DateTime Time { get; set; } @@ -152,9 +156,9 @@ public class Meeting public class PostReviewDto { - public long MeetingId { get; set; } + public String MeetingId { get; set; } = null!; - public string UserId { get; set; } = null!; + public String UserId { get; set; } = null!; public string Text { get; set; } = null!; @@ -169,7 +173,7 @@ public class PostReviewDto public class PutReviewDto { - public long Id { get; set; } + public string Id { get; set; } = null!; public string Text { get; set; } = null!; @@ -181,13 +185,24 @@ public class PutReviewDto } +public class PostQuestionDto +{ + public string Text { get; set; } = null!; + + public string MeetingId { get; set; } = null!; + + public string UserId { get; set; } = null!; +} + + public class Question { - public long Id { get; set; } + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public string Id { get; set; } = null!; public string Text { get; set; } = null!; - public long MeetingId { get; set; } + public string MeetingId { get; set; } = null!; public string UserId { get; set; } = null!; } @@ -195,9 +210,10 @@ public class Question public class Review { - public long Id { get; set; } + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public string Id { get; set; } = null!; - public long MeetingId { get; set; } + public string MeetingId { get; set; } = null!; public User User { get; set; } = null!; @@ -217,7 +233,7 @@ public class Review public class PostReactionDto { - public long QuestionId { get; set; } + public string QuestionId { get; set; } = null!; public string UserId { get; set; } = null!; @@ -228,9 +244,10 @@ public class PostReactionDto public class Reaction { - public long Id { get; set; } + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public string Id { get; set; } = null!; - public long QuestionId { get; set; } + public string QuestionId { get; set; } = null!; public string UserId { get; set; } = null!; @@ -265,7 +282,7 @@ public class ApplicationContext : IdentityDbContext builder.Entity().HasMany().WithOne(r => r.User).HasForeignKey(c => c.UserId); builder.Entity().HasMany().WithOne().HasForeignKey(c => c.UserId); - builder.Entity().HasMany().WithOne().HasForeignKey(c => c.UserId); + builder.Entity().HasOne().WithMany().HasForeignKey(c => c.UserId); builder.Entity().HasMany().WithOne().HasForeignKey(c => c.QuestionId); diff --git a/CyberBoom/appsettings.json b/CyberBoom/appsettings.json index 9f85f41..4cf5405 100644 --- a/CyberBoom/appsettings.json +++ b/CyberBoom/appsettings.json @@ -6,7 +6,6 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*", "CONNECTION_STRING": "Host=localhost; Database=CyberBoomWellBeing; Username=postgres; Password=supper_password_123"