diff --git a/CyberBoom/Controllers/UserController.cs b/CyberBoom/Controllers/UserController.cs index 87ccec7..a2a3121 100644 --- a/CyberBoom/Controllers/UserController.cs +++ b/CyberBoom/Controllers/UserController.cs @@ -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 Post([FromBody] Question question) + { + await _applicationContext.Questions.AddAsync(question); + + await _applicationContext.SaveChangesAsync(); + + return Ok(new { + question.Id + }); + } + + [HttpPut] + public async Task 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 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 diff --git a/CyberBoom/DbContext/User.cs b/CyberBoom/DbContext/User.cs index c0a6130..7fc3c5b 100644 --- a/CyberBoom/DbContext/User.cs +++ b/CyberBoom/DbContext/User.cs @@ -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 public DbSet Reviews { get; set; } public DbSet Reactions { get; set; } + public DbSet UserWriteToMetings { get; set; } + public DbSet Questions { get; set; } + public ApplicationContext(DbContextOptions options) : base(options) { @@ -234,9 +261,14 @@ public class ApplicationContext : IdentityDbContext { base.OnModelCreating(builder); builder.Entity().HasMany().WithOne().HasForeignKey(c => c.MeetingId); + builder.Entity().HasMany().WithOne().HasForeignKey(c => c.MeetingId); + 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.ReviewId); + builder.Entity().HasMany().WithOne().HasForeignKey(c => c.UserId); + + builder.Entity().HasMany().WithOne().HasForeignKey(c => c.QuestionId); + builder.Entity().HasMany().WithOne().HasForeignKey(c => c.MeetingId); builder.Entity().HasMany().WithOne().HasForeignKey(c => c.UserId); } diff --git a/CyberBoom/Program.cs b/CyberBoom/Program.cs index 6706ee2..bde6be6 100644 --- a/CyberBoom/Program.cs +++ b/CyberBoom/Program.cs @@ -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(