diff --git a/UrphaCapital.API/Controllers/HomeworksController.cs b/UrphaCapital.API/Controllers/HomeworksController.cs index 0ab6646..6d1a1aa 100644 --- a/UrphaCapital.API/Controllers/HomeworksController.cs +++ b/UrphaCapital.API/Controllers/HomeworksController.cs @@ -4,6 +4,7 @@ using UrphaCapital.Application.UseCases.Homework.Queries; using UrphaCapital.Application.UseCases.Lessons.Queries; using UrphaCapital.Application.ViewModels; +using UrphaCapital.Domain.DTOs; using UrphaCapital.Domain.Entities; namespace UrphaCapital.API.Controllers @@ -25,7 +26,7 @@ public async Task PostLesson([FromForm] CreateHomeworkCommand com return response; } - + [HttpDelete("{id}")] public async Task RemoveHomework(long id, CancellationToken cancellation) { @@ -35,7 +36,7 @@ public async Task RemoveHomework(long id, CancellationToken cance return response; } - + [HttpPut] public async Task PutHomework([FromForm] UpdateHomeworkCommand command, CancellationToken cancellation) { @@ -43,7 +44,30 @@ public async Task PutHomework([FromForm] UpdateHomeworkCommand co return response; } - + + [HttpPut("grade-homework")] + public async Task PutHomework([FromBody] GradeHomeworkCommand command, CancellationToken cancellation) + { + var response = await _mediator.Send(command, cancellation); + + return response; + } + + [HttpGet("{studentId}/results/{index}/{count}")] + public async Task> GetStudentHomeworkResults(long studentId, int index, int count, CancellationToken cancellation) + { + var query = new GetStudentHomeworkResultsQuery() + { + StudentId = studentId, + Index = index, + Count = count, + }; + + var response = await _mediator.Send(query, cancellation); + + return response; + } + [HttpGet("{index}/{count}")] public async Task> GetAll(int index, int count, CancellationToken cancellation) { diff --git a/UrphaCapital.Application/AuthServices/AuthService.cs b/UrphaCapital.Application/AuthServices/AuthService.cs index a5932b6..d706c41 100644 --- a/UrphaCapital.Application/AuthServices/AuthService.cs +++ b/UrphaCapital.Application/AuthServices/AuthService.cs @@ -36,7 +36,7 @@ public TokenModel GenerateToken(Student user) new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), new Claim(JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(DateTime.UtcNow).ToString(CultureInfo.InvariantCulture), ClaimValueTypes.Integer64), new Claim("UserId", user.Id.ToString()), - new Claim("Name", user.FullName), + new Claim("Title", user.FullName), new Claim("Phone", user.PhoneNumber), new Claim("ids", ids), new Claim("Address", user.Address), @@ -75,7 +75,7 @@ public TokenModel GenerateToken(Admin user) new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), new Claim(JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(DateTime.UtcNow).ToString(CultureInfo.InvariantCulture), ClaimValueTypes.Integer64), new Claim("Id", user.Id.ToString()), - new Claim("Name", user.Name), + new Claim("Title", user.Name), new Claim("Phone", user.PhoneNumber), new Claim("Email", user.Email), new Claim("Role", user.Role!) @@ -111,7 +111,7 @@ public TokenModel GenerateToken(Mentor user) new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), new Claim(JwtRegisteredClaimNames.Iat, EpochTime.GetIntDate(DateTime.UtcNow).ToString(CultureInfo.InvariantCulture), ClaimValueTypes.Integer64), new Claim("Id", user.Id.ToString()), - new Claim("Name", user.Name), + new Claim("Title", user.Name), new Claim("Phone", user.PhoneNumber), new Claim("Email", user.Email), new Claim("Role", user.Role!) diff --git a/UrphaCapital.Application/UseCases/Homework/Commands/CreateHomeworkCommand.cs b/UrphaCapital.Application/UseCases/Homework/Commands/CreateHomeworkCommand.cs index 7c8f87e..827655d 100644 --- a/UrphaCapital.Application/UseCases/Homework/Commands/CreateHomeworkCommand.cs +++ b/UrphaCapital.Application/UseCases/Homework/Commands/CreateHomeworkCommand.cs @@ -14,7 +14,7 @@ public class CreateHomeworkCommand: IRequest public string Title { get; set; } public IFormFile FILE { get; set; } public string Description { get; set; } - public long studentId { get; set; } + public long StudentId { get; set; } public Guid LessonId { get; set; } } } diff --git a/UrphaCapital.Application/UseCases/Homework/Commands/GradeHomeworkCommand.cs b/UrphaCapital.Application/UseCases/Homework/Commands/GradeHomeworkCommand.cs new file mode 100644 index 0000000..49de599 --- /dev/null +++ b/UrphaCapital.Application/UseCases/Homework/Commands/GradeHomeworkCommand.cs @@ -0,0 +1,17 @@ +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UrphaCapital.Application.ViewModels; + +namespace UrphaCapital.Application.UseCases.Homework.Commands +{ + public class GradeHomeworkCommand : IRequest + { + public long HomeworkId { get; set; } + public long MentorId { get; set; } + public int Grade { get; set; } + } +} diff --git a/UrphaCapital.Application/UseCases/Homework/Commands/UpdateHomeworkCommand.cs b/UrphaCapital.Application/UseCases/Homework/Commands/UpdateHomeworkCommand.cs index c276921..b343de3 100644 --- a/UrphaCapital.Application/UseCases/Homework/Commands/UpdateHomeworkCommand.cs +++ b/UrphaCapital.Application/UseCases/Homework/Commands/UpdateHomeworkCommand.cs @@ -15,7 +15,7 @@ public class UpdateHomeworkCommand: IRequest public string Title { get; set; } public IFormFile FILE { get; set; } public string Description { get; set; } - public long studentId { get; set; } + public long StudentId { get; set; } public Guid LessonId { get; set; } } } diff --git a/UrphaCapital.Application/UseCases/Homework/Handlers/CreateHomeworkCommandHandler.cs b/UrphaCapital.Application/UseCases/Homework/Handlers/CreateHomeworkCommandHandler.cs index a11b75b..2027fb4 100644 --- a/UrphaCapital.Application/UseCases/Homework/Handlers/CreateHomeworkCommandHandler.cs +++ b/UrphaCapital.Application/UseCases/Homework/Handlers/CreateHomeworkCommandHandler.cs @@ -59,7 +59,7 @@ public async Task Handle(CreateHomeworkCommand request, Cancellat Title = request.Title, LessonId = request.LessonId, Description = request.Description, - studentId = request.studentId, + StudentId = request.StudentId, FILE = "/HomeworkFile/" + fileName, }; diff --git a/UrphaCapital.Application/UseCases/Homework/Handlers/GradeHomeworkCommandHandler.cs b/UrphaCapital.Application/UseCases/Homework/Handlers/GradeHomeworkCommandHandler.cs new file mode 100644 index 0000000..a2f904f --- /dev/null +++ b/UrphaCapital.Application/UseCases/Homework/Handlers/GradeHomeworkCommandHandler.cs @@ -0,0 +1,33 @@ +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UrphaCapital.Application.Abstractions; +using UrphaCapital.Application.UseCases.Homework.Commands; +using UrphaCapital.Application.ViewModels; + +namespace UrphaCapital.Application.UseCases.Homework.Handlers +{ + public class GradeHomeworkCommandHandler : IRequestHandler + { + private readonly IApplicationDbContext _context; + public async Task Handle(GradeHomeworkCommand request, CancellationToken cancellationToken) + { + var homework = await _context.Homeworks.FindAsync(request.HomeworkId); + if (homework == null) return new ResponseModel() { IsSuccess = false, Message = "Not Found", StatusCode = 404 }; + + homework.Grade = request.Grade; + homework.MentorId = request.MentorId; + await _context.SaveChangesAsync(); + + return new ResponseModel() + { + IsSuccess = true, + Message = "Successfully Graded", + StatusCode = 200 + }; + } + } +} diff --git a/UrphaCapital.Application/UseCases/Homework/Handlers/UpdateHomeworkCommandHandler.cs b/UrphaCapital.Application/UseCases/Homework/Handlers/UpdateHomeworkCommandHandler.cs index 979711f..64a9d84 100644 --- a/UrphaCapital.Application/UseCases/Homework/Handlers/UpdateHomeworkCommandHandler.cs +++ b/UrphaCapital.Application/UseCases/Homework/Handlers/UpdateHomeworkCommandHandler.cs @@ -70,7 +70,7 @@ public async Task Handle(UpdateHomeworkCommand request, Cancellat hw.Title = request.Title; hw.FILE = "/HomeworkFile/" + fileName; hw.Description = request.Description; - hw.studentId = request.studentId; + hw.StudentId = request.StudentId; hw.LessonId = request.LessonId; await _context.SaveChangesAsync(cancellationToken); diff --git a/UrphaCapital.Application/UseCases/Homework/Queries/GetHomeworkByStudentIdQuery.cs b/UrphaCapital.Application/UseCases/Homework/Queries/GetHomeworkByStudentIdQuery.cs deleted file mode 100644 index 3e08956..0000000 --- a/UrphaCapital.Application/UseCases/Homework/Queries/GetHomeworkByStudentIdQuery.cs +++ /dev/null @@ -1,15 +0,0 @@ -using MediatR; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using UrphaCapital.Domain.Entities; - -namespace UrphaCapital.Application.UseCases.Homework.Queries -{ - public class GetHomeworkByStudentIdQuery: IRequest> - { - public long studentId { get; set; } - } -} diff --git a/UrphaCapital.Application/UseCases/Homework/Queries/GetStudentHomeworkResultsQuery.cs b/UrphaCapital.Application/UseCases/Homework/Queries/GetStudentHomeworkResultsQuery.cs new file mode 100644 index 0000000..b2e1a96 --- /dev/null +++ b/UrphaCapital.Application/UseCases/Homework/Queries/GetStudentHomeworkResultsQuery.cs @@ -0,0 +1,17 @@ +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UrphaCapital.Domain.DTOs; + +namespace UrphaCapital.Application.UseCases.Homework.Queries +{ + public class GetStudentHomeworkResultsQuery : IRequest> + { + public long StudentId { get; set; } + public int Index { get; set; } + public int Count { get; set; } + } +} diff --git a/UrphaCapital.Application/UseCases/Homework/QueriesHandler/GetHomeworksByStudentIdQueryHandler.cs b/UrphaCapital.Application/UseCases/Homework/QueriesHandler/GetHomeworksByStudentIdQueryHandler.cs deleted file mode 100644 index 19cabfb..0000000 --- a/UrphaCapital.Application/UseCases/Homework/QueriesHandler/GetHomeworksByStudentIdQueryHandler.cs +++ /dev/null @@ -1,28 +0,0 @@ -using MediatR; -using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using UrphaCapital.Application.Abstractions; -using UrphaCapital.Application.UseCases.Homework.Queries; -using UrphaCapital.Domain.Entities; - -namespace UrphaCapital.Application.UseCases.Homework.QueriesHandler -{ - public class GetHomeworksByStudentIdQueryHandler : IRequestHandler> - { - private readonly IApplicationDbContext _context; - - public GetHomeworksByStudentIdQueryHandler(IApplicationDbContext context) - { - _context = context; - } - - public async Task> Handle(GetHomeworkByStudentIdQuery request, CancellationToken cancellationToken) - { - return await _context.Homeworks.Where(x => x.studentId == request.studentId).ToListAsync(); - } - } -} diff --git a/UrphaCapital.Application/UseCases/Homework/QueriesHandler/GetStudentHomeworkResultsQueryHandler.cs b/UrphaCapital.Application/UseCases/Homework/QueriesHandler/GetStudentHomeworkResultsQueryHandler.cs new file mode 100644 index 0000000..654dc0e --- /dev/null +++ b/UrphaCapital.Application/UseCases/Homework/QueriesHandler/GetStudentHomeworkResultsQueryHandler.cs @@ -0,0 +1,45 @@ +using MediatR; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UrphaCapital.Application.Abstractions; +using UrphaCapital.Application.UseCases.Homework.Queries; +using UrphaCapital.Domain.DTOs; +using UrphaCapital.Domain.Entities.Auth; + +namespace UrphaCapital.Application.UseCases.Homework.QueriesHandler +{ + public class GetStudentHomeworkResultsQueryHandler : IRequestHandler> + { + private readonly IApplicationDbContext _context; + + public GetStudentHomeworkResultsQueryHandler(IApplicationDbContext context) + { + _context = context; + } + + public async Task> Handle(GetStudentHomeworkResultsQuery request, CancellationToken cancellationToken) + { + var homeworkList = await _context.Homeworks + .Where(h => h.StudentId == request.StudentId) + .Skip(request.Index - 1) + .Take(request.Count) + .Include(h => h.Lesson) + .ToListAsync(); + + var result = homeworkList.Select(h => new HomeworkResultView() + { + HomeworkId = h.Id, + FILE = h.FILE, + Grade = h.Grade, + LessonTitle = h.Lesson.Title + }); + + return result; + + } + } +} diff --git a/UrphaCapital.Application/UseCases/Lessons/Commands/CreateLessonCommand.cs b/UrphaCapital.Application/UseCases/Lessons/Commands/CreateLessonCommand.cs index 1b161a7..044179f 100644 --- a/UrphaCapital.Application/UseCases/Lessons/Commands/CreateLessonCommand.cs +++ b/UrphaCapital.Application/UseCases/Lessons/Commands/CreateLessonCommand.cs @@ -8,6 +8,7 @@ public class CreateLessonCommand : IRequest { public string Name { get; set; } public Guid CourseId { get; set; } + public string HomeworkDescription { get; set; } public IFormFile Video { get; set; } } } diff --git a/UrphaCapital.Application/UseCases/Lessons/Commands/UpdateLessonCommand.cs b/UrphaCapital.Application/UseCases/Lessons/Commands/UpdateLessonCommand.cs index d7b2feb..cdb91b5 100644 --- a/UrphaCapital.Application/UseCases/Lessons/Commands/UpdateLessonCommand.cs +++ b/UrphaCapital.Application/UseCases/Lessons/Commands/UpdateLessonCommand.cs @@ -15,5 +15,6 @@ public class UpdateLessonCommand : IRequest public string Name { get; set; } public Guid CourseId { get; set; } public IFormFile Video { get; set; } + public string HomeworkDescription { get; set; } } } diff --git a/UrphaCapital.Application/UseCases/Lessons/Handlers/CommandHandlers/CreateLessonCommandHandler.cs b/UrphaCapital.Application/UseCases/Lessons/Handlers/CommandHandlers/CreateLessonCommandHandler.cs index 3253959..06b6026 100644 --- a/UrphaCapital.Application/UseCases/Lessons/Handlers/CommandHandlers/CreateLessonCommandHandler.cs +++ b/UrphaCapital.Application/UseCases/Lessons/Handlers/CommandHandlers/CreateLessonCommandHandler.cs @@ -59,8 +59,9 @@ public async Task Handle(CreateLessonCommand request, Cancellatio var category = new Lesson() { - Name = request.Name, + Title = request.Name, CourseId = request.CourseId, + HomeworkDescription = request.HomeworkDescription, Video = "/LessonVideos/" + fileName, }; diff --git a/UrphaCapital.Application/UseCases/Lessons/Handlers/CommandHandlers/UpdateLessonCommandHandler.cs b/UrphaCapital.Application/UseCases/Lessons/Handlers/CommandHandlers/UpdateLessonCommandHandler.cs index 2c633b9..a253864 100644 --- a/UrphaCapital.Application/UseCases/Lessons/Handlers/CommandHandlers/UpdateLessonCommandHandler.cs +++ b/UrphaCapital.Application/UseCases/Lessons/Handlers/CommandHandlers/UpdateLessonCommandHandler.cs @@ -71,9 +71,10 @@ public async Task Handle(UpdateLessonCommand request, Cancellatio - lesson.Name = request.Name; + lesson.Title = request.Name; lesson.Video = "/LessonVideos/" + fileName; lesson.CourseId = request.CourseId; + lesson.HomeworkDescription = request.HomeworkDescription; await _context.SaveChangesAsync(cancellationToken); diff --git a/UrphaCapital.Application/UseCases/Lessons/Handlers/QueryHandlers/GetAllLessonsByCourseIdQueryHandler.cs b/UrphaCapital.Application/UseCases/Lessons/Handlers/QueryHandlers/GetAllLessonsByCourseIdQueryHandler.cs index c7a2b63..d372cad 100644 --- a/UrphaCapital.Application/UseCases/Lessons/Handlers/QueryHandlers/GetAllLessonsByCourseIdQueryHandler.cs +++ b/UrphaCapital.Application/UseCases/Lessons/Handlers/QueryHandlers/GetAllLessonsByCourseIdQueryHandler.cs @@ -39,7 +39,7 @@ public async Task> Handle(GetAllLessonsByCourseIdQuery reque .Select(x => new Lesson { Id = x.Id, - Name = x.Name, + Title = x.Title, CourseId = x.CourseId }) .ToListAsync(cancellationToken), diff --git a/UrphaCapital.Domain/DTOs/HomeworkResultView.cs b/UrphaCapital.Domain/DTOs/HomeworkResultView.cs new file mode 100644 index 0000000..9e14a8c --- /dev/null +++ b/UrphaCapital.Domain/DTOs/HomeworkResultView.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UrphaCapital.Domain.DTOs +{ + public class HomeworkResultView + { + public long HomeworkId { get; set; } + public string LessonTitle { get; set; } + public string FILE { get; set; } + public int? Grade { get; set; } + } +} diff --git a/UrphaCapital.Domain/Entities/Homeworks.cs b/UrphaCapital.Domain/Entities/Homeworks.cs index 3e04c53..932e941 100644 --- a/UrphaCapital.Domain/Entities/Homeworks.cs +++ b/UrphaCapital.Domain/Entities/Homeworks.cs @@ -12,8 +12,11 @@ public class Homeworks public string Title { get; set; } public string FILE { get; set; } public string Description { get; set; } + public long StudentId { get; set; } + public int? Grade { get; set; } + public long? MentorId { get; set; } public Guid LessonId { get; set; } - public long studentId { get; set; } + public Lesson Lesson { get; set; } } } diff --git a/UrphaCapital.Domain/Entities/Lesson.cs b/UrphaCapital.Domain/Entities/Lesson.cs index 5146c6d..633c520 100644 --- a/UrphaCapital.Domain/Entities/Lesson.cs +++ b/UrphaCapital.Domain/Entities/Lesson.cs @@ -9,9 +9,12 @@ namespace UrphaCapital.Domain.Entities public class Lesson { public Guid Id { get; set; } = Guid.NewGuid(); - public string Name { get; set; } + public string Title { get; set; } + public string HomeworkDescription { get; set; } + public string Video { get; set; } public Guid CourseId { get; set; } + + public Course Course { get; set; } - public string Video { get; set; } } } diff --git a/UrphaCapital.Infrastructure/Migrations/20240912013458_firstMigration.Designer.cs b/UrphaCapital.Infrastructure/Migrations/20240912013458_firstMigration.Designer.cs index 258adfb..896c300 100644 --- a/UrphaCapital.Infrastructure/Migrations/20240912013458_firstMigration.Designer.cs +++ b/UrphaCapital.Infrastructure/Migrations/20240912013458_firstMigration.Designer.cs @@ -63,7 +63,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("text"); - b.Property("Name") + b.Property("Title") .IsRequired() .HasColumnType("text"); @@ -116,7 +116,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("text"); - b.Property("Name") + b.Property("Title") .IsRequired() .HasColumnType("text"); @@ -203,7 +203,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("MentorId") .HasColumnType("bigint"); - b.Property("Name") + b.Property("Title") .IsRequired() .HasColumnType("text"); @@ -297,7 +297,7 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("CourseId") .HasColumnType("uuid"); - b.Property("Name") + b.Property("Title") .IsRequired() .HasColumnType("text"); diff --git a/UrphaCapital.Infrastructure/Migrations/20240912013458_firstMigration.cs b/UrphaCapital.Infrastructure/Migrations/20240912013458_firstMigration.cs index e2fa7dd..388796c 100644 --- a/UrphaCapital.Infrastructure/Migrations/20240912013458_firstMigration.cs +++ b/UrphaCapital.Infrastructure/Migrations/20240912013458_firstMigration.cs @@ -196,7 +196,7 @@ protected override void Up(MigrationBuilder migrationBuilder) migrationBuilder.InsertData( table: "Admins", - columns: new[] { "Id", "Email", "Name", "PasswordHash", "PhoneNumber", "Role", "Salt" }, + columns: new[] { "Id", "Email", "Title", "PasswordHash", "PhoneNumber", "Role", "Salt" }, values: new object[] { 1L, "admin@gmail.com", "Ozod Ali", "0uWF1h1dUY3IskvUlLOklhBlgmBACiFQQ/zcLXz1VFU=", "+998934013443", "SuperAdmin", "82f73fc9-42fe-417f-afae-7dcbbfd629fb" }); migrationBuilder.CreateIndex( diff --git a/UrphaCapital.Infrastructure/Migrations/20240914175812_secondMigrationForHomework.Designer.cs b/UrphaCapital.Infrastructure/Migrations/20240914175812_secondMigrationForHomework.Designer.cs new file mode 100644 index 0000000..72459b7 --- /dev/null +++ b/UrphaCapital.Infrastructure/Migrations/20240914175812_secondMigrationForHomework.Designer.cs @@ -0,0 +1,410 @@ +// +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using UrphaCapital.Infrastructure.Persistanse; + +#nullable disable + +namespace UrphaCapital.Infrastructure.Migrations +{ + [DbContext(typeof(UrphaCapitalDbContext))] + [Migration("20240914175812_secondMigrationForHomework")] + partial class secondMigrationForHomework + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.7") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Answer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Content") + .IsRequired() + .HasColumnType("text"); + + b.Property("TestId") + .HasColumnType("bigint"); + + b.Property("isCorrect") + .HasColumnType("boolean"); + + b.HasKey("Id"); + + b.HasIndex("TestId"); + + b.ToTable("Answers"); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Auth.Admin", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("text"); + + b.Property("Role") + .IsRequired() + .HasColumnType("text"); + + b.Property("Salt") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Admins"); + + b.HasData( + new + { + Id = 1L, + Email = "admin@gmail.com", + Name = "Ozod Ali", + PasswordHash = "4Il9e3rB5x4yv8ICacJKVcQIw7AM0ckPme6Io4ttYsg=", + PhoneNumber = "+998934013443", + Role = "SuperAdmin", + Salt = "8d09c77e-61d4-45c6-b403-a1bba01d1946" + }); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Auth.Mentor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("text"); + + b.Property("Picture") + .IsRequired() + .HasColumnType("text"); + + b.Property("Role") + .IsRequired() + .HasColumnType("text"); + + b.Property("Salt") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Mentors"); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Auth.Student", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property>("CourseIds") + .IsRequired() + .HasColumnType("text[]"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FullName") + .IsRequired() + .HasColumnType("text"); + + b.Property("PasswordHash") + .IsRequired() + .HasColumnType("text"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("text"); + + b.Property("Role") + .IsRequired() + .HasColumnType("text"); + + b.Property("Salt") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Course", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("MentorId") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.Property("Picture") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .IsRequired() + .HasColumnType("text"); + + b.Property("Subtitle") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("MentorId"); + + b.ToTable("Courses"); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Help", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("CourseType") + .IsRequired() + .HasColumnType("text"); + + b.Property("Email") + .IsRequired() + .HasColumnType("text"); + + b.Property("FullName") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Helps"); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Homeworks", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("FILE") + .IsRequired() + .HasColumnType("text"); + + b.Property("Grade") + .HasColumnType("integer"); + + b.Property("LessonId") + .HasColumnType("uuid"); + + b.Property("MentorId") + .HasColumnType("bigint"); + + b.Property("StudentId") + .HasColumnType("bigint"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("LessonId"); + + b.ToTable("Homeworks"); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Lesson", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CourseId") + .HasColumnType("uuid"); + + b.Property("Title") + .IsRequired() + .HasColumnType("text"); + + b.Property("Video") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("CourseId"); + + b.ToTable("Lessons"); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Test", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("LessonId") + .HasColumnType("uuid"); + + b.Property("Question") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("LessonId"); + + b.ToTable("Tests"); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Answer", b => + { + b.HasOne("UrphaCapital.Domain.Entities.Test", "Test") + .WithMany("Answers") + .HasForeignKey("TestId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Test"); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Course", b => + { + b.HasOne("UrphaCapital.Domain.Entities.Auth.Mentor", "Mentor") + .WithMany("Courses") + .HasForeignKey("MentorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Mentor"); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Homeworks", b => + { + b.HasOne("UrphaCapital.Domain.Entities.Lesson", "Lesson") + .WithMany() + .HasForeignKey("LessonId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Lesson"); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Lesson", b => + { + b.HasOne("UrphaCapital.Domain.Entities.Course", "Course") + .WithMany() + .HasForeignKey("CourseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Course"); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Test", b => + { + b.HasOne("UrphaCapital.Domain.Entities.Lesson", "Lesson") + .WithMany() + .HasForeignKey("LessonId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Lesson"); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Auth.Mentor", b => + { + b.Navigation("Courses"); + }); + + modelBuilder.Entity("UrphaCapital.Domain.Entities.Test", b => + { + b.Navigation("Answers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/UrphaCapital.Infrastructure/Migrations/20240914175812_secondMigrationForHomework.cs b/UrphaCapital.Infrastructure/Migrations/20240914175812_secondMigrationForHomework.cs new file mode 100644 index 0000000..9ed8608 --- /dev/null +++ b/UrphaCapital.Infrastructure/Migrations/20240914175812_secondMigrationForHomework.cs @@ -0,0 +1,62 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace UrphaCapital.Infrastructure.Migrations +{ + /// + public partial class secondMigrationForHomework : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.RenameColumn( + name: "studentId", + table: "Homeworks", + newName: "StudentId"); + + migrationBuilder.AddColumn( + name: "Grade", + table: "Homeworks", + type: "integer", + nullable: true); + + migrationBuilder.AddColumn( + name: "MentorId", + table: "Homeworks", + type: "bigint", + nullable: true); + + migrationBuilder.UpdateData( + table: "Admins", + keyColumn: "Id", + keyValue: 1L, + columns: new[] { "PasswordHash", "Salt" }, + values: new object[] { "4Il9e3rB5x4yv8ICacJKVcQIw7AM0ckPme6Io4ttYsg=", "8d09c77e-61d4-45c6-b403-a1bba01d1946" }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "Grade", + table: "Homeworks"); + + migrationBuilder.DropColumn( + name: "MentorId", + table: "Homeworks"); + + migrationBuilder.RenameColumn( + name: "StudentId", + table: "Homeworks", + newName: "studentId"); + + migrationBuilder.UpdateData( + table: "Admins", + keyColumn: "Id", + keyValue: 1L, + columns: new[] { "PasswordHash", "Salt" }, + values: new object[] { "0uWF1h1dUY3IskvUlLOklhBlgmBACiFQQ/zcLXz1VFU=", "82f73fc9-42fe-417f-afae-7dcbbfd629fb" }); + } + } +} diff --git a/UrphaCapital.Infrastructure/Migrations/UrphaCapitalDbContextModelSnapshot.cs b/UrphaCapital.Infrastructure/Migrations/UrphaCapitalDbContextModelSnapshot.cs index 6b96ee1..50577bd 100644 --- a/UrphaCapital.Infrastructure/Migrations/UrphaCapitalDbContextModelSnapshot.cs +++ b/UrphaCapital.Infrastructure/Migrations/UrphaCapitalDbContextModelSnapshot.cs @@ -60,7 +60,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("text"); - b.Property("Name") + b.Property("Title") .IsRequired() .HasColumnType("text"); @@ -90,10 +90,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) Id = 1L, Email = "admin@gmail.com", Name = "Ozod Ali", - PasswordHash = "0uWF1h1dUY3IskvUlLOklhBlgmBACiFQQ/zcLXz1VFU=", + PasswordHash = "4Il9e3rB5x4yv8ICacJKVcQIw7AM0ckPme6Io4ttYsg=", PhoneNumber = "+998934013443", Role = "SuperAdmin", - Salt = "82f73fc9-42fe-417f-afae-7dcbbfd629fb" + Salt = "8d09c77e-61d4-45c6-b403-a1bba01d1946" }); }); @@ -113,7 +113,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("text"); - b.Property("Name") + b.Property("Title") .IsRequired() .HasColumnType("text"); @@ -200,7 +200,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("MentorId") .HasColumnType("bigint"); - b.Property("Name") + b.Property("Title") .IsRequired() .HasColumnType("text"); @@ -268,16 +268,22 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("text"); + b.Property("Grade") + .HasColumnType("integer"); + b.Property("LessonId") .HasColumnType("uuid"); + b.Property("MentorId") + .HasColumnType("bigint"); + + b.Property("StudentId") + .HasColumnType("bigint"); + b.Property("Title") .IsRequired() .HasColumnType("text"); - b.Property("studentId") - .HasColumnType("bigint"); - b.HasKey("Id"); b.HasIndex("LessonId"); @@ -294,7 +300,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("CourseId") .HasColumnType("uuid"); - b.Property("Name") + b.Property("Title") .IsRequired() .HasColumnType("text");