фиксы
This commit is contained in:
		| @@ -37,15 +37,16 @@ public class UsersController : ControllerBase | |||||||
|             Fio = user.Fio, |             Fio = user.Fio, | ||||||
|             Specialities = user.Specialities, |             Specialities = user.Specialities, | ||||||
|             TelegramBotUrl = user.TelegramBotUrl, |             TelegramBotUrl = user.TelegramBotUrl, | ||||||
|  |             UserName = user.Username | ||||||
|         }; |         }; | ||||||
|         await _userManager.CreateAsync(userWr); |         var result = await _userManager.CreateAsync(userWr); | ||||||
|  |         if(result.Succeeded) | ||||||
|         return Ok( |             return Ok( | ||||||
|             new { |                 new { | ||||||
|                 userWr.Id |                     userWr.Id | ||||||
|             } |                 } | ||||||
|         ); |             ); | ||||||
|  |         return BadRequest(result.Errors); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // [HttpGet("google-auth")] |     // [HttpGet("google-auth")] | ||||||
| @@ -205,12 +206,14 @@ public class ReviewsController : ControllerBase | |||||||
|     [HttpGet] |     [HttpGet] | ||||||
|     public async Task<IActionResult> Get(string id) |     public async Task<IActionResult> Get(string id) | ||||||
|     { |     { | ||||||
|         var review = await _applicationContext.Reviews |         var review = await _applicationContext.Reviews.FirstAsync(s => s.Id == id); | ||||||
|             .Include(c => c.User) |  | ||||||
|             .FirstAsync(s => s.Id == id); |  | ||||||
|  |  | ||||||
|  |         var user = await _applicationContext.Users.FirstAsync(s => s.Id == review.UserId); | ||||||
|          |          | ||||||
|         return Ok(review); |         return Ok(new { | ||||||
|  |             review, | ||||||
|  |             user | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|      |      | ||||||
| @@ -222,8 +225,12 @@ public class ReviewsController : ControllerBase | |||||||
|             .Skip(offset) |             .Skip(offset) | ||||||
|             .Take(limit); |             .Take(limit); | ||||||
|  |  | ||||||
|  |         // var userIds = reviews.Select(u => u.UserId).ToArray(); | ||||||
|  |         // var users = _applicationContext.Users.Where(u => userIds.Contains(u.Id)); | ||||||
|          |          | ||||||
|         return Ok(reviews); |         return Ok( | ||||||
|  |             reviews | ||||||
|  |         ); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -256,7 +263,7 @@ public class QuestionsController : ControllerBase | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     [HttpPut] |     [HttpPut] | ||||||
|     public async Task<IActionResult> Put([FromBody]Question question) |     public async Task<IActionResult> Put([FromBody]PutQuestionDto question) | ||||||
|     { |     { | ||||||
|          |          | ||||||
|         var fReview = await _applicationContext.Questions.FirstAsync(r => r.Id == question.Id); |         var fReview = await _applicationContext.Questions.FirstAsync(r => r.Id == question.Id); | ||||||
| @@ -283,6 +290,7 @@ public class QuestionsController : ControllerBase | |||||||
|     public IActionResult GetList(int offset, int limit) |     public IActionResult GetList(int offset, int limit) | ||||||
|     { |     { | ||||||
|         var questions = _applicationContext.Questions |         var questions = _applicationContext.Questions | ||||||
|  |             .Include(c => c.User) | ||||||
|             .Skip(offset) |             .Skip(offset) | ||||||
|             .Take(limit); |             .Take(limit); | ||||||
|  |  | ||||||
| @@ -339,11 +347,13 @@ public class ReactionsController : ControllerBase | |||||||
|     public async Task<IActionResult> Get(string id) |     public async Task<IActionResult> Get(string id) | ||||||
|     { |     { | ||||||
|         var review = await _applicationContext.Reviews |         var review = await _applicationContext.Reviews | ||||||
|             .Include(c => c.User) |  | ||||||
|             .FirstAsync(s => s.Id == id); |             .FirstAsync(s => s.Id == id); | ||||||
|  |  | ||||||
|          |         var user = await _applicationContext.Users.FirstAsync(s => s.Id == review.UserId); | ||||||
|         return Ok(review); |         return Ok(new { | ||||||
|  |             review, | ||||||
|  |             user | ||||||
|  |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|      |      | ||||||
| @@ -351,12 +361,17 @@ public class ReactionsController : ControllerBase | |||||||
|     public IActionResult GetList(int offset, int limit) |     public IActionResult GetList(int offset, int limit) | ||||||
|     { |     { | ||||||
|         var reviews = _applicationContext.Reviews |         var reviews = _applicationContext.Reviews | ||||||
|             .Include(c => c.User) |  | ||||||
|             .Skip(offset) |             .Skip(offset) | ||||||
|             .Take(limit); |             .Take(limit); | ||||||
|  |  | ||||||
|          |          | ||||||
|         return Ok(reviews); |         var users = _applicationContext.Users.Where(u => reviews.Select(u => u.UserId).Contains(u.Id)); | ||||||
|  |          | ||||||
|  |         return Ok( | ||||||
|  |             reviews.Select(s => new { | ||||||
|  |                 review = s, | ||||||
|  |                 user = users.First(u => u.Id == s.UserId) | ||||||
|  |             }) | ||||||
|  |         ); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -195,6 +195,13 @@ public class PostQuestionDto | |||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | public class PutQuestionDto | ||||||
|  | { | ||||||
|  |     public string Id { get; set; } = null!; | ||||||
|  |  | ||||||
|  |     public string Text { get; set; } = null!; | ||||||
|  | } | ||||||
|  |  | ||||||
| public class Question | public class Question | ||||||
| { | { | ||||||
|     [DatabaseGenerated(DatabaseGeneratedOption.Identity)] |     [DatabaseGenerated(DatabaseGeneratedOption.Identity)] | ||||||
| @@ -205,6 +212,8 @@ public class Question | |||||||
|     public string MeetingId { get; set; } = null!; |     public string MeetingId { get; set; } = null!; | ||||||
|  |  | ||||||
|     public string UserId { get; set; } = null!; |     public string UserId { get; set; } = null!; | ||||||
|  |  | ||||||
|  |     public User User { get; set; } = null!; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -214,8 +223,6 @@ public class Review | |||||||
|     public string Id { get; set; } = null!; |     public string Id { get; set; } = null!; | ||||||
|  |  | ||||||
|     public string MeetingId { get; set; } = null!; |     public string MeetingId { get; set; } = null!; | ||||||
|  |  | ||||||
|     public User User { get; set; } = null!; |  | ||||||
|      |      | ||||||
|     public string UserId { get; set; } = null!; |     public string UserId { get; set; } = null!; | ||||||
|  |  | ||||||
| @@ -223,6 +230,8 @@ public class Review | |||||||
|  |  | ||||||
|     public int Score { get; set; } = 0; |     public int Score { get; set; } = 0; | ||||||
|  |  | ||||||
|  |     public User User { get; set; } = null!; | ||||||
|  |  | ||||||
|     DateTime _date; |     DateTime _date; | ||||||
|      |      | ||||||
|     public DateTime Date { get => _date; set => _date = value.ToUniversalTime(); } |     public DateTime Date { get => _date; set => _date = value.ToUniversalTime(); } | ||||||
| @@ -280,13 +289,18 @@ public class ApplicationContext : IdentityDbContext<User> | |||||||
|         builder.Entity<Meeting>().HasMany<Review>().WithOne().HasForeignKey(c => c.MeetingId); |         builder.Entity<Meeting>().HasMany<Review>().WithOne().HasForeignKey(c => c.MeetingId); | ||||||
|         builder.Entity<Meeting>().HasMany<Question>().WithOne().HasForeignKey(c => c.MeetingId); |         builder.Entity<Meeting>().HasMany<Question>().WithOne().HasForeignKey(c => c.MeetingId); | ||||||
|  |  | ||||||
|         builder.Entity<User>().HasMany<Review>().WithOne(r => r.User).HasForeignKey(c => c.UserId); |          | ||||||
|         builder.Entity<User>().HasMany<Reaction>().WithOne().HasForeignKey(c => c.UserId); |          | ||||||
|         builder.Entity<Question>().HasOne<Meeting>().WithMany().HasForeignKey(c => c.UserId); |          | ||||||
|  |         builder.Entity<Reaction>().HasOne<User>().WithMany().HasForeignKey(c => c.UserId); | ||||||
|  |         builder.Entity<Review>().HasOne(c => c.User).WithMany().HasForeignKey(c => c.UserId); | ||||||
|  |  | ||||||
|         builder.Entity<Question>().HasMany<Reaction>().WithOne().HasForeignKey(c => c.QuestionId); |         builder.Entity<Question>().HasOne<Meeting>().WithMany().HasForeignKey(c => c.MeetingId); | ||||||
|  |         builder.Entity<Question>().HasOne(c => c.User).WithMany().HasForeignKey(c => c.UserId); | ||||||
|  |          | ||||||
|  |         builder.Entity<Reaction>().HasOne<Question>().WithMany().HasForeignKey(c => c.QuestionId); | ||||||
|  |  | ||||||
|         builder.Entity<Meeting>().HasMany<UserWriteToMeting>().WithOne().HasForeignKey(c => c.MeetingId); |         builder.Entity<Meeting>().HasMany<UserWriteToMeting>().WithOne().HasForeignKey(c => c.MeetingId); | ||||||
|         builder.Entity<User>().HasMany<UserWriteToMeting>().WithOne().HasForeignKey(c => c.UserId); |         builder.Entity<UserWriteToMeting>().HasOne<User>().WithMany().HasForeignKey(c => c.UserId); | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user