добавил логику
This commit is contained in:
		| @@ -34,7 +34,10 @@ public class UsersController : ControllerBase | ||||
|         await user.Avatar.WriteFileToDirectory(); | ||||
|         var userWr = new User { | ||||
|             AvatarUrl = user.Avatar.FileName, | ||||
|             UserName = user.Username | ||||
|             Fio = user.Fio, | ||||
|             Specialities = user.Specialities, | ||||
|             TelegramBotUrl = user.TelegramBotUrl, | ||||
|  | ||||
|         }; | ||||
|         await _userManager.CreateAsync(userWr); | ||||
|  | ||||
| @@ -226,6 +229,69 @@ public class ReviewsController : ControllerBase | ||||
|  | ||||
|  | ||||
|  | ||||
| [ApiController] | ||||
| [Route("/api/[controller]")] | ||||
| public class QuestionsController : ControllerBase | ||||
| { | ||||
|  | ||||
|     private readonly ApplicationContext _applicationContext; | ||||
|  | ||||
|     public QuestionsController(ApplicationContext applicationContext) | ||||
|     { | ||||
|         _applicationContext = applicationContext; | ||||
|     } | ||||
|  | ||||
|  | ||||
|     [HttpPost] | ||||
|     public async Task<IActionResult> Post([FromBody] Question question) | ||||
|     { | ||||
|         await _applicationContext.Questions.AddAsync(question); | ||||
|          | ||||
|         await _applicationContext.SaveChangesAsync(); | ||||
|          | ||||
|         return Ok(new { | ||||
|             question.Id | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     [HttpPut] | ||||
|     public async Task<IActionResult> Put([FromBody]Question question) | ||||
|     { | ||||
|          | ||||
|         var fReview = await _applicationContext.Questions.FirstAsync(r => r.Id == question.Id); | ||||
|          | ||||
|         fReview.Text = question.Text; | ||||
|          | ||||
|         await _applicationContext.SaveChangesAsync(); | ||||
|          | ||||
|         return Ok(); | ||||
|     } | ||||
|  | ||||
|     [HttpGet] | ||||
|     public async Task<IActionResult> Get(int id) | ||||
|     { | ||||
|         var question = await _applicationContext.Questions | ||||
|             .FirstAsync(s => s.Id == id); | ||||
|  | ||||
|          | ||||
|         return Ok(question); | ||||
|     } | ||||
|  | ||||
|      | ||||
|     [HttpGet("list")] | ||||
|     public IActionResult GetList(int offset, int limit) | ||||
|     { | ||||
|         var questions = _applicationContext.Questions | ||||
|             .Skip(offset) | ||||
|             .Take(limit); | ||||
|  | ||||
|          | ||||
|         return Ok(questions); | ||||
|     } | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| [ApiController] | ||||
| [Route("/api/[controller]")] | ||||
| public class ReactionsController : ControllerBase | ||||
|   | ||||
| @@ -5,13 +5,27 @@ using Microsoft.EntityFrameworkCore; | ||||
| public class User : IdentityUser | ||||
| { | ||||
|     public string AvatarUrl { get; set; } = null!; | ||||
|  | ||||
|     public string Fio { get; set; } = null!; | ||||
|  | ||||
|     public string Specialities { get; set; } = null!; | ||||
|  | ||||
|     public string TelegramBotUrl { get; set; } = null!; | ||||
|  | ||||
|     public int Level { get; set; } | ||||
| } | ||||
|  | ||||
| public class UserPost | ||||
| { | ||||
|     public IFormFile Avatar { get; set; } = null!; | ||||
|  | ||||
|     public string Fio { get; set; } = null!; | ||||
|  | ||||
|     public string Username { get; set; } = null!; | ||||
|  | ||||
|     public string Specialities { get; set; } = null!; | ||||
|  | ||||
|     public string TelegramBotUrl { get; set; } = null!; | ||||
| } | ||||
|  | ||||
| public class PostMeetingDto | ||||
| @@ -39,7 +53,11 @@ public class PostMeetingDto | ||||
|  | ||||
|     public string Tags { get; set; } = null!; | ||||
|  | ||||
|     public string VideoUrl { get; set; } = null!; | ||||
|     public string Urls { get; set; } = null!; | ||||
|  | ||||
|     public string PlaceAdress { get; set; } = null!; | ||||
|  | ||||
|     public string Duration { get; set; } = null!; | ||||
| } | ||||
|  | ||||
|  | ||||
| @@ -88,9 +106,14 @@ public class PutMeetingDto | ||||
|  | ||||
|     public string Tags { get; set; } = null!; | ||||
|  | ||||
|     public string VideoUrl { get; set; } = null!; | ||||
|     public string Urls { get; set; } = null!; | ||||
|  | ||||
|     public string PlaceAdress { get; set; } = null!; | ||||
|  | ||||
|     public string Duration { get; set; } = null!; | ||||
| } | ||||
|  | ||||
|  | ||||
| public class Meeting | ||||
| { | ||||
|     public long Id { get; set; } | ||||
| @@ -119,12 +142,11 @@ public class Meeting | ||||
|  | ||||
|     public string Tags { get; set; } = null!; | ||||
|  | ||||
|     public string VideoUrl { get; set; } = null!; | ||||
|     public string Urls { get; set; } = null!; | ||||
|  | ||||
|      | ||||
|     // public string MeetingChatUrl { get; set; } = null!; | ||||
|     public string PlaceAdress { get; set; } = null!; | ||||
|  | ||||
|     // public string SocialUrls { get; set; } = null!; | ||||
|     public string Duration { get; set; } = null!; | ||||
| }    | ||||
|  | ||||
|  | ||||
| @@ -159,6 +181,18 @@ public class PutReviewDto | ||||
| } | ||||
|  | ||||
|  | ||||
| public class Question | ||||
| { | ||||
|     public long Id { get; set; } | ||||
|  | ||||
|     public string Text { get; set; } = null!; | ||||
|  | ||||
|     public long MeetingId { get; set; } | ||||
|  | ||||
|     public string UserId { get; set; } = null!; | ||||
| } | ||||
|  | ||||
|  | ||||
| public class Review | ||||
| { | ||||
|     public long Id { get; set; } | ||||
| @@ -183,30 +217,20 @@ public class Review | ||||
| public class PostReactionDto | ||||
| { | ||||
|  | ||||
|     public long ReviewId { get; set; } | ||||
|     public long QuestionId { get; set; } | ||||
|  | ||||
|     public string UserId { get; set; } = null!; | ||||
|  | ||||
|     public bool IsLike { get; set; } = true; | ||||
| } | ||||
|  | ||||
| public class PutReactionDto | ||||
| { | ||||
|     public long Id { get; set; } | ||||
|  | ||||
|     public long ReviewId { get; set; } | ||||
|  | ||||
|     public string UserId { get; set; } = null!; | ||||
|  | ||||
|     public bool IsLike { get; set; } = true; | ||||
| } | ||||
|  | ||||
|  | ||||
| public class Reaction | ||||
| { | ||||
|     public long Id { get; set; } | ||||
|  | ||||
|     public long ReviewId { get; set; } | ||||
|     public long QuestionId { get; set; } | ||||
|  | ||||
|     public string UserId { get; set; } = null!; | ||||
|  | ||||
| @@ -222,8 +246,11 @@ public class ApplicationContext : IdentityDbContext<User> | ||||
|     public DbSet<Review> Reviews { get; set; } | ||||
|  | ||||
|     public DbSet<Reaction> Reactions { get; set; } | ||||
|      | ||||
|     public DbSet<UserWriteToMeting> UserWriteToMetings { get; set; } | ||||
|  | ||||
|     public DbSet<Question> Questions { get; set; } | ||||
|  | ||||
|     public ApplicationContext(DbContextOptions<ApplicationContext> options) | ||||
|         : base(options) | ||||
|     { | ||||
| @@ -234,9 +261,14 @@ public class ApplicationContext : IdentityDbContext<User> | ||||
|     { | ||||
|         base.OnModelCreating(builder); | ||||
|         builder.Entity<Meeting>().HasMany<Review>().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<Review>().HasMany<Reaction>().WithOne().HasForeignKey(c => c.ReviewId); | ||||
|         builder.Entity<User>().HasMany<Question>().WithOne().HasForeignKey(c => c.UserId); | ||||
|  | ||||
|         builder.Entity<Question>().HasMany<Reaction>().WithOne().HasForeignKey(c => c.QuestionId); | ||||
|  | ||||
|         builder.Entity<Meeting>().HasMany<UserWriteToMeting>().WithOne().HasForeignKey(c => c.MeetingId); | ||||
|         builder.Entity<User>().HasMany<UserWriteToMeting>().WithOne().HasForeignKey(c => c.UserId); | ||||
|     } | ||||
|   | ||||
| @@ -69,9 +69,12 @@ builder.Services.AddControllers(); | ||||
| // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||||
| builder.Services.AddEndpointsApiExplorer(); | ||||
| builder.Services.AddSwaggerGen(); | ||||
| builder.Services.AddCors(); | ||||
|  | ||||
| var app = builder.Build(); | ||||
|  | ||||
| app.UseCors(builder => builder.AllowAnyOrigin().AllowAnyMethod()); | ||||
|  | ||||
| app.UseStaticFiles(new StaticFileOptions | ||||
| { | ||||
|     FileProvider = new PhysicalFileProvider( | ||||
|   | ||||
		Reference in New Issue
	
	Block a user