From 2a9329f7b7a3d1109d00c99d7acc19aa4eb871b0 Mon Sep 17 00:00:00 2001 From: Evenya Date: Wed, 22 Sep 2021 00:35:32 +0300 Subject: [PATCH 01/30] Query Task added --- .../Queries/GetTheoryBlockByIdQuery.cs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs diff --git a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs new file mode 100644 index 0000000..c471503 --- /dev/null +++ b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs @@ -0,0 +1,38 @@ +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using StudySharp.Domain.Constants; +using StudySharp.Domain.General; +using StudySharp.Domain.Models; +using StudySharp.DomainServices; + +namespace StudySharp.ApplicationServices.Queries +{ + public sealed class GetTheoryBlockByIdQuery : IRequest> + { + public int Id { get; set; } + } + + public sealed class GetTheoryBlockByIdQueryHandler : IRequestHandler> + { + private readonly StudySharpDbContext _context; + + public GetTheoryBlockByIdQueryHandler(StudySharpDbContext studySharpDbContext) + { + _context = studySharpDbContext; + } + + public async Task> Handle( + GetTheoryBlockByIdQuery request, + CancellationToken cancellationToken) + { + var theoryBlock = await _context.TheoryBlocks.FindAsync(request.Id, cancellationToken); + if (theoryBlock == null) + { + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Id), request.Id)); + } + + return OperationResult.Ok(theoryBlock); + } + } +} \ No newline at end of file From d4ccb27ef49c96dc230d221911cab5034b104ca5 Mon Sep 17 00:00:00 2001 From: Evenya Date: Fri, 24 Sep 2021 01:45:57 +0300 Subject: [PATCH 02/30] created: // AddTheoryBlockCommand.cs // GetTheoryBlockByIdQuery.cs // RemoveTheoryBlockByIdCommand.cs --- .../Commands/AddTheoryBlockCommand.cs | 45 +++++++++++++++++++ .../Commands/RemoveTheoryBlockByIdCommand.cs | 41 +++++++++++++++++ .../Queries/GetTheoryBlockByIdQuery.cs | 1 + 3 files changed, 87 insertions(+) create mode 100644 server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs create mode 100644 server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs diff --git a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs new file mode 100644 index 0000000..c2be89f --- /dev/null +++ b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs @@ -0,0 +1,45 @@ +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using Microsoft.EntityFrameworkCore; +using Microsoft.VisualBasic; +using StudySharp.Domain.Constants; +using StudySharp.Domain.General; +using StudySharp.Domain.Models; +using StudySharp.DomainServices; + +namespace StudySharp.ApplicationServices.Commands +{ + public sealed class AddTheoryBlockCommand : IRequest + { + public string Name { get; set; } + public int CourseId { get; set; } + } + + public sealed class AddTheoryBlockHandler : IRequestHandler + { + private readonly StudySharpDbContext _context; + + public AddTheoryBlockHandler(StudySharpDbContext sharpDbContext) + { + _context = sharpDbContext; + } + + public async Task Handle(AddTheoryBlockCommand request, CancellationToken cancellationToken) + { + if (await _context.TheoryBlocks.AnyAsync(c => Equals(c.Name.ToLower()) && c.CourseId == request.CourseId, cancellationToken)) + { + return OperationResult.Fail(string.Format(ErrorConstants.EntityAlreadyExists, nameof(TheoryBlock), nameof(TheoryBlock.Name), request.Name)); + } + + await _context.TheoryBlocks.AddAsync( + new TheoryBlock + { + Name = request.Name, CourseId = request.CourseId, + }, cancellationToken); + await _context.SaveChangesAsync(cancellationToken); + return OperationResult.Ok(); + } + } +} \ No newline at end of file diff --git a/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs b/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs new file mode 100644 index 0000000..f97318b --- /dev/null +++ b/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs @@ -0,0 +1,41 @@ +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using StudySharp.Domain.Constants; +using StudySharp.Domain.General; +using StudySharp.Domain.Models; +using StudySharp.DomainServices; + +namespace StudySharp.ApplicationServices.Commands +{ + public sealed class RemoveTheoryBlockByIdCommand : IRequest + { + public int Id { get; set; } + } + + public sealed class RemoveTheoryBlockByIdCommandHandler : IRequestHandler + { + private readonly StudySharpDbContext _context; + + public RemoveTheoryBlockByIdCommandHandler(StudySharpDbContext sharpDbContext) + { + _context = sharpDbContext; + } + + public async Task Handle( + RemoveTheoryBlockByIdCommand request, + CancellationToken cancellationToken) + { + var theoryBlock = await _context.TheoryBlocks.FindAsync(request.Id, cancellationToken); + + if (theoryBlock == null) + { + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Name), request.Id)); + } + + _context.TheoryBlocks.Remove(theoryBlock); + await _context.SaveChangesAsync(cancellationToken); + return OperationResult.Ok(); + } + } +} diff --git a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs index c471503..1b42d73 100644 --- a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs +++ b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs @@ -13,6 +13,7 @@ public sealed class GetTheoryBlockByIdQuery : IRequest> { private readonly StudySharpDbContext _context; From bdd649e73d804a4ae64d4ef88e98a54e07a2e0ff Mon Sep 17 00:00:00 2001 From: Maria Dodonova Date: Fri, 24 Sep 2021 15:06:51 +0300 Subject: [PATCH 03/30] Added course controller and course requests and responses --- .../Controllers/CourseController.cs | 73 +++++++++++++++++++ .../Requests/Courses/AddCourseRequest.cs | 8 ++ .../Requests/Courses/GetCourseByIdRequest.cs | 7 ++ .../Requests/Courses/GetCoursesRequest.cs | 6 ++ .../Courses/RemoveCourseByIdRequest.cs | 7 ++ .../Responses/Courses/AddCourseResponse.cs | 6 ++ .../Courses/GetCourseByIdResponse.cs | 18 +++++ .../Responses/Courses/GetCoursesResponse.cs | 10 +++ .../Courses/RemoveCourseByIdResponse.cs | 6 ++ 9 files changed, 141 insertions(+) create mode 100644 server/StudySharp.API/Controllers/CourseController.cs create mode 100644 server/StudySharp.API/Requests/Courses/AddCourseRequest.cs create mode 100644 server/StudySharp.API/Requests/Courses/GetCourseByIdRequest.cs create mode 100644 server/StudySharp.API/Requests/Courses/GetCoursesRequest.cs create mode 100644 server/StudySharp.API/Requests/Courses/RemoveCourseByIdRequest.cs create mode 100644 server/StudySharp.API/Responses/Courses/AddCourseResponse.cs create mode 100644 server/StudySharp.API/Responses/Courses/GetCourseByIdResponse.cs create mode 100644 server/StudySharp.API/Responses/Courses/GetCoursesResponse.cs create mode 100644 server/StudySharp.API/Responses/Courses/RemoveCourseByIdResponse.cs diff --git a/server/StudySharp.API/Controllers/CourseController.cs b/server/StudySharp.API/Controllers/CourseController.cs new file mode 100644 index 0000000..7b2b596 --- /dev/null +++ b/server/StudySharp.API/Controllers/CourseController.cs @@ -0,0 +1,73 @@ +using System.Threading.Tasks; +using AutoMapper; +using MediatR; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using StudySharp.API.Requests.Courses; +using StudySharp.API.Responses.Courses; +using StudySharp.ApplicationServices.Commands; +using StudySharp.ApplicationServices.Queries; +using StudySharp.Domain.General; + +namespace StudySharp.API.Controllers +{ + [Authorize] + [ApiController] + [Route("api/[controller]")] + + public class CourseController : ControllerBase + { + private readonly IMediator _mediator; + private readonly IMapper _mapper; + + public CourseController(IMediator mediator, IMapper mapper) + { + _mediator = mediator; + _mapper = mapper; + } + + [HttpPost] + public async Task Add([FromBody] AddCourseRequest addCourseRequest) + { + var addCourseCommand = _mapper.Map(addCourseRequest); + return await _mediator.Send(addCourseCommand); + } + + [HttpPost] + public async Task Remove([FromBody] RemoveCourseByIdRequest removeCourseByIdRequest) + { + var removeCourseByIdCommand = _mapper.Map(removeCourseByIdRequest); + return await _mediator.Send(removeCourseByIdCommand); + } + + [HttpPost] + public async Task GetCourseById([FromBody] GetCourseByIdRequest getCourseByIdRequest) + { + var getCourseByIdQuery = _mapper.Map(getCourseByIdRequest); + var operationResult = await _mediator.Send(getCourseByIdQuery); + + if (!operationResult.IsSucceeded) + { + return OperationResult.Fail(operationResult.Errors); + } + + var response = _mapper.Map(operationResult.Result); + return OperationResult.Ok(response); + } + + [HttpPost] + public async Task GetCourses([FromBody] GetCoursesRequest getCoursesRequest) + { + var getCoursesQuery = _mapper.Map(getCoursesRequest); + var operationResult = await _mediator.Send(getCoursesQuery); + + if (!operationResult.IsSucceeded) + { + return OperationResult.Fail(operationResult.Errors); + } + + var response = _mapper.Map(operationResult.Result); + return OperationResult.Ok(response); + } + } +} diff --git a/server/StudySharp.API/Requests/Courses/AddCourseRequest.cs b/server/StudySharp.API/Requests/Courses/AddCourseRequest.cs new file mode 100644 index 0000000..0e0cd56 --- /dev/null +++ b/server/StudySharp.API/Requests/Courses/AddCourseRequest.cs @@ -0,0 +1,8 @@ +namespace StudySharp.API.Requests.Courses +{ + public class AddCourseRequest + { + public string Name { get; set; } + public int TeacherId { get; set; } + } +} diff --git a/server/StudySharp.API/Requests/Courses/GetCourseByIdRequest.cs b/server/StudySharp.API/Requests/Courses/GetCourseByIdRequest.cs new file mode 100644 index 0000000..242f8bc --- /dev/null +++ b/server/StudySharp.API/Requests/Courses/GetCourseByIdRequest.cs @@ -0,0 +1,7 @@ +namespace StudySharp.API.Requests.Courses +{ + public class GetCourseByIdRequest + { + public int Id { get; set; } + } +} diff --git a/server/StudySharp.API/Requests/Courses/GetCoursesRequest.cs b/server/StudySharp.API/Requests/Courses/GetCoursesRequest.cs new file mode 100644 index 0000000..425394e --- /dev/null +++ b/server/StudySharp.API/Requests/Courses/GetCoursesRequest.cs @@ -0,0 +1,6 @@ +namespace StudySharp.API.Requests.Courses +{ + public class GetCoursesRequest + { + } +} diff --git a/server/StudySharp.API/Requests/Courses/RemoveCourseByIdRequest.cs b/server/StudySharp.API/Requests/Courses/RemoveCourseByIdRequest.cs new file mode 100644 index 0000000..da11152 --- /dev/null +++ b/server/StudySharp.API/Requests/Courses/RemoveCourseByIdRequest.cs @@ -0,0 +1,7 @@ +namespace StudySharp.API.Requests.Courses +{ + public class RemoveCourseByIdRequest + { + public int Id { get; set; } + } +} diff --git a/server/StudySharp.API/Responses/Courses/AddCourseResponse.cs b/server/StudySharp.API/Responses/Courses/AddCourseResponse.cs new file mode 100644 index 0000000..0f4e946 --- /dev/null +++ b/server/StudySharp.API/Responses/Courses/AddCourseResponse.cs @@ -0,0 +1,6 @@ +namespace StudySharp.API.Responses.Courses +{ + public class AddCourseResponse + { + } +} diff --git a/server/StudySharp.API/Responses/Courses/GetCourseByIdResponse.cs b/server/StudySharp.API/Responses/Courses/GetCourseByIdResponse.cs new file mode 100644 index 0000000..523a43d --- /dev/null +++ b/server/StudySharp.API/Responses/Courses/GetCourseByIdResponse.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using StudySharp.Domain.Models; +namespace StudySharp.API.Responses.Courses +{ + public class GetCourseByIdResponse + { + public int Id { get; set; } + public string Name { get; set; } + public List Tags { get; set; } + public int TeacherId { get; set; } + public Teacher Teacher { get; set; } + public List TheoryBlocks { get; set; } + public List PracticalBlocks { get; set; } + public DateTimeOffset DateCreated { get; private set; } + public DateTimeOffset? DateModified { get; private set; } + } +} diff --git a/server/StudySharp.API/Responses/Courses/GetCoursesResponse.cs b/server/StudySharp.API/Responses/Courses/GetCoursesResponse.cs new file mode 100644 index 0000000..adc1998 --- /dev/null +++ b/server/StudySharp.API/Responses/Courses/GetCoursesResponse.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using StudySharp.Domain.Models; + +namespace StudySharp.API.Responses.Courses +{ + public class GetCoursesResponse + { + public List Courses { get; set; } + } +} diff --git a/server/StudySharp.API/Responses/Courses/RemoveCourseByIdResponse.cs b/server/StudySharp.API/Responses/Courses/RemoveCourseByIdResponse.cs new file mode 100644 index 0000000..938fe57 --- /dev/null +++ b/server/StudySharp.API/Responses/Courses/RemoveCourseByIdResponse.cs @@ -0,0 +1,6 @@ +namespace StudySharp.API.Responses.Courses +{ + public class RemoveCourseByIdResponse + { + } +} From 3af6452385a15c07154a5092dd534eb2a60698d0 Mon Sep 17 00:00:00 2001 From: Maria Dodonova Date: Fri, 24 Sep 2021 15:24:44 +0300 Subject: [PATCH 04/30] Fixed http get/post --- server/StudySharp.API/Controllers/CourseController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/StudySharp.API/Controllers/CourseController.cs b/server/StudySharp.API/Controllers/CourseController.cs index 7b2b596..fa891c6 100644 --- a/server/StudySharp.API/Controllers/CourseController.cs +++ b/server/StudySharp.API/Controllers/CourseController.cs @@ -40,7 +40,7 @@ public async Task Remove([FromBody] RemoveCourseByIdRequest rem return await _mediator.Send(removeCourseByIdCommand); } - [HttpPost] + [HttpGet] public async Task GetCourseById([FromBody] GetCourseByIdRequest getCourseByIdRequest) { var getCourseByIdQuery = _mapper.Map(getCourseByIdRequest); @@ -55,7 +55,7 @@ public async Task GetCourseById([FromBody] GetCourseByIdRequest return OperationResult.Ok(response); } - [HttpPost] + [HttpGet] public async Task GetCourses([FromBody] GetCoursesRequest getCoursesRequest) { var getCoursesQuery = _mapper.Map(getCoursesRequest); From c926da95f188f6e614af57d767174eb38fece31b Mon Sep 17 00:00:00 2001 From: Maria Dodonova Date: Fri, 24 Sep 2021 15:51:12 +0300 Subject: [PATCH 05/30] Added course mapper profile --- .../Controllers/CourseController.cs | 4 ++-- .../MapperProfiles/CourseProfile.cs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 server/StudySharp.API/MapperProfiles/CourseProfile.cs diff --git a/server/StudySharp.API/Controllers/CourseController.cs b/server/StudySharp.API/Controllers/CourseController.cs index fa891c6..c69cf30 100644 --- a/server/StudySharp.API/Controllers/CourseController.cs +++ b/server/StudySharp.API/Controllers/CourseController.cs @@ -26,14 +26,14 @@ public CourseController(IMediator mediator, IMapper mapper) _mapper = mapper; } - [HttpPost] + [HttpPost("add")] public async Task Add([FromBody] AddCourseRequest addCourseRequest) { var addCourseCommand = _mapper.Map(addCourseRequest); return await _mediator.Send(addCourseCommand); } - [HttpPost] + [HttpPost("remove")] public async Task Remove([FromBody] RemoveCourseByIdRequest removeCourseByIdRequest) { var removeCourseByIdCommand = _mapper.Map(removeCourseByIdRequest); diff --git a/server/StudySharp.API/MapperProfiles/CourseProfile.cs b/server/StudySharp.API/MapperProfiles/CourseProfile.cs new file mode 100644 index 0000000..3606b8b --- /dev/null +++ b/server/StudySharp.API/MapperProfiles/CourseProfile.cs @@ -0,0 +1,18 @@ +using AutoMapper; +using StudySharp.API.Requests.Courses; +using StudySharp.ApplicationServices.Commands; +using StudySharp.ApplicationServices.Queries; + +namespace StudySharp.API.MapperProfiles +{ + public class CourseProfile : Profile + { + public CourseProfile() + { + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); + } + } +} From 961285b23ac30197c1a4e31735189a02df5c2094 Mon Sep 17 00:00:00 2001 From: Evenya Date: Fri, 24 Sep 2021 18:35:17 +0300 Subject: [PATCH 06/30] Fixwd conversions #bodyazaebal --- .../Commands/AddCourseCommand.cs | 6 +++--- .../Commands/AddTheoryBlockCommand.cs | 9 ++++----- .../Queries/GetTheoryBlockByIdQuery.cs | 1 - 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/server/StudySharp.ApplicationServices/Commands/AddCourseCommand.cs b/server/StudySharp.ApplicationServices/Commands/AddCourseCommand.cs index dcc8f1c..faeeb23 100644 --- a/server/StudySharp.ApplicationServices/Commands/AddCourseCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/AddCourseCommand.cs @@ -26,16 +26,16 @@ public AddCourseCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(AddCourseCommand request, CancellationToken cancellationToken) { - if (await _context.Courses.AnyAsync(c => Equals(c.Name.ToLower(), request.Name.ToLower()) && c.TeacherId == request.TeacherId, cancellationToken)) + if (await _context.Courses.AnyAsync(_ => Equals(_.Name.ToLower(), request.Name.ToLower()) && _.TeacherId == request.TeacherId, cancellationToken)) { return OperationResult.Fail(string.Format(ErrorConstants.EntityAlreadyExists, nameof(Course), nameof(Course.Name), request.Name)); } await _context.Courses.AddAsync( new Course - { + { Name = request.Name, TeacherId = request.TeacherId, - }, cancellationToken); + }, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return OperationResult.Ok(); diff --git a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs index c2be89f..42cadba 100644 --- a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs @@ -1,9 +1,7 @@ -using System.Linq; using System.Threading; using System.Threading.Tasks; using MediatR; using Microsoft.EntityFrameworkCore; -using Microsoft.VisualBasic; using StudySharp.Domain.Constants; using StudySharp.Domain.General; using StudySharp.Domain.Models; @@ -17,18 +15,18 @@ public sealed class AddTheoryBlockCommand : IRequest public int CourseId { get; set; } } - public sealed class AddTheoryBlockHandler : IRequestHandler + public sealed class AddTheoryBlockCommandHandler : IRequestHandler { private readonly StudySharpDbContext _context; - public AddTheoryBlockHandler(StudySharpDbContext sharpDbContext) + public AddTheoryBlockCommandHandler(StudySharpDbContext sharpDbContext) { _context = sharpDbContext; } public async Task Handle(AddTheoryBlockCommand request, CancellationToken cancellationToken) { - if (await _context.TheoryBlocks.AnyAsync(c => Equals(c.Name.ToLower()) && c.CourseId == request.CourseId, cancellationToken)) + if (await _context.TheoryBlocks.AnyAsync(c => Equals(c.Name.ToLower(), request.Name.ToLower()) && c.CourseId == request.CourseId, cancellationToken)) { return OperationResult.Fail(string.Format(ErrorConstants.EntityAlreadyExists, nameof(TheoryBlock), nameof(TheoryBlock.Name), request.Name)); } @@ -38,6 +36,7 @@ await _context.TheoryBlocks.AddAsync( { Name = request.Name, CourseId = request.CourseId, }, cancellationToken); + await _context.SaveChangesAsync(cancellationToken); return OperationResult.Ok(); } diff --git a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs index 1b42d73..c471503 100644 --- a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs +++ b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs @@ -13,7 +13,6 @@ public sealed class GetTheoryBlockByIdQuery : IRequest> { private readonly StudySharpDbContext _context; From d125f65dd2fd4471540fe8cbad3696f29efb39e4 Mon Sep 17 00:00:00 2001 From: Evenya Date: Fri, 24 Sep 2021 19:36:21 +0300 Subject: [PATCH 07/30] Argument Fix --- .../StudySharp.ApplicationServices/Commands/AddCourseCommand.cs | 2 +- .../Commands/AddTheoryBlockCommand.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/StudySharp.ApplicationServices/Commands/AddCourseCommand.cs b/server/StudySharp.ApplicationServices/Commands/AddCourseCommand.cs index faeeb23..55bc550 100644 --- a/server/StudySharp.ApplicationServices/Commands/AddCourseCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/AddCourseCommand.cs @@ -26,7 +26,7 @@ public AddCourseCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(AddCourseCommand request, CancellationToken cancellationToken) { - if (await _context.Courses.AnyAsync(_ => Equals(_.Name.ToLower(), request.Name.ToLower()) && _.TeacherId == request.TeacherId, cancellationToken)) + if (await _context.Courses.AnyAsync(с => Equals(с.Name.ToLower(), request.Name.ToLower()) && с.TeacherId == request.TeacherId, cancellationToken)) { return OperationResult.Fail(string.Format(ErrorConstants.EntityAlreadyExists, nameof(Course), nameof(Course.Name), request.Name)); } diff --git a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs index 42cadba..a6bad66 100644 --- a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs @@ -26,7 +26,7 @@ public AddTheoryBlockCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(AddTheoryBlockCommand request, CancellationToken cancellationToken) { - if (await _context.TheoryBlocks.AnyAsync(c => Equals(c.Name.ToLower(), request.Name.ToLower()) && c.CourseId == request.CourseId, cancellationToken)) + if (await _context.TheoryBlocks.AnyAsync(_ => Equals(_.Name.ToLower(), request.Name.ToLower()) && _.CourseId == request.CourseId, cancellationToken)) { return OperationResult.Fail(string.Format(ErrorConstants.EntityAlreadyExists, nameof(TheoryBlock), nameof(TheoryBlock.Name), request.Name)); } From 9cd3df05eb6d403fceec3421afcdcbc7d1b0b755 Mon Sep 17 00:00:00 2001 From: zefirlover Date: Sat, 25 Sep 2021 12:26:06 +0300 Subject: [PATCH 08/30] AddTheoryBlockRequest, RemoveTheoryBlockByIdRequest and TheoryBlockController created --- .../Controllers/TheoryBlockController.cs | 41 +++++++++++++++++++ .../TheoryBlocks/AddTheoryBlockRequest.cs | 8 ++++ .../RemoveTheoryBlockByIdRequest.cs | 7 ++++ 3 files changed, 56 insertions(+) create mode 100644 server/StudySharp.API/Controllers/TheoryBlockController.cs create mode 100644 server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs create mode 100644 server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs new file mode 100644 index 0000000..b9db8a7 --- /dev/null +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -0,0 +1,41 @@ +using System.Threading.Tasks; +using AutoMapper; +using MediatR; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using StudySharp.API.Requests.TheoryBlocks; +using StudySharp.ApplicationServices.Commands; +using StudySharp.Domain.General; + +namespace StudySharp.API.Controllers +{ + [Authorize] + [ApiController] + [Route("api/[controller]")] + + public class TheoryBlockController : ControllerBase + { + private readonly IMediator _mediator; + private readonly IMapper _mapper; + + public TheoryBlockController(IMediator mediator, IMapper mapper) + { + _mapper = mapper; + _mediator = mediator; + } + + [HttpPost("add")] + public async Task Add([FromBody] AddTheoryBlockRequest addTheoryBlockRequest) + { + var addTheoryBlockCommand = _mapper.Map(addTheoryBlockRequest); + return await _mediator.Send(addTheoryBlockCommand); + } + + [HttpPost("remove")] + public async Task Remove([FromBody] RemoveTheoryBlockByIdRequest removeTheoryBlockByIdRequest) + { + var removeTheoryBlockByIdCommand = _mapper.Map(removeTheoryBlockByIdRequest); + return await _mediator.Send(removeTheoryBlockByIdCommand); + } + } +} \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs new file mode 100644 index 0000000..fdeb42f --- /dev/null +++ b/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs @@ -0,0 +1,8 @@ +namespace StudySharp.API.Requests.TheoryBlocks +{ + public class AddTheoryBlockRequest + { + public string Name { get; set; } + public int CourseId { get; set; } + } +} \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs new file mode 100644 index 0000000..e47f5a4 --- /dev/null +++ b/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs @@ -0,0 +1,7 @@ +namespace StudySharp.API.Requests.TheoryBlocks +{ + public class RemoveTheoryBlockByIdRequest + { + public int Id { get; set; } + } +} \ No newline at end of file From 852e0783221fcd6221a51569a231f855000c7f53 Mon Sep 17 00:00:00 2001 From: SleepyF0X Date: Sat, 25 Sep 2021 13:16:30 +0300 Subject: [PATCH 09/30] Fix Equals and code style --- .../Commands/AddCourseCommand.cs | 13 ++++++++----- .../Commands/AddTheoryBlockCommand.cs | 15 ++++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/server/StudySharp.ApplicationServices/Commands/AddCourseCommand.cs b/server/StudySharp.ApplicationServices/Commands/AddCourseCommand.cs index 55bc550..f0fd2e6 100644 --- a/server/StudySharp.ApplicationServices/Commands/AddCourseCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/AddCourseCommand.cs @@ -26,19 +26,22 @@ public AddCourseCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(AddCourseCommand request, CancellationToken cancellationToken) { - if (await _context.Courses.AnyAsync(с => Equals(с.Name.ToLower(), request.Name.ToLower()) && с.TeacherId == request.TeacherId, cancellationToken)) + if (await _context.Courses.AnyAsync( + _ => _.Name.ToLower().Equals(request.Name.ToLower()) && _.TeacherId == request.TeacherId, + cancellationToken)) { return OperationResult.Fail(string.Format(ErrorConstants.EntityAlreadyExists, nameof(Course), nameof(Course.Name), request.Name)); } await _context.Courses.AddAsync( new Course - { - Name = request.Name, TeacherId = request.TeacherId, - }, cancellationToken); + { + Name = request.Name, + TeacherId = request.TeacherId, + }, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return OperationResult.Ok(); } } -} \ No newline at end of file +} diff --git a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs index a6bad66..aef2848 100644 --- a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs @@ -12,6 +12,7 @@ namespace StudySharp.ApplicationServices.Commands public sealed class AddTheoryBlockCommand : IRequest { public string Name { get; set; } + public string Description { get; set; } public int CourseId { get; set; } } @@ -26,19 +27,23 @@ public AddTheoryBlockCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(AddTheoryBlockCommand request, CancellationToken cancellationToken) { - if (await _context.TheoryBlocks.AnyAsync(_ => Equals(_.Name.ToLower(), request.Name.ToLower()) && _.CourseId == request.CourseId, cancellationToken)) + if (await _context.TheoryBlocks.AnyAsync( + _ => _.Name.ToLower().Equals(request.Name.ToLower()) && _.CourseId == request.CourseId, + cancellationToken)) { return OperationResult.Fail(string.Format(ErrorConstants.EntityAlreadyExists, nameof(TheoryBlock), nameof(TheoryBlock.Name), request.Name)); } await _context.TheoryBlocks.AddAsync( new TheoryBlock - { - Name = request.Name, CourseId = request.CourseId, - }, cancellationToken); + { + Name = request.Name, + CourseId = request.CourseId, + Description = request.Description, + }, cancellationToken); await _context.SaveChangesAsync(cancellationToken); return OperationResult.Ok(); } } -} \ No newline at end of file +} From 8ca9cc7716e1c44ad7f5874496ac7aa6938a39f4 Mon Sep 17 00:00:00 2001 From: zefirlover Date: Sat, 25 Sep 2021 13:45:45 +0300 Subject: [PATCH 10/30] HttpGet by Id added into TheoryBlockController.cs and other minor changes Added: GetTheoryBlockByIdRequest GetTheoryBlockByIdResponse GetTheoryBlocksRequest GetTheoryBlocksResponse TheoryBlockProfile --- .../Controllers/TheoryBlockController.cs | 17 +++++++++++++++++ .../MapperProfiles/TheoryBlockProfile.cs | 17 +++++++++++++++++ .../TheoryBlocks/GetTheoryBlockByIdRequest.cs | 7 +++++++ .../TheoryBlocks/GetTheoryBlocksRequest.cs | 9 +++++++++ .../TheoryBlocks/GetTheoryBlockByIdResponse.cs | 13 +++++++++++++ .../TheoryBlocks/GetTheoryBlocksResponse.cs | 10 ++++++++++ 6 files changed, 73 insertions(+) create mode 100644 server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs create mode 100644 server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs create mode 100644 server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlocksRequest.cs create mode 100644 server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlockByIdResponse.cs create mode 100644 server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlocksResponse.cs diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index b9db8a7..7ba7b29 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -4,7 +4,9 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using StudySharp.API.Requests.TheoryBlocks; +using StudySharp.API.Responses.TheoryBlocks; using StudySharp.ApplicationServices.Commands; +using StudySharp.ApplicationServices.Queries; using StudySharp.Domain.General; namespace StudySharp.API.Controllers @@ -37,5 +39,20 @@ public async Task Remove([FromBody] RemoveTheoryBlockByIdReques var removeTheoryBlockByIdCommand = _mapper.Map(removeTheoryBlockByIdRequest); return await _mediator.Send(removeTheoryBlockByIdCommand); } + + [HttpGet] + public async Task GetTheoryBlockById([FromBody] GetTheoryBlockByIdRequest getTheoryBlockByIdRequest) + { + var getTheoryBlockByIdQuery = _mapper.Map(getTheoryBlockByIdRequest); + var operationResult = await _mediator.Send(getTheoryBlockByIdQuery); + + if (!operationResult.IsSucceeded) + { + return OperationResult.Fail(operationResult.Errors); + } + + var response = _mapper.Map(operationResult.Result); + return OperationResult.Ok(response); + } } } \ No newline at end of file diff --git a/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs b/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs new file mode 100644 index 0000000..839ea66 --- /dev/null +++ b/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs @@ -0,0 +1,17 @@ +using AutoMapper; +using StudySharp.API.Requests.TheoryBlocks; +using StudySharp.ApplicationServices.Commands; +using StudySharp.ApplicationServices.Queries; + +namespace StudySharp.API.MapperProfiles +{ + public class TheoryBlockProfile : Profile + { + public TheoryBlockProfile() + { + CreateMap(); + CreateMap(); + CreateMap(); + } + } +} \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs new file mode 100644 index 0000000..7098ad8 --- /dev/null +++ b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs @@ -0,0 +1,7 @@ +namespace StudySharp.API.Requests.TheoryBlocks +{ + public class GetTheoryBlockByIdRequest + { + public int Id { get; set; } + } +} \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlocksRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlocksRequest.cs new file mode 100644 index 0000000..f6f3c60 --- /dev/null +++ b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlocksRequest.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; +using StudySharp.Domain.Models; + +namespace StudySharp.API.Requests.TheoryBlocks +{ + public class GetTheoryBlocksRequest + { + } +} \ No newline at end of file diff --git a/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlockByIdResponse.cs b/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlockByIdResponse.cs new file mode 100644 index 0000000..16f1b4b --- /dev/null +++ b/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlockByIdResponse.cs @@ -0,0 +1,13 @@ +using StudySharp.Domain.Models; + +namespace StudySharp.API.Responses.TheoryBlocks +{ + public class GetTheoryBlockByIdResponse + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public int CourseId { get; set; } + public Course Course { get; set; } + } +} \ No newline at end of file diff --git a/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlocksResponse.cs b/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlocksResponse.cs new file mode 100644 index 0000000..302b776 --- /dev/null +++ b/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlocksResponse.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using StudySharp.Domain.Models; + +namespace StudySharp.API.Responses.TheoryBlocks +{ + public class GetTheoryBlocksResponse + { + public List TheoryBlocks { get; set; } + } +} \ No newline at end of file From c718f990f05577f37fa1dcebb2482fd86fdebfdc Mon Sep 17 00:00:00 2001 From: zefirlover Date: Sun, 26 Sep 2021 18:26:54 +0300 Subject: [PATCH 11/30] After review update --- .../Controllers/TheoryBlockController.cs | 16 ++++++++-------- .../TheoryBlocks/GetTheoryBlockByIdRequest.cs | 3 +++ .../TheoryBlocks/RemoveTheoryBlockByIdRequest.cs | 3 +++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index 7ba7b29..eda00af 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -13,7 +13,7 @@ namespace StudySharp.API.Controllers { [Authorize] [ApiController] - [Route("api/[controller]")] + [Route("api/theory-blocks")] public class TheoryBlockController : ControllerBase { @@ -26,33 +26,33 @@ public TheoryBlockController(IMediator mediator, IMapper mapper) _mediator = mediator; } - [HttpPost("add")] + [HttpPost] public async Task Add([FromBody] AddTheoryBlockRequest addTheoryBlockRequest) { var addTheoryBlockCommand = _mapper.Map(addTheoryBlockRequest); return await _mediator.Send(addTheoryBlockCommand); } - [HttpPost("remove")] - public async Task Remove([FromBody] RemoveTheoryBlockByIdRequest removeTheoryBlockByIdRequest) + [HttpDelete("{id:int}")] + public async Task Remove([FromRoute] RemoveTheoryBlockByIdRequest removeTheoryBlockByIdRequest) { var removeTheoryBlockByIdCommand = _mapper.Map(removeTheoryBlockByIdRequest); return await _mediator.Send(removeTheoryBlockByIdCommand); } - [HttpGet] - public async Task GetTheoryBlockById([FromBody] GetTheoryBlockByIdRequest getTheoryBlockByIdRequest) + [HttpGet("{id:int}")] + public async Task> GetTheoryBlockById([FromRoute] GetTheoryBlockByIdRequest getTheoryBlockByIdRequest) { var getTheoryBlockByIdQuery = _mapper.Map(getTheoryBlockByIdRequest); var operationResult = await _mediator.Send(getTheoryBlockByIdQuery); if (!operationResult.IsSucceeded) { - return OperationResult.Fail(operationResult.Errors); + return OperationResult.Fail(operationResult.Errors); } var response = _mapper.Map(operationResult.Result); - return OperationResult.Ok(response); + return OperationResult.Ok(response); } } } \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs index 7098ad8..e2d4615 100644 --- a/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs +++ b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs @@ -1,7 +1,10 @@ +using Microsoft.AspNetCore.Mvc; + namespace StudySharp.API.Requests.TheoryBlocks { public class GetTheoryBlockByIdRequest { + [BindProperty(Name = "id", SupportsGet = true)] public int Id { get; set; } } } \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs index e47f5a4..4d15d51 100644 --- a/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs +++ b/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs @@ -1,7 +1,10 @@ +using Microsoft.AspNetCore.Mvc; + namespace StudySharp.API.Requests.TheoryBlocks { public class RemoveTheoryBlockByIdRequest { + [BindProperty(Name = "id", SupportsGet = true)] public int Id { get; set; } } } \ No newline at end of file From 3163021ae1a4e361a685eaf85ef44919399274c2 Mon Sep 17 00:00:00 2001 From: zefirlover Date: Sun, 26 Sep 2021 19:33:22 +0300 Subject: [PATCH 12/30] Remove stupid generics --- server/StudySharp.API/Controllers/TheoryBlockController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index eda00af..2340e7b 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -48,11 +48,11 @@ public async Task> GetTheoryBlockByI if (!operationResult.IsSucceeded) { - return OperationResult.Fail(operationResult.Errors); + return OperationResult.Fail(operationResult.Errors); } var response = _mapper.Map(operationResult.Result); - return OperationResult.Ok(response); + return OperationResult.Ok(response); } } } \ No newline at end of file From a5fe2bea2abb41e78694860e3fdb45fc44d3940b Mon Sep 17 00:00:00 2001 From: zefirlover Date: Mon, 27 Sep 2021 12:53:25 +0300 Subject: [PATCH 13/30] GetTheoryBlockByCourseId pre-update Add GetTheoryBlockByCourseIdRequest and GetTheoryBlockByCourseIdResponse Add GetTheoryBlockByCourseId logic to the TheoryBlockController.cs, now commented due to lack of some queries --- .../Controllers/TheoryBlockController.cs | 17 ++++++++++++++++- .../GetTheoryBlockByCourseIdRequest.cs | 10 ++++++++++ .../GetTheoryBlockByCourseIdResponse.cs | 13 +++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByCourseIdRequest.cs create mode 100644 server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlockByCourseIdResponse.cs diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index 2340e7b..be3df07 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -53,6 +53,21 @@ public async Task> GetTheoryBlockByI var response = _mapper.Map(operationResult.Result); return OperationResult.Ok(response); - } + }/* + + [HttpGet("{courseId:int}")] + public async Task> GetTheoryBlockByCourseId([FromRoute] GetTheoryBlockByCourseIdRequest getTheoryBlockByCourseIdRequest) + { + var getTheoryBlockByCourseIdQuery = _mapper.Map(getTheoryBlockByCourseIdRequest); + var operationResult = await _mediator.Send(getTheoryBlockByCourseIdQuery); + + if (!operationResult.IsSucceeded) + { + return OperationResult.Fail(operationResult.Errors); + } + + var response = _mapper.Map(operationResult.Result); + return OperationResult.Ok(response); + }*/ } } \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByCourseIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByCourseIdRequest.cs new file mode 100644 index 0000000..ec1a1a0 --- /dev/null +++ b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByCourseIdRequest.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Mvc; + +namespace StudySharp.API.Requests.TheoryBlocks +{ + public class GetTheoryBlockByCourseIdRequest + { + [BindProperty(Name = "courseId", SupportsGet = true)] + public int CourseId { get; set; } + } +} \ No newline at end of file diff --git a/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlockByCourseIdResponse.cs b/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlockByCourseIdResponse.cs new file mode 100644 index 0000000..f1e05fc --- /dev/null +++ b/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlockByCourseIdResponse.cs @@ -0,0 +1,13 @@ +using StudySharp.Domain.Models; + +namespace StudySharp.API.Responses.TheoryBlocks +{ + public class GetTheoryBlockByCourseIdResponse + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public int CourseId { get; set; } + public Course Course { get; set; } + } +} \ No newline at end of file From 6d3d9fe4bbf1a5d2eefea3d38eb3aa2acf2834c7 Mon Sep 17 00:00:00 2001 From: zefirlover Date: Tue, 28 Sep 2021 23:10:05 +0300 Subject: [PATCH 14/30] Add "Update" functionality to the TheoryBlockController --- .../Controllers/TheoryBlockController.cs | 18 +++++++- .../MapperProfiles/TheoryBlockProfile.cs | 1 + .../UpdateTheoryBlockByIdRequest.cs | 10 +++++ .../TheoryBlocks/UpdateTheoryBlockResponce.cs | 6 +++ .../Commands/UpdateTheoryBlockCommand.cs | 44 +++++++++++++++++++ 5 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs create mode 100644 server/StudySharp.API/Responses/TheoryBlocks/UpdateTheoryBlockResponce.cs create mode 100644 server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index be3df07..4214f39 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -53,8 +53,24 @@ public async Task> GetTheoryBlockByI var response = _mapper.Map(operationResult.Result); return OperationResult.Ok(response); - }/* + } + + [HttpPut("{id:int}")] + public async Task> Update([FromRoute] UpdateTheoryBlockByIdRequest updateTheoryBlockByIdRequest) + { + var updateTheoryBlockCommand = _mapper.Map(updateTheoryBlockByIdRequest); + var operationResult = await _mediator.Send(updateTheoryBlockCommand); + + if (!operationResult.IsSucceeded) + { + return OperationResult.Fail(operationResult.Errors); + } + + var response = _mapper.Map(operationResult); + return OperationResult.Ok(response); + } + /* [HttpGet("{courseId:int}")] public async Task> GetTheoryBlockByCourseId([FromRoute] GetTheoryBlockByCourseIdRequest getTheoryBlockByCourseIdRequest) { diff --git a/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs b/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs index 839ea66..b4237d5 100644 --- a/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs +++ b/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs @@ -12,6 +12,7 @@ public TheoryBlockProfile() CreateMap(); CreateMap(); CreateMap(); + CreateMap(); } } } \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs new file mode 100644 index 0000000..5604e58 --- /dev/null +++ b/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs @@ -0,0 +1,10 @@ +using Microsoft.AspNetCore.Mvc; + +namespace StudySharp.API.Requests.TheoryBlocks +{ + public class UpdateTheoryBlockByIdRequest + { + [BindProperty(Name = "id", SupportsGet = true)] + public int Id { get; set; } + } +} \ No newline at end of file diff --git a/server/StudySharp.API/Responses/TheoryBlocks/UpdateTheoryBlockResponce.cs b/server/StudySharp.API/Responses/TheoryBlocks/UpdateTheoryBlockResponce.cs new file mode 100644 index 0000000..04e2d78 --- /dev/null +++ b/server/StudySharp.API/Responses/TheoryBlocks/UpdateTheoryBlockResponce.cs @@ -0,0 +1,6 @@ +namespace StudySharp.API.Responses.TheoryBlocks +{ + public class UpdateTheoryBlockResponce + { + } +} \ No newline at end of file diff --git a/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs b/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs new file mode 100644 index 0000000..40768da --- /dev/null +++ b/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs @@ -0,0 +1,44 @@ +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using StudySharp.Domain.Constants; +using StudySharp.Domain.General; +using StudySharp.Domain.Models; +using StudySharp.DomainServices; + +namespace StudySharp.ApplicationServices.Commands +{ + public sealed class UpdateTheoryBlockCommand : IRequest + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + } + + public sealed class UpdateTheoryBlockCommandHandler : IRequestHandler + { + private readonly StudySharpDbContext _context; + + public UpdateTheoryBlockCommandHandler(StudySharpDbContext sharpDbContext) + { + _context = sharpDbContext; + } + + public async Task Handle(UpdateTheoryBlockCommand request, CancellationToken cancellationToken) + { + var theoryBlock = await _context.TheoryBlocks.FindAsync(request.Id, cancellationToken); + + if (theoryBlock == null) + { + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Name), request.Id)); + } + + theoryBlock.Name = request.Name; + theoryBlock.Description = request.Description; + + _context.TheoryBlocks.Update(theoryBlock); + await _context.SaveChangesAsync(cancellationToken); + return OperationResult.Ok(); + } + } +} \ No newline at end of file From 35725c11047152e8a3aa155d918fe6e6bb781c47 Mon Sep 17 00:00:00 2001 From: zefirlover Date: Fri, 1 Oct 2021 14:19:49 +0300 Subject: [PATCH 15/30] Add GetTheoryBlockByCourseId Add GetTheoryBlockByCourseIdQuery Uncomment code in TheoryBlockController.cs --- .../Controllers/TheoryBlockController.cs | 3 +- .../Queries/GetTheoryBlockByCourseIdQuery.cs | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index 4214f39..8232739 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -70,7 +70,6 @@ public async Task> Update([FromRoute] return OperationResult.Ok(response); } - /* [HttpGet("{courseId:int}")] public async Task> GetTheoryBlockByCourseId([FromRoute] GetTheoryBlockByCourseIdRequest getTheoryBlockByCourseIdRequest) { @@ -84,6 +83,6 @@ public async Task> GetTheoryBl var response = _mapper.Map(operationResult.Result); return OperationResult.Ok(response); - }*/ + } } } \ No newline at end of file diff --git a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs new file mode 100644 index 0000000..6abe694 --- /dev/null +++ b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs @@ -0,0 +1,36 @@ +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using StudySharp.Domain.Constants; +using StudySharp.Domain.General; +using StudySharp.Domain.Models; +using StudySharp.DomainServices; + +namespace StudySharp.ApplicationServices.Queries +{ + public sealed class GetTheoryBlockByCourseIdQuery : IRequest> + { + public int CourseId { get; set; } + } + + public sealed class GetTheoryBlockByCourseIdQueryHandler : IRequestHandler> + { + private readonly StudySharpDbContext _context; + + public GetTheoryBlockByCourseIdQueryHandler(StudySharpDbContext studySharpDbContext) + { + _context = studySharpDbContext; + } + + public async Task> Handle(GetTheoryBlockByCourseIdQuery request, CancellationToken cancellationToken) + { + var theoryBlock = await _context.TheoryBlocks.FindAsync(request.CourseId, cancellationToken); + if (theoryBlock == null) + { + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Id), request.CourseId)); + } + + return OperationResult.Ok(theoryBlock); + } + } +} \ No newline at end of file From ee7f7c5460706b7cadb5790a71906141ce789088 Mon Sep 17 00:00:00 2001 From: zefirlover Date: Fri, 1 Oct 2021 21:14:44 +0300 Subject: [PATCH 16/30] Pre-rewrite update --- server/StudySharp.API/Controllers/TheoryBlockController.cs | 6 +++--- .../Requests/TheoryBlocks/AddTheoryBlockRequest.cs | 1 + .../Commands/RemoveTheoryBlockByIdCommand.cs | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index 8232739..c1152c7 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -11,9 +11,9 @@ namespace StudySharp.API.Controllers { - [Authorize] + // [Authorize] [ApiController] - [Route("api/theory-blocks")] + [Route("api/courses")] public class TheoryBlockController : ControllerBase { @@ -70,7 +70,7 @@ public async Task> Update([FromRoute] return OperationResult.Ok(response); } - [HttpGet("{courseId:int}")] + [HttpGet("course/{courseId:int}")] public async Task> GetTheoryBlockByCourseId([FromRoute] GetTheoryBlockByCourseIdRequest getTheoryBlockByCourseIdRequest) { var getTheoryBlockByCourseIdQuery = _mapper.Map(getTheoryBlockByCourseIdRequest); diff --git a/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs index fdeb42f..7c6b08c 100644 --- a/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs +++ b/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs @@ -3,6 +3,7 @@ namespace StudySharp.API.Requests.TheoryBlocks public class AddTheoryBlockRequest { public string Name { get; set; } + public string Description { get; set; } public int CourseId { get; set; } } } \ No newline at end of file diff --git a/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs b/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs index f97318b..14758f4 100644 --- a/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs @@ -26,11 +26,11 @@ public async Task Handle( RemoveTheoryBlockByIdCommand request, CancellationToken cancellationToken) { - var theoryBlock = await _context.TheoryBlocks.FindAsync(request.Id, cancellationToken); + var theoryBlock = await _context.TheoryBlocks.FindAsync(request.Id); if (theoryBlock == null) { - return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Name), request.Id)); + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Id), request.Id)); } _context.TheoryBlocks.Remove(theoryBlock); From ca150d9aef01c486d96d0145e357881a8267f3fb Mon Sep 17 00:00:00 2001 From: zefirlover Date: Fri, 1 Oct 2021 22:44:30 +0300 Subject: [PATCH 17/30] Major update of the TheoryBlockController TheoryBlockController now works like a part of Course Remove GetTheoryBlocksRequest.cs due to is uselessness Other minor changes due to adding CourseId validation --- .../Controllers/TheoryBlockController.cs | 24 +++++++++---------- .../TheoryBlocks/GetTheoryBlockByIdRequest.cs | 1 + ...cs => GetTheoryBlocksByCourseIdRequest.cs} | 2 +- .../TheoryBlocks/GetTheoryBlocksRequest.cs | 9 ------- .../RemoveTheoryBlockByIdRequest.cs | 1 + .../UpdateTheoryBlockByIdRequest.cs | 1 + .../GetTheoryBlockByCourseIdResponse.cs | 13 ---------- .../GetTheoryBlocksByCourseIdResponse.cs | 10 ++++++++ ...sponce.cs => UpdateTheoryBlockResponse.cs} | 2 +- .../Commands/RemoveTheoryBlockByIdCommand.cs | 10 ++++---- .../Commands/UpdateTheoryBlockCommand.cs | 6 +++-- .../Queries/GetTheoryBlockByIdQuery.cs | 10 ++++---- 12 files changed, 41 insertions(+), 48 deletions(-) rename server/StudySharp.API/Requests/TheoryBlocks/{GetTheoryBlockByCourseIdRequest.cs => GetTheoryBlocksByCourseIdRequest.cs} (79%) delete mode 100644 server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlocksRequest.cs delete mode 100644 server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlockByCourseIdResponse.cs create mode 100644 server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlocksByCourseIdResponse.cs rename server/StudySharp.API/Responses/TheoryBlocks/{UpdateTheoryBlockResponce.cs => UpdateTheoryBlockResponse.cs} (59%) diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index c1152c7..a293c40 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -11,7 +11,7 @@ namespace StudySharp.API.Controllers { - // [Authorize] + [Authorize] [ApiController] [Route("api/courses")] @@ -26,21 +26,21 @@ public TheoryBlockController(IMediator mediator, IMapper mapper) _mediator = mediator; } - [HttpPost] + [HttpPost("{courseId:int}/theory-blocks")] public async Task Add([FromBody] AddTheoryBlockRequest addTheoryBlockRequest) { var addTheoryBlockCommand = _mapper.Map(addTheoryBlockRequest); return await _mediator.Send(addTheoryBlockCommand); } - [HttpDelete("{id:int}")] + [HttpDelete("{courseId:int}/theory-blocks/{theoryBlockId:int}")] public async Task Remove([FromRoute] RemoveTheoryBlockByIdRequest removeTheoryBlockByIdRequest) { var removeTheoryBlockByIdCommand = _mapper.Map(removeTheoryBlockByIdRequest); return await _mediator.Send(removeTheoryBlockByIdCommand); } - [HttpGet("{id:int}")] + [HttpGet("{courseId:int}/theory-blocks/{theoryBlockId:int}")] public async Task> GetTheoryBlockById([FromRoute] GetTheoryBlockByIdRequest getTheoryBlockByIdRequest) { var getTheoryBlockByIdQuery = _mapper.Map(getTheoryBlockByIdRequest); @@ -55,33 +55,33 @@ public async Task> GetTheoryBlockByI return OperationResult.Ok(response); } - [HttpPut("{id:int}")] - public async Task> Update([FromRoute] UpdateTheoryBlockByIdRequest updateTheoryBlockByIdRequest) + [HttpPut("{courseId:int}/theory-blocks/{theoryBlockId:int}")] + public async Task> Update([FromRoute] UpdateTheoryBlockByIdRequest updateTheoryBlockByIdRequest) { var updateTheoryBlockCommand = _mapper.Map(updateTheoryBlockByIdRequest); var operationResult = await _mediator.Send(updateTheoryBlockCommand); if (!operationResult.IsSucceeded) { - return OperationResult.Fail(operationResult.Errors); + return OperationResult.Fail(operationResult.Errors); } - var response = _mapper.Map(operationResult); + var response = _mapper.Map(operationResult); return OperationResult.Ok(response); } - [HttpGet("course/{courseId:int}")] - public async Task> GetTheoryBlockByCourseId([FromRoute] GetTheoryBlockByCourseIdRequest getTheoryBlockByCourseIdRequest) + [HttpGet("{courseId:int}/theory-blocks")] + public async Task> GetTheoryBlockByCourseId([FromRoute] GetTheoryBlocksByCourseIdRequest getTheoryBlockByCourseIdRequest) { var getTheoryBlockByCourseIdQuery = _mapper.Map(getTheoryBlockByCourseIdRequest); var operationResult = await _mediator.Send(getTheoryBlockByCourseIdQuery); if (!operationResult.IsSucceeded) { - return OperationResult.Fail(operationResult.Errors); + return OperationResult.Fail(operationResult.Errors); } - var response = _mapper.Map(operationResult.Result); + var response = _mapper.Map(operationResult.Result); return OperationResult.Ok(response); } } diff --git a/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs index e2d4615..e79eacc 100644 --- a/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs +++ b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs @@ -6,5 +6,6 @@ public class GetTheoryBlockByIdRequest { [BindProperty(Name = "id", SupportsGet = true)] public int Id { get; set; } + public int CourseId { get; set; } } } \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByCourseIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlocksByCourseIdRequest.cs similarity index 79% rename from server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByCourseIdRequest.cs rename to server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlocksByCourseIdRequest.cs index ec1a1a0..a1842fb 100644 --- a/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByCourseIdRequest.cs +++ b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlocksByCourseIdRequest.cs @@ -2,7 +2,7 @@ namespace StudySharp.API.Requests.TheoryBlocks { - public class GetTheoryBlockByCourseIdRequest + public class GetTheoryBlocksByCourseIdRequest { [BindProperty(Name = "courseId", SupportsGet = true)] public int CourseId { get; set; } diff --git a/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlocksRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlocksRequest.cs deleted file mode 100644 index f6f3c60..0000000 --- a/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlocksRequest.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections.Generic; -using StudySharp.Domain.Models; - -namespace StudySharp.API.Requests.TheoryBlocks -{ - public class GetTheoryBlocksRequest - { - } -} \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs index 4d15d51..8943371 100644 --- a/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs +++ b/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs @@ -6,5 +6,6 @@ public class RemoveTheoryBlockByIdRequest { [BindProperty(Name = "id", SupportsGet = true)] public int Id { get; set; } + public int CourseId { get; set; } } } \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs index 5604e58..d5a092e 100644 --- a/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs +++ b/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs @@ -6,5 +6,6 @@ public class UpdateTheoryBlockByIdRequest { [BindProperty(Name = "id", SupportsGet = true)] public int Id { get; set; } + public int CourseId { get; set; } } } \ No newline at end of file diff --git a/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlockByCourseIdResponse.cs b/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlockByCourseIdResponse.cs deleted file mode 100644 index f1e05fc..0000000 --- a/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlockByCourseIdResponse.cs +++ /dev/null @@ -1,13 +0,0 @@ -using StudySharp.Domain.Models; - -namespace StudySharp.API.Responses.TheoryBlocks -{ - public class GetTheoryBlockByCourseIdResponse - { - public int Id { get; set; } - public string Name { get; set; } - public string Description { get; set; } - public int CourseId { get; set; } - public Course Course { get; set; } - } -} \ No newline at end of file diff --git a/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlocksByCourseIdResponse.cs b/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlocksByCourseIdResponse.cs new file mode 100644 index 0000000..6724174 --- /dev/null +++ b/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlocksByCourseIdResponse.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using StudySharp.Domain.Models; + +namespace StudySharp.API.Responses.TheoryBlocks +{ + public class GetTheoryBlocksByCourseIdResponse + { + public List TheoryBlocks { get; set; } + } +} \ No newline at end of file diff --git a/server/StudySharp.API/Responses/TheoryBlocks/UpdateTheoryBlockResponce.cs b/server/StudySharp.API/Responses/TheoryBlocks/UpdateTheoryBlockResponse.cs similarity index 59% rename from server/StudySharp.API/Responses/TheoryBlocks/UpdateTheoryBlockResponce.cs rename to server/StudySharp.API/Responses/TheoryBlocks/UpdateTheoryBlockResponse.cs index 04e2d78..9c48a56 100644 --- a/server/StudySharp.API/Responses/TheoryBlocks/UpdateTheoryBlockResponce.cs +++ b/server/StudySharp.API/Responses/TheoryBlocks/UpdateTheoryBlockResponse.cs @@ -1,6 +1,6 @@ namespace StudySharp.API.Responses.TheoryBlocks { - public class UpdateTheoryBlockResponce + public class UpdateTheoryBlockResponse { } } \ No newline at end of file diff --git a/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs b/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs index 14758f4..7618408 100644 --- a/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs @@ -1,6 +1,7 @@ using System.Threading; using System.Threading.Tasks; using MediatR; +using Microsoft.EntityFrameworkCore; using StudySharp.Domain.Constants; using StudySharp.Domain.General; using StudySharp.Domain.Models; @@ -11,6 +12,7 @@ namespace StudySharp.ApplicationServices.Commands public sealed class RemoveTheoryBlockByIdCommand : IRequest { public int Id { get; set; } + public int CourseId { get; set; } } public sealed class RemoveTheoryBlockByIdCommandHandler : IRequestHandler @@ -22,15 +24,13 @@ public RemoveTheoryBlockByIdCommandHandler(StudySharpDbContext sharpDbContext) _context = sharpDbContext; } - public async Task Handle( - RemoveTheoryBlockByIdCommand request, - CancellationToken cancellationToken) + public async Task Handle(RemoveTheoryBlockByIdCommand request, CancellationToken cancellationToken) { - var theoryBlock = await _context.TheoryBlocks.FindAsync(request.Id); + var theoryBlock = await _context.TheoryBlocks.FirstOrDefaultAsync(_ => _.Id == request.Id && _.CourseId == request.CourseId); if (theoryBlock == null) { - return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Id), request.Id)); + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Id), nameof(TheoryBlock.CourseId), request.Id, request.CourseId)); } _context.TheoryBlocks.Remove(theoryBlock); diff --git a/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs b/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs index 40768da..40af187 100644 --- a/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs @@ -1,6 +1,7 @@ using System.Threading; using System.Threading.Tasks; using MediatR; +using Microsoft.EntityFrameworkCore; using StudySharp.Domain.Constants; using StudySharp.Domain.General; using StudySharp.Domain.Models; @@ -11,6 +12,7 @@ namespace StudySharp.ApplicationServices.Commands public sealed class UpdateTheoryBlockCommand : IRequest { public int Id { get; set; } + public int CourseId { get; set; } public string Name { get; set; } public string Description { get; set; } } @@ -26,11 +28,11 @@ public UpdateTheoryBlockCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(UpdateTheoryBlockCommand request, CancellationToken cancellationToken) { - var theoryBlock = await _context.TheoryBlocks.FindAsync(request.Id, cancellationToken); + var theoryBlock = await _context.TheoryBlocks.FirstOrDefaultAsync(_ => _.Id == request.Id && _.CourseId == request.CourseId, cancellationToken); if (theoryBlock == null) { - return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Name), request.Id)); + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Name), nameof(TheoryBlock.CourseId), request.Id, request.CourseId)); } theoryBlock.Name = request.Name; diff --git a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs index c471503..7c3469a 100644 --- a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs +++ b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs @@ -1,6 +1,7 @@ using System.Threading; using System.Threading.Tasks; using MediatR; +using Microsoft.EntityFrameworkCore; using StudySharp.Domain.Constants; using StudySharp.Domain.General; using StudySharp.Domain.Models; @@ -11,6 +12,7 @@ namespace StudySharp.ApplicationServices.Queries public sealed class GetTheoryBlockByIdQuery : IRequest> { public int Id { get; set; } + public int CourseId { get; set; } } public sealed class GetTheoryBlockByIdQueryHandler : IRequestHandler> @@ -22,14 +24,12 @@ public GetTheoryBlockByIdQueryHandler(StudySharpDbContext studySharpDbContext) _context = studySharpDbContext; } - public async Task> Handle( - GetTheoryBlockByIdQuery request, - CancellationToken cancellationToken) + public async Task> Handle(GetTheoryBlockByIdQuery request, CancellationToken cancellationToken) { - var theoryBlock = await _context.TheoryBlocks.FindAsync(request.Id, cancellationToken); + var theoryBlock = await _context.TheoryBlocks.FirstOrDefaultAsync(_ => _.Id == request.Id && _.CourseId == request.CourseId, cancellationToken); if (theoryBlock == null) { - return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Id), request.Id)); + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Id), nameof(TheoryBlock.CourseId), request.Id, request.CourseId)); } return OperationResult.Ok(theoryBlock); From 88da422589eb5a6487d7ce7d0c1fc2a167f65f4c Mon Sep 17 00:00:00 2001 From: zefirlover Date: Fri, 1 Oct 2021 22:55:18 +0300 Subject: [PATCH 18/30] GetTheoryBlockByCourseIdQuery returns a List of TheoryBlocks if theoryBlock == null --- .../Queries/GetTheoryBlockByCourseIdQuery.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs index 6abe694..88a2513 100644 --- a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs +++ b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs @@ -27,7 +27,7 @@ public async Task> Handle(GetTheoryBlockByCourseIdQ var theoryBlock = await _context.TheoryBlocks.FindAsync(request.CourseId, cancellationToken); if (theoryBlock == null) { - return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Id), request.CourseId)); + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.TheoryBlocks), request.CourseId)); } return OperationResult.Ok(theoryBlock); From 9f0b2a217653eb4d77986626a1ff9f64b6a907bc Mon Sep 17 00:00:00 2001 From: zefirlover Date: Fri, 1 Oct 2021 23:45:52 +0300 Subject: [PATCH 19/30] Pull update from dev --- .../Controllers/TheoryBlockController.cs | 3 +- .../20210925114723_Init.Designer.cs | 495 ------------------ .../Migrations/20210925114723_Init.cs | 402 -------------- .../StudySharpDbContextModelSnapshot.cs | 493 ----------------- 4 files changed, 2 insertions(+), 1391 deletions(-) delete mode 100644 server/StudySharp.DomainServices/Migrations/20210925114723_Init.Designer.cs delete mode 100644 server/StudySharp.DomainServices/Migrations/20210925114723_Init.cs delete mode 100644 server/StudySharp.DomainServices/Migrations/StudySharpDbContextModelSnapshot.cs diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index a293c40..d305f2d 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -11,7 +11,7 @@ namespace StudySharp.API.Controllers { - [Authorize] + // [Authorize] [ApiController] [Route("api/courses")] @@ -20,6 +20,7 @@ public class TheoryBlockController : ControllerBase private readonly IMediator _mediator; private readonly IMapper _mapper; + // comment to made commit with dev update public TheoryBlockController(IMediator mediator, IMapper mapper) { _mapper = mapper; diff --git a/server/StudySharp.DomainServices/Migrations/20210925114723_Init.Designer.cs b/server/StudySharp.DomainServices/Migrations/20210925114723_Init.Designer.cs deleted file mode 100644 index 6c147d8..0000000 --- a/server/StudySharp.DomainServices/Migrations/20210925114723_Init.Designer.cs +++ /dev/null @@ -1,495 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using StudySharp.DomainServices; - -namespace StudySharp.DomainServices.Migrations -{ - [DbContext(typeof(StudySharpDbContext))] - [Migration("20210925114723_Init")] - partial class Init - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("Relational:MaxIdentifierLength", 63) - .HasAnnotation("ProductVersion", "5.0.10") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - modelBuilder.Entity("CourseTag", b => - { - b.Property("CoursesId") - .HasColumnType("integer"); - - b.Property("TagsId") - .HasColumnType("integer"); - - b.HasKey("CoursesId", "TagsId"); - - b.HasIndex("TagsId"); - - b.ToTable("CourseTag"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("AspNetRoles"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("integer"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("integer"); - - b.Property("RoleId") - .HasColumnType("integer"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("integer"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Course", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("DateCreated") - .HasColumnType("timestamp with time zone"); - - b.Property("DateModified") - .HasColumnType("timestamp with time zone"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("TeacherId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("TeacherId"); - - b.ToTable("Courses"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.PracticalBlock", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("CourseId") - .HasColumnType("integer"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("QuizId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("CourseId"); - - b.HasIndex("QuizId") - .IsUnique(); - - b.ToTable("PracticalBlocks"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Quiz", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.HasKey("Id"); - - b.ToTable("Quizzes"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Tag", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("Tags"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Teacher", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("text"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.ToTable("Teachers"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.TheoryBlock", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("CourseId") - .HasColumnType("integer"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("CourseId"); - - b.ToTable("TheoryBlocks"); - }); - - modelBuilder.Entity("StudySharp.DomainServices.ApplicationUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("AspNetUsers"); - }); - - modelBuilder.Entity("CourseTag", b => - { - b.HasOne("StudySharp.Domain.Models.Course", null) - .WithMany() - .HasForeignKey("CoursesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("StudySharp.Domain.Models.Tag", null) - .WithMany() - .HasForeignKey("TagsId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("StudySharp.DomainServices.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("StudySharp.DomainServices.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("StudySharp.DomainServices.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("StudySharp.DomainServices.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Course", b => - { - b.HasOne("StudySharp.Domain.Models.Teacher", "Teacher") - .WithMany("Courses") - .HasForeignKey("TeacherId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Teacher"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.PracticalBlock", b => - { - b.HasOne("StudySharp.Domain.Models.Course", "Course") - .WithMany("PracticalBlocks") - .HasForeignKey("CourseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("StudySharp.Domain.Models.Quiz", "Quiz") - .WithOne("PracticalBlock") - .HasForeignKey("StudySharp.Domain.Models.PracticalBlock", "QuizId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Course"); - - b.Navigation("Quiz"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.TheoryBlock", b => - { - b.HasOne("StudySharp.Domain.Models.Course", "Course") - .WithMany("TheoryBlocks") - .HasForeignKey("CourseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Course"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Course", b => - { - b.Navigation("PracticalBlocks"); - - b.Navigation("TheoryBlocks"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Quiz", b => - { - b.Navigation("PracticalBlock") - .IsRequired(); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Teacher", b => - { - b.Navigation("Courses"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/server/StudySharp.DomainServices/Migrations/20210925114723_Init.cs b/server/StudySharp.DomainServices/Migrations/20210925114723_Init.cs deleted file mode 100644 index 0607e7a..0000000 --- a/server/StudySharp.DomainServices/Migrations/20210925114723_Init.cs +++ /dev/null @@ -1,402 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -namespace StudySharp.DomainServices.Migrations -{ - public partial class Init : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "AspNetRoles", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - ConcurrencyStamp = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoles", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetUsers", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), - EmailConfirmed = table.Column(type: "boolean", nullable: false), - PasswordHash = table.Column(type: "text", nullable: true), - SecurityStamp = table.Column(type: "text", nullable: true), - ConcurrencyStamp = table.Column(type: "text", nullable: true), - PhoneNumber = table.Column(type: "text", nullable: true), - PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), - TwoFactorEnabled = table.Column(type: "boolean", nullable: false), - LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), - LockoutEnabled = table.Column(type: "boolean", nullable: false), - AccessFailedCount = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUsers", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Quizzes", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) - }, - constraints: table => - { - table.PrimaryKey("PK_Quizzes", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Tags", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Tags", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Teachers", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "integer", nullable: false), - FirstName = table.Column(type: "text", nullable: false), - LastName = table.Column(type: "text", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Teachers", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetRoleClaims", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - RoleId = table.Column(type: "integer", nullable: false), - ClaimType = table.Column(type: "text", nullable: true), - ClaimValue = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", - column: x => x.RoleId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserClaims", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "integer", nullable: false), - ClaimType = table.Column(type: "text", nullable: true), - ClaimValue = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetUserClaims_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserLogins", - columns: table => new - { - LoginProvider = table.Column(type: "text", nullable: false), - ProviderKey = table.Column(type: "text", nullable: false), - ProviderDisplayName = table.Column(type: "text", nullable: true), - UserId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); - table.ForeignKey( - name: "FK_AspNetUserLogins_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserRoles", - columns: table => new - { - UserId = table.Column(type: "integer", nullable: false), - RoleId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetRoles_RoleId", - column: x => x.RoleId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserTokens", - columns: table => new - { - UserId = table.Column(type: "integer", nullable: false), - LoginProvider = table.Column(type: "text", nullable: false), - Name = table.Column(type: "text", nullable: false), - Value = table.Column(type: "text", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); - table.ForeignKey( - name: "FK_AspNetUserTokens_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Courses", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "text", nullable: false), - TeacherId = table.Column(type: "integer", nullable: false), - DateCreated = table.Column(type: "timestamp with time zone", nullable: false), - DateModified = table.Column(type: "timestamp with time zone", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Courses", x => x.Id); - table.ForeignKey( - name: "FK_Courses_Teachers_TeacherId", - column: x => x.TeacherId, - principalTable: "Teachers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "CourseTag", - columns: table => new - { - CoursesId = table.Column(type: "integer", nullable: false), - TagsId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_CourseTag", x => new { x.CoursesId, x.TagsId }); - table.ForeignKey( - name: "FK_CourseTag_Courses_CoursesId", - column: x => x.CoursesId, - principalTable: "Courses", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_CourseTag_Tags_TagsId", - column: x => x.TagsId, - principalTable: "Tags", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "PracticalBlocks", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "text", nullable: false), - Description = table.Column(type: "text", nullable: false), - QuizId = table.Column(type: "integer", nullable: false), - CourseId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_PracticalBlocks", x => x.Id); - table.ForeignKey( - name: "FK_PracticalBlocks_Courses_CourseId", - column: x => x.CourseId, - principalTable: "Courses", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_PracticalBlocks_Quizzes_QuizId", - column: x => x.QuizId, - principalTable: "Quizzes", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "TheoryBlocks", - columns: table => new - { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - Name = table.Column(type: "text", nullable: false), - Description = table.Column(type: "text", nullable: false), - CourseId = table.Column(type: "integer", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_TheoryBlocks", x => x.Id); - table.ForeignKey( - name: "FK_TheoryBlocks_Courses_CourseId", - column: x => x.CourseId, - principalTable: "Courses", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_AspNetRoleClaims_RoleId", - table: "AspNetRoleClaims", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "RoleNameIndex", - table: "AspNetRoles", - column: "NormalizedName", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserClaims_UserId", - table: "AspNetUserClaims", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserLogins_UserId", - table: "AspNetUserLogins", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserRoles_RoleId", - table: "AspNetUserRoles", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "EmailIndex", - table: "AspNetUsers", - column: "NormalizedEmail"); - - migrationBuilder.CreateIndex( - name: "UserNameIndex", - table: "AspNetUsers", - column: "NormalizedUserName", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Courses_TeacherId", - table: "Courses", - column: "TeacherId"); - - migrationBuilder.CreateIndex( - name: "IX_CourseTag_TagsId", - table: "CourseTag", - column: "TagsId"); - - migrationBuilder.CreateIndex( - name: "IX_PracticalBlocks_CourseId", - table: "PracticalBlocks", - column: "CourseId"); - - migrationBuilder.CreateIndex( - name: "IX_PracticalBlocks_QuizId", - table: "PracticalBlocks", - column: "QuizId", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_TheoryBlocks_CourseId", - table: "TheoryBlocks", - column: "CourseId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "AspNetRoleClaims"); - - migrationBuilder.DropTable( - name: "AspNetUserClaims"); - - migrationBuilder.DropTable( - name: "AspNetUserLogins"); - - migrationBuilder.DropTable( - name: "AspNetUserRoles"); - - migrationBuilder.DropTable( - name: "AspNetUserTokens"); - - migrationBuilder.DropTable( - name: "CourseTag"); - - migrationBuilder.DropTable( - name: "PracticalBlocks"); - - migrationBuilder.DropTable( - name: "TheoryBlocks"); - - migrationBuilder.DropTable( - name: "AspNetRoles"); - - migrationBuilder.DropTable( - name: "AspNetUsers"); - - migrationBuilder.DropTable( - name: "Tags"); - - migrationBuilder.DropTable( - name: "Quizzes"); - - migrationBuilder.DropTable( - name: "Courses"); - - migrationBuilder.DropTable( - name: "Teachers"); - } - } -} diff --git a/server/StudySharp.DomainServices/Migrations/StudySharpDbContextModelSnapshot.cs b/server/StudySharp.DomainServices/Migrations/StudySharpDbContextModelSnapshot.cs deleted file mode 100644 index 69beb26..0000000 --- a/server/StudySharp.DomainServices/Migrations/StudySharpDbContextModelSnapshot.cs +++ /dev/null @@ -1,493 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; -using StudySharp.DomainServices; - -namespace StudySharp.DomainServices.Migrations -{ - [DbContext(typeof(StudySharpDbContext))] - partial class StudySharpDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("Relational:MaxIdentifierLength", 63) - .HasAnnotation("ProductVersion", "5.0.10") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - modelBuilder.Entity("CourseTag", b => - { - b.Property("CoursesId") - .HasColumnType("integer"); - - b.Property("TagsId") - .HasColumnType("integer"); - - b.HasKey("CoursesId", "TagsId"); - - b.HasIndex("TagsId"); - - b.ToTable("CourseTag"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("AspNetRoles"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("RoleId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("ClaimType") - .HasColumnType("text"); - - b.Property("ClaimValue") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - b.Property("ProviderDisplayName") - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("integer"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("integer"); - - b.Property("RoleId") - .HasColumnType("integer"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("integer"); - - b.Property("LoginProvider") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - b.Property("Value") - .HasColumnType("text"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Course", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("DateCreated") - .HasColumnType("timestamp with time zone"); - - b.Property("DateModified") - .HasColumnType("timestamp with time zone"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("TeacherId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("TeacherId"); - - b.ToTable("Courses"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.PracticalBlock", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("CourseId") - .HasColumnType("integer"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.Property("QuizId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.HasIndex("CourseId"); - - b.HasIndex("QuizId") - .IsUnique(); - - b.ToTable("PracticalBlocks"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Quiz", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.HasKey("Id"); - - b.ToTable("Quizzes"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Tag", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.ToTable("Tags"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Teacher", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("FirstName") - .IsRequired() - .HasColumnType("text"); - - b.Property("LastName") - .IsRequired() - .HasColumnType("text"); - - b.Property("UserId") - .HasColumnType("integer"); - - b.HasKey("Id"); - - b.ToTable("Teachers"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.TheoryBlock", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("CourseId") - .HasColumnType("integer"); - - b.Property("Description") - .IsRequired() - .HasColumnType("text"); - - b.Property("Name") - .IsRequired() - .HasColumnType("text"); - - b.HasKey("Id"); - - b.HasIndex("CourseId"); - - b.ToTable("TheoryBlocks"); - }); - - modelBuilder.Entity("StudySharp.DomainServices.ApplicationUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("integer") - .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); - - b.Property("AccessFailedCount") - .HasColumnType("integer"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("text"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("boolean"); - - b.Property("LockoutEnabled") - .HasColumnType("boolean"); - - b.Property("LockoutEnd") - .HasColumnType("timestamp with time zone"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.Property("PasswordHash") - .HasColumnType("text"); - - b.Property("PhoneNumber") - .HasColumnType("text"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("boolean"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("character varying(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("AspNetUsers"); - }); - - modelBuilder.Entity("CourseTag", b => - { - b.HasOne("StudySharp.Domain.Models.Course", null) - .WithMany() - .HasForeignKey("CoursesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("StudySharp.Domain.Models.Tag", null) - .WithMany() - .HasForeignKey("TagsId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("StudySharp.DomainServices.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("StudySharp.DomainServices.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("StudySharp.DomainServices.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("StudySharp.DomainServices.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Course", b => - { - b.HasOne("StudySharp.Domain.Models.Teacher", "Teacher") - .WithMany("Courses") - .HasForeignKey("TeacherId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Teacher"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.PracticalBlock", b => - { - b.HasOne("StudySharp.Domain.Models.Course", "Course") - .WithMany("PracticalBlocks") - .HasForeignKey("CourseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("StudySharp.Domain.Models.Quiz", "Quiz") - .WithOne("PracticalBlock") - .HasForeignKey("StudySharp.Domain.Models.PracticalBlock", "QuizId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Course"); - - b.Navigation("Quiz"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.TheoryBlock", b => - { - b.HasOne("StudySharp.Domain.Models.Course", "Course") - .WithMany("TheoryBlocks") - .HasForeignKey("CourseId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Course"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Course", b => - { - b.Navigation("PracticalBlocks"); - - b.Navigation("TheoryBlocks"); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Quiz", b => - { - b.Navigation("PracticalBlock") - .IsRequired(); - }); - - modelBuilder.Entity("StudySharp.Domain.Models.Teacher", b => - { - b.Navigation("Courses"); - }); -#pragma warning restore 612, 618 - } - } -} From 24fbe12b608703211f7757a99f697ff7b938f7cf Mon Sep 17 00:00:00 2001 From: zefirlover Date: Sat, 2 Oct 2021 19:11:09 +0300 Subject: [PATCH 20/30] Add Course validation In AddTheoryBlockCommand, GetTheoryBlockByCourseIdQuery, GetTheoryBlockByIdQuery, RemoveTheoryBlockByIdCommand, UpdateTheoryBlockCommand --- .../Commands/AddTheoryBlockCommand.cs | 9 ++++++--- .../Commands/RemoveTheoryBlockByIdCommand.cs | 5 +++++ .../Commands/UpdateTheoryBlockCommand.cs | 5 +++++ .../Queries/GetTheoryBlockByCourseIdQuery.cs | 6 ++++++ .../Queries/GetTheoryBlockByIdQuery.cs | 5 +++++ 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs index aef2848..febef84 100644 --- a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs @@ -27,9 +27,12 @@ public AddTheoryBlockCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(AddTheoryBlockCommand request, CancellationToken cancellationToken) { - if (await _context.TheoryBlocks.AnyAsync( - _ => _.Name.ToLower().Equals(request.Name.ToLower()) && _.CourseId == request.CourseId, - cancellationToken)) + if (await _context.Courses.AnyAsync(_ => _.Id != request.CourseId, cancellationToken)) + { + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); + } + + if (await _context.TheoryBlocks.AnyAsync(_ => _.Name.ToLower().Equals(request.Name.ToLower()) && _.CourseId == request.CourseId, cancellationToken)) { return OperationResult.Fail(string.Format(ErrorConstants.EntityAlreadyExists, nameof(TheoryBlock), nameof(TheoryBlock.Name), request.Name)); } diff --git a/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs b/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs index 7618408..80749b4 100644 --- a/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs @@ -26,6 +26,11 @@ public RemoveTheoryBlockByIdCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(RemoveTheoryBlockByIdCommand request, CancellationToken cancellationToken) { + if (await _context.Courses.AnyAsync(_ => _.Id != request.CourseId, cancellationToken)) + { + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); + } + var theoryBlock = await _context.TheoryBlocks.FirstOrDefaultAsync(_ => _.Id == request.Id && _.CourseId == request.CourseId); if (theoryBlock == null) diff --git a/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs b/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs index 40af187..e44decc 100644 --- a/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs @@ -28,6 +28,11 @@ public UpdateTheoryBlockCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(UpdateTheoryBlockCommand request, CancellationToken cancellationToken) { + if (await _context.Courses.AnyAsync(_ => _.Id != request.CourseId, cancellationToken)) + { + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); + } + var theoryBlock = await _context.TheoryBlocks.FirstOrDefaultAsync(_ => _.Id == request.Id && _.CourseId == request.CourseId, cancellationToken); if (theoryBlock == null) diff --git a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs index 88a2513..5f64a52 100644 --- a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs +++ b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs @@ -1,6 +1,7 @@ using System.Threading; using System.Threading.Tasks; using MediatR; +using Microsoft.EntityFrameworkCore; using StudySharp.Domain.Constants; using StudySharp.Domain.General; using StudySharp.Domain.Models; @@ -24,6 +25,11 @@ public GetTheoryBlockByCourseIdQueryHandler(StudySharpDbContext studySharpDbCont public async Task> Handle(GetTheoryBlockByCourseIdQuery request, CancellationToken cancellationToken) { + if (await _context.Courses.AnyAsync(_ => _.Id != request.CourseId, cancellationToken)) + { + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); + } + var theoryBlock = await _context.TheoryBlocks.FindAsync(request.CourseId, cancellationToken); if (theoryBlock == null) { diff --git a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs index 7c3469a..f7de375 100644 --- a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs +++ b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs @@ -26,6 +26,11 @@ public GetTheoryBlockByIdQueryHandler(StudySharpDbContext studySharpDbContext) public async Task> Handle(GetTheoryBlockByIdQuery request, CancellationToken cancellationToken) { + if (await _context.Courses.AnyAsync(_ => _.Id != request.CourseId, cancellationToken)) + { + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); + } + var theoryBlock = await _context.TheoryBlocks.FirstOrDefaultAsync(_ => _.Id == request.Id && _.CourseId == request.CourseId, cancellationToken); if (theoryBlock == null) { From ea7fa14f01feb1ed69391153ca2c42d65cc87a9c Mon Sep 17 00:00:00 2001 From: zefirlover Date: Sat, 2 Oct 2021 19:13:42 +0300 Subject: [PATCH 21/30] Remove useless comment --- server/StudySharp.API/Controllers/TheoryBlockController.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index d305f2d..a293c40 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -11,7 +11,7 @@ namespace StudySharp.API.Controllers { - // [Authorize] + [Authorize] [ApiController] [Route("api/courses")] @@ -20,7 +20,6 @@ public class TheoryBlockController : ControllerBase private readonly IMediator _mediator; private readonly IMapper _mapper; - // comment to made commit with dev update public TheoryBlockController(IMediator mediator, IMapper mapper) { _mapper = mapper; From 5888538b4b6c4166e708ae0e54c96d70741333f1 Mon Sep 17 00:00:00 2001 From: zefirlover Date: Sun, 3 Oct 2021 13:06:20 +0300 Subject: [PATCH 22/30] Minor changes Delete GetTheoryBlocksResponse.cs GetTheoryBlockByCourseId => GetTheoryBlocksByCourseId --- .../Controllers/TheoryBlockController.cs | 2 +- .../Responses/TheoryBlocks/GetTheoryBlocksResponse.cs | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlocksResponse.cs diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index a293c40..bca3a82 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -71,7 +71,7 @@ public async Task> Update([FromRoute] } [HttpGet("{courseId:int}/theory-blocks")] - public async Task> GetTheoryBlockByCourseId([FromRoute] GetTheoryBlocksByCourseIdRequest getTheoryBlockByCourseIdRequest) + public async Task> GetTheoryBlocksByCourseId([FromRoute] GetTheoryBlocksByCourseIdRequest getTheoryBlockByCourseIdRequest) { var getTheoryBlockByCourseIdQuery = _mapper.Map(getTheoryBlockByCourseIdRequest); var operationResult = await _mediator.Send(getTheoryBlockByCourseIdQuery); diff --git a/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlocksResponse.cs b/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlocksResponse.cs deleted file mode 100644 index 302b776..0000000 --- a/server/StudySharp.API/Responses/TheoryBlocks/GetTheoryBlocksResponse.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; -using StudySharp.Domain.Models; - -namespace StudySharp.API.Responses.TheoryBlocks -{ - public class GetTheoryBlocksResponse - { - public List TheoryBlocks { get; set; } - } -} \ No newline at end of file From ee51462421f9a11f03baa9bb968d14bc9c566f8c Mon Sep 17 00:00:00 2001 From: zefirlover Date: Sun, 3 Oct 2021 22:24:40 +0300 Subject: [PATCH 23/30] Remove unnecessary Course elements --- .../Controllers/CourseController.cs | 73 ------------------- .../MapperProfiles/CourseProfile.cs | 18 ----- .../Requests/Courses/AddCourseRequest.cs | 8 -- .../Requests/Courses/GetCourseByIdRequest.cs | 7 -- .../Requests/Courses/GetCoursesRequest.cs | 6 -- .../Courses/RemoveCourseByIdRequest.cs | 7 -- .../Responses/Courses/AddCourseResponse.cs | 6 -- .../Courses/GetCourseByIdResponse.cs | 18 ----- .../Responses/Courses/GetCoursesResponse.cs | 10 --- .../Courses/RemoveCourseByIdResponse.cs | 6 -- 10 files changed, 159 deletions(-) delete mode 100644 server/StudySharp.API/Controllers/CourseController.cs delete mode 100644 server/StudySharp.API/MapperProfiles/CourseProfile.cs delete mode 100644 server/StudySharp.API/Requests/Courses/AddCourseRequest.cs delete mode 100644 server/StudySharp.API/Requests/Courses/GetCourseByIdRequest.cs delete mode 100644 server/StudySharp.API/Requests/Courses/GetCoursesRequest.cs delete mode 100644 server/StudySharp.API/Requests/Courses/RemoveCourseByIdRequest.cs delete mode 100644 server/StudySharp.API/Responses/Courses/AddCourseResponse.cs delete mode 100644 server/StudySharp.API/Responses/Courses/GetCourseByIdResponse.cs delete mode 100644 server/StudySharp.API/Responses/Courses/GetCoursesResponse.cs delete mode 100644 server/StudySharp.API/Responses/Courses/RemoveCourseByIdResponse.cs diff --git a/server/StudySharp.API/Controllers/CourseController.cs b/server/StudySharp.API/Controllers/CourseController.cs deleted file mode 100644 index c69cf30..0000000 --- a/server/StudySharp.API/Controllers/CourseController.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System.Threading.Tasks; -using AutoMapper; -using MediatR; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using StudySharp.API.Requests.Courses; -using StudySharp.API.Responses.Courses; -using StudySharp.ApplicationServices.Commands; -using StudySharp.ApplicationServices.Queries; -using StudySharp.Domain.General; - -namespace StudySharp.API.Controllers -{ - [Authorize] - [ApiController] - [Route("api/[controller]")] - - public class CourseController : ControllerBase - { - private readonly IMediator _mediator; - private readonly IMapper _mapper; - - public CourseController(IMediator mediator, IMapper mapper) - { - _mediator = mediator; - _mapper = mapper; - } - - [HttpPost("add")] - public async Task Add([FromBody] AddCourseRequest addCourseRequest) - { - var addCourseCommand = _mapper.Map(addCourseRequest); - return await _mediator.Send(addCourseCommand); - } - - [HttpPost("remove")] - public async Task Remove([FromBody] RemoveCourseByIdRequest removeCourseByIdRequest) - { - var removeCourseByIdCommand = _mapper.Map(removeCourseByIdRequest); - return await _mediator.Send(removeCourseByIdCommand); - } - - [HttpGet] - public async Task GetCourseById([FromBody] GetCourseByIdRequest getCourseByIdRequest) - { - var getCourseByIdQuery = _mapper.Map(getCourseByIdRequest); - var operationResult = await _mediator.Send(getCourseByIdQuery); - - if (!operationResult.IsSucceeded) - { - return OperationResult.Fail(operationResult.Errors); - } - - var response = _mapper.Map(operationResult.Result); - return OperationResult.Ok(response); - } - - [HttpGet] - public async Task GetCourses([FromBody] GetCoursesRequest getCoursesRequest) - { - var getCoursesQuery = _mapper.Map(getCoursesRequest); - var operationResult = await _mediator.Send(getCoursesQuery); - - if (!operationResult.IsSucceeded) - { - return OperationResult.Fail(operationResult.Errors); - } - - var response = _mapper.Map(operationResult.Result); - return OperationResult.Ok(response); - } - } -} diff --git a/server/StudySharp.API/MapperProfiles/CourseProfile.cs b/server/StudySharp.API/MapperProfiles/CourseProfile.cs deleted file mode 100644 index 3606b8b..0000000 --- a/server/StudySharp.API/MapperProfiles/CourseProfile.cs +++ /dev/null @@ -1,18 +0,0 @@ -using AutoMapper; -using StudySharp.API.Requests.Courses; -using StudySharp.ApplicationServices.Commands; -using StudySharp.ApplicationServices.Queries; - -namespace StudySharp.API.MapperProfiles -{ - public class CourseProfile : Profile - { - public CourseProfile() - { - CreateMap(); - CreateMap(); - CreateMap(); - CreateMap(); - } - } -} diff --git a/server/StudySharp.API/Requests/Courses/AddCourseRequest.cs b/server/StudySharp.API/Requests/Courses/AddCourseRequest.cs deleted file mode 100644 index 0e0cd56..0000000 --- a/server/StudySharp.API/Requests/Courses/AddCourseRequest.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace StudySharp.API.Requests.Courses -{ - public class AddCourseRequest - { - public string Name { get; set; } - public int TeacherId { get; set; } - } -} diff --git a/server/StudySharp.API/Requests/Courses/GetCourseByIdRequest.cs b/server/StudySharp.API/Requests/Courses/GetCourseByIdRequest.cs deleted file mode 100644 index 242f8bc..0000000 --- a/server/StudySharp.API/Requests/Courses/GetCourseByIdRequest.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace StudySharp.API.Requests.Courses -{ - public class GetCourseByIdRequest - { - public int Id { get; set; } - } -} diff --git a/server/StudySharp.API/Requests/Courses/GetCoursesRequest.cs b/server/StudySharp.API/Requests/Courses/GetCoursesRequest.cs deleted file mode 100644 index 425394e..0000000 --- a/server/StudySharp.API/Requests/Courses/GetCoursesRequest.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace StudySharp.API.Requests.Courses -{ - public class GetCoursesRequest - { - } -} diff --git a/server/StudySharp.API/Requests/Courses/RemoveCourseByIdRequest.cs b/server/StudySharp.API/Requests/Courses/RemoveCourseByIdRequest.cs deleted file mode 100644 index da11152..0000000 --- a/server/StudySharp.API/Requests/Courses/RemoveCourseByIdRequest.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace StudySharp.API.Requests.Courses -{ - public class RemoveCourseByIdRequest - { - public int Id { get; set; } - } -} diff --git a/server/StudySharp.API/Responses/Courses/AddCourseResponse.cs b/server/StudySharp.API/Responses/Courses/AddCourseResponse.cs deleted file mode 100644 index 0f4e946..0000000 --- a/server/StudySharp.API/Responses/Courses/AddCourseResponse.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace StudySharp.API.Responses.Courses -{ - public class AddCourseResponse - { - } -} diff --git a/server/StudySharp.API/Responses/Courses/GetCourseByIdResponse.cs b/server/StudySharp.API/Responses/Courses/GetCourseByIdResponse.cs deleted file mode 100644 index 523a43d..0000000 --- a/server/StudySharp.API/Responses/Courses/GetCourseByIdResponse.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using StudySharp.Domain.Models; -namespace StudySharp.API.Responses.Courses -{ - public class GetCourseByIdResponse - { - public int Id { get; set; } - public string Name { get; set; } - public List Tags { get; set; } - public int TeacherId { get; set; } - public Teacher Teacher { get; set; } - public List TheoryBlocks { get; set; } - public List PracticalBlocks { get; set; } - public DateTimeOffset DateCreated { get; private set; } - public DateTimeOffset? DateModified { get; private set; } - } -} diff --git a/server/StudySharp.API/Responses/Courses/GetCoursesResponse.cs b/server/StudySharp.API/Responses/Courses/GetCoursesResponse.cs deleted file mode 100644 index adc1998..0000000 --- a/server/StudySharp.API/Responses/Courses/GetCoursesResponse.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Generic; -using StudySharp.Domain.Models; - -namespace StudySharp.API.Responses.Courses -{ - public class GetCoursesResponse - { - public List Courses { get; set; } - } -} diff --git a/server/StudySharp.API/Responses/Courses/RemoveCourseByIdResponse.cs b/server/StudySharp.API/Responses/Courses/RemoveCourseByIdResponse.cs deleted file mode 100644 index 938fe57..0000000 --- a/server/StudySharp.API/Responses/Courses/RemoveCourseByIdResponse.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace StudySharp.API.Responses.Courses -{ - public class RemoveCourseByIdResponse - { - } -} From 2b7c5bfba0f22986aa9abf60bc7489493b53a010 Mon Sep 17 00:00:00 2001 From: zefirlover Date: Sun, 3 Oct 2021 23:48:40 +0300 Subject: [PATCH 24/30] Tests 1/2 Add row in mapper profile Rename and minor changes in GetTheoryBlocksByCourseIdQuery.cs --- .../Controllers/TheoryBlockController.cs | 12 +++++++++--- .../MapperProfiles/TheoryBlockProfile.cs | 1 + ...eIdQuery.cs => GetTheoryBlocksByCourseIdQuery.cs} | 10 +++++----- 3 files changed, 15 insertions(+), 8 deletions(-) rename server/StudySharp.ApplicationServices/Queries/{GetTheoryBlockByCourseIdQuery.cs => GetTheoryBlocksByCourseIdQuery.cs} (76%) diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index bca3a82..9b8eb1e 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -11,7 +11,8 @@ namespace StudySharp.API.Controllers { - [Authorize] + // TODO delete Authorize comment + // [Authorize] [ApiController] [Route("api/courses")] @@ -26,6 +27,7 @@ public TheoryBlockController(IMediator mediator, IMapper mapper) _mediator = mediator; } + // works [HttpPost("{courseId:int}/theory-blocks")] public async Task Add([FromBody] AddTheoryBlockRequest addTheoryBlockRequest) { @@ -33,6 +35,7 @@ public async Task Add([FromBody] AddTheoryBlockRequest addTheor return await _mediator.Send(addTheoryBlockCommand); } + // todo test delete [HttpDelete("{courseId:int}/theory-blocks/{theoryBlockId:int}")] public async Task Remove([FromRoute] RemoveTheoryBlockByIdRequest removeTheoryBlockByIdRequest) { @@ -40,7 +43,8 @@ public async Task Remove([FromRoute] RemoveTheoryBlockByIdReque return await _mediator.Send(removeTheoryBlockByIdCommand); } - [HttpGet("{courseId:int}/theory-blocks/{theoryBlockId:int}")] + // todo test get (id) + [HttpGet("{courseId:int}/theory-blocks/{id:int}")] public async Task> GetTheoryBlockById([FromRoute] GetTheoryBlockByIdRequest getTheoryBlockByIdRequest) { var getTheoryBlockByIdQuery = _mapper.Map(getTheoryBlockByIdRequest); @@ -55,6 +59,7 @@ public async Task> GetTheoryBlockByI return OperationResult.Ok(response); } + // todo test put [HttpPut("{courseId:int}/theory-blocks/{theoryBlockId:int}")] public async Task> Update([FromRoute] UpdateTheoryBlockByIdRequest updateTheoryBlockByIdRequest) { @@ -70,10 +75,11 @@ public async Task> Update([FromRoute] return OperationResult.Ok(response); } + // works [HttpGet("{courseId:int}/theory-blocks")] public async Task> GetTheoryBlocksByCourseId([FromRoute] GetTheoryBlocksByCourseIdRequest getTheoryBlockByCourseIdRequest) { - var getTheoryBlockByCourseIdQuery = _mapper.Map(getTheoryBlockByCourseIdRequest); + var getTheoryBlockByCourseIdQuery = _mapper.Map(getTheoryBlockByCourseIdRequest); var operationResult = await _mediator.Send(getTheoryBlockByCourseIdQuery); if (!operationResult.IsSucceeded) diff --git a/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs b/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs index b4237d5..6f7ee8a 100644 --- a/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs +++ b/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs @@ -13,6 +13,7 @@ public TheoryBlockProfile() CreateMap(); CreateMap(); CreateMap(); + CreateMap(); } } } \ No newline at end of file diff --git a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlocksByCourseIdQuery.cs similarity index 76% rename from server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs rename to server/StudySharp.ApplicationServices/Queries/GetTheoryBlocksByCourseIdQuery.cs index 5f64a52..a00fee1 100644 --- a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByCourseIdQuery.cs +++ b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlocksByCourseIdQuery.cs @@ -9,12 +9,12 @@ namespace StudySharp.ApplicationServices.Queries { - public sealed class GetTheoryBlockByCourseIdQuery : IRequest> + public sealed class GetTheoryBlocksByCourseIdQuery : IRequest> { public int CourseId { get; set; } } - public sealed class GetTheoryBlockByCourseIdQueryHandler : IRequestHandler> + public sealed class GetTheoryBlockByCourseIdQueryHandler : IRequestHandler> { private readonly StudySharpDbContext _context; @@ -23,17 +23,17 @@ public GetTheoryBlockByCourseIdQueryHandler(StudySharpDbContext studySharpDbCont _context = studySharpDbContext; } - public async Task> Handle(GetTheoryBlockByCourseIdQuery request, CancellationToken cancellationToken) + public async Task> Handle(GetTheoryBlocksByCourseIdQuery request, CancellationToken cancellationToken) { if (await _context.Courses.AnyAsync(_ => _.Id != request.CourseId, cancellationToken)) { return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); } - var theoryBlock = await _context.TheoryBlocks.FindAsync(request.CourseId, cancellationToken); + var theoryBlock = await _context.TheoryBlocks.FindAsync(request.CourseId); if (theoryBlock == null) { - return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.TheoryBlocks), request.CourseId)); + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), request.CourseId, nameof(Course.TheoryBlocks))); } return OperationResult.Ok(theoryBlock); From 3998fcda941c8c38839ffa4ea42617e38df120ed Mon Sep 17 00:00:00 2001 From: zefirlover Date: Mon, 4 Oct 2021 14:43:11 +0300 Subject: [PATCH 25/30] Tests 2/2 Some changes in Update and Remove blocks --- .../Controllers/TheoryBlockController.cs | 17 +- .../UpdateTheoryBlockByIdRequest.cs | 2 + .../Commands/RemoveTheoryBlockByIdCommand.cs | 2 +- .../Commands/UpdateTheoryBlockCommand.cs | 6 +- .../20210925114723_Init.Designer.cs | 495 ++++++++++++++++++ .../Migrations/20210925114723_Init.cs | 402 ++++++++++++++ .../StudySharpDbContextModelSnapshot.cs | 493 +++++++++++++++++ 7 files changed, 1405 insertions(+), 12 deletions(-) create mode 100644 server/StudySharp.DomainServices/Migrations/20210925114723_Init.Designer.cs create mode 100644 server/StudySharp.DomainServices/Migrations/20210925114723_Init.cs create mode 100644 server/StudySharp.DomainServices/Migrations/StudySharpDbContextModelSnapshot.cs diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index 9b8eb1e..2cc095d 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -11,8 +11,7 @@ namespace StudySharp.API.Controllers { - // TODO delete Authorize comment - // [Authorize] + [Authorize] [ApiController] [Route("api/courses")] @@ -35,15 +34,15 @@ public async Task Add([FromBody] AddTheoryBlockRequest addTheor return await _mediator.Send(addTheoryBlockCommand); } - // todo test delete - [HttpDelete("{courseId:int}/theory-blocks/{theoryBlockId:int}")] - public async Task Remove([FromRoute] RemoveTheoryBlockByIdRequest removeTheoryBlockByIdRequest) + // FromRoute do not works + [HttpDelete("{courseId:int}/theory-blocks/{id:int}")] + public async Task Remove([FromBody] RemoveTheoryBlockByIdRequest removeTheoryBlockByIdRequest) { var removeTheoryBlockByIdCommand = _mapper.Map(removeTheoryBlockByIdRequest); return await _mediator.Send(removeTheoryBlockByIdCommand); } - // todo test get (id) + // works, fail return partly correct [HttpGet("{courseId:int}/theory-blocks/{id:int}")] public async Task> GetTheoryBlockById([FromRoute] GetTheoryBlockByIdRequest getTheoryBlockByIdRequest) { @@ -59,9 +58,9 @@ public async Task> GetTheoryBlockByI return OperationResult.Ok(response); } - // todo test put - [HttpPut("{courseId:int}/theory-blocks/{theoryBlockId:int}")] - public async Task> Update([FromRoute] UpdateTheoryBlockByIdRequest updateTheoryBlockByIdRequest) + // works, but without CourseId exception + [HttpPut("{courseId:int}/theory-blocks/{id:int}")] + public async Task> Update([FromBody] UpdateTheoryBlockByIdRequest updateTheoryBlockByIdRequest) { var updateTheoryBlockCommand = _mapper.Map(updateTheoryBlockByIdRequest); var operationResult = await _mediator.Send(updateTheoryBlockCommand); diff --git a/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs index d5a092e..3122458 100644 --- a/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs +++ b/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs @@ -7,5 +7,7 @@ public class UpdateTheoryBlockByIdRequest [BindProperty(Name = "id", SupportsGet = true)] public int Id { get; set; } public int CourseId { get; set; } + public string Name { get; set; } + public string Description { get; set; } } } \ No newline at end of file diff --git a/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs b/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs index 80749b4..9fba7f7 100644 --- a/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs @@ -35,7 +35,7 @@ public async Task Handle(RemoveTheoryBlockByIdCommand request, if (theoryBlock == null) { - return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Id), nameof(TheoryBlock.CourseId), request.Id, request.CourseId)); + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Id), request.Id)); } _context.TheoryBlocks.Remove(theoryBlock); diff --git a/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs b/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs index e44decc..c2774ed 100644 --- a/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs @@ -28,16 +28,18 @@ public UpdateTheoryBlockCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(UpdateTheoryBlockCommand request, CancellationToken cancellationToken) { + // do not work if (await _context.Courses.AnyAsync(_ => _.Id != request.CourseId, cancellationToken)) { return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); } - var theoryBlock = await _context.TheoryBlocks.FirstOrDefaultAsync(_ => _.Id == request.Id && _.CourseId == request.CourseId, cancellationToken); + // && _.CourseId == request.CourseId + var theoryBlock = await _context.TheoryBlocks.FirstOrDefaultAsync(_ => _.Id == request.Id, cancellationToken); if (theoryBlock == null) { - return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Name), nameof(TheoryBlock.CourseId), request.Id, request.CourseId)); + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Id), request.Id)); } theoryBlock.Name = request.Name; diff --git a/server/StudySharp.DomainServices/Migrations/20210925114723_Init.Designer.cs b/server/StudySharp.DomainServices/Migrations/20210925114723_Init.Designer.cs new file mode 100644 index 0000000..e0fe55d --- /dev/null +++ b/server/StudySharp.DomainServices/Migrations/20210925114723_Init.Designer.cs @@ -0,0 +1,495 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using StudySharp.DomainServices; + +namespace StudySharp.DomainServices.Migrations +{ + [DbContext(typeof(StudySharpDbContext))] + [Migration("20210925114723_Init")] + partial class Init + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.10") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + modelBuilder.Entity("CourseTag", b => + { + b.Property("CoursesId") + .HasColumnType("integer"); + + b.Property("TagsId") + .HasColumnType("integer"); + + b.HasKey("CoursesId", "TagsId"); + + b.HasIndex("TagsId"); + + b.ToTable("CourseTag"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("integer"); + + b.Property("RoleId") + .HasColumnType("integer"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("integer"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Course", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("DateCreated") + .HasColumnType("timestamp with time zone"); + + b.Property("DateModified") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("TeacherId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("TeacherId"); + + b.ToTable("Courses"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.PracticalBlock", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("CourseId") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("QuizId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CourseId"); + + b.HasIndex("QuizId") + .IsUnique(); + + b.ToTable("PracticalBlocks"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.HasKey("Id"); + + b.ToTable("Quizzes"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Tag", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Tags"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Teacher", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Teachers"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.TheoryBlock", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("CourseId") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("CourseId"); + + b.ToTable("TheoryBlocks"); + }); + + modelBuilder.Entity("StudySharp.DomainServices.ApplicationUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("CourseTag", b => + { + b.HasOne("StudySharp.Domain.Models.Course", null) + .WithMany() + .HasForeignKey("CoursesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("StudySharp.Domain.Models.Tag", null) + .WithMany() + .HasForeignKey("TagsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("StudySharp.DomainServices.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("StudySharp.DomainServices.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("StudySharp.DomainServices.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("StudySharp.DomainServices.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Course", b => + { + b.HasOne("StudySharp.Domain.Models.Teacher", "Teacher") + .WithMany("Courses") + .HasForeignKey("TeacherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Teacher"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.PracticalBlock", b => + { + b.HasOne("StudySharp.Domain.Models.Course", "Course") + .WithMany("PracticalBlocks") + .HasForeignKey("CourseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("StudySharp.Domain.Models.Quiz", "Quiz") + .WithOne("PracticalBlock") + .HasForeignKey("StudySharp.Domain.Models.PracticalBlock", "QuizId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Course"); + + b.Navigation("Quiz"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.TheoryBlock", b => + { + b.HasOne("StudySharp.Domain.Models.Course", "Course") + .WithMany("TheoryBlocks") + .HasForeignKey("CourseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Course"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Course", b => + { + b.Navigation("PracticalBlocks"); + + b.Navigation("TheoryBlocks"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Quiz", b => + { + b.Navigation("PracticalBlock") + .IsRequired(); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Teacher", b => + { + b.Navigation("Courses"); + }); +#pragma warning restore 612, 618 + } + } +} \ No newline at end of file diff --git a/server/StudySharp.DomainServices/Migrations/20210925114723_Init.cs b/server/StudySharp.DomainServices/Migrations/20210925114723_Init.cs new file mode 100644 index 0000000..73a2696 --- /dev/null +++ b/server/StudySharp.DomainServices/Migrations/20210925114723_Init.cs @@ -0,0 +1,402 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace StudySharp.DomainServices.Migrations +{ + public partial class Init : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + EmailConfirmed = table.Column(type: "boolean", nullable: false), + PasswordHash = table.Column(type: "text", nullable: true), + SecurityStamp = table.Column(type: "text", nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true), + PhoneNumber = table.Column(type: "text", nullable: true), + PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), + TwoFactorEnabled = table.Column(type: "boolean", nullable: false), + LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), + LockoutEnabled = table.Column(type: "boolean", nullable: false), + AccessFailedCount = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Quizzes", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn) + }, + constraints: table => + { + table.PrimaryKey("PK_Quizzes", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Tags", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Tags", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Teachers", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "integer", nullable: false), + FirstName = table.Column(type: "text", nullable: false), + LastName = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Teachers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + RoleId = table.Column(type: "integer", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserClaims", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "integer", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetUserClaims_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserLogins", + columns: table => new + { + LoginProvider = table.Column(type: "text", nullable: false), + ProviderKey = table.Column(type: "text", nullable: false), + ProviderDisplayName = table.Column(type: "text", nullable: true), + UserId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_AspNetUserLogins_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserRoles", + columns: table => new + { + UserId = table.Column(type: "integer", nullable: false), + RoleId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserTokens", + columns: table => new + { + UserId = table.Column(type: "integer", nullable: false), + LoginProvider = table.Column(type: "text", nullable: false), + Name = table.Column(type: "text", nullable: false), + Value = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + table.ForeignKey( + name: "FK_AspNetUserTokens_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Courses", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + TeacherId = table.Column(type: "integer", nullable: false), + DateCreated = table.Column(type: "timestamp with time zone", nullable: false), + DateModified = table.Column(type: "timestamp with time zone", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Courses", x => x.Id); + table.ForeignKey( + name: "FK_Courses_Teachers_TeacherId", + column: x => x.TeacherId, + principalTable: "Teachers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "CourseTag", + columns: table => new + { + CoursesId = table.Column(type: "integer", nullable: false), + TagsId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CourseTag", x => new { x.CoursesId, x.TagsId }); + table.ForeignKey( + name: "FK_CourseTag_Courses_CoursesId", + column: x => x.CoursesId, + principalTable: "Courses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_CourseTag_Tags_TagsId", + column: x => x.TagsId, + principalTable: "Tags", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "PracticalBlocks", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Description = table.Column(type: "text", nullable: false), + QuizId = table.Column(type: "integer", nullable: false), + CourseId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PracticalBlocks", x => x.Id); + table.ForeignKey( + name: "FK_PracticalBlocks_Courses_CourseId", + column: x => x.CourseId, + principalTable: "Courses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_PracticalBlocks_Quizzes_QuizId", + column: x => x.QuizId, + principalTable: "Quizzes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "TheoryBlocks", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: false), + Description = table.Column(type: "text", nullable: false), + CourseId = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_TheoryBlocks", x => x.Id); + table.ForeignKey( + name: "FK_TheoryBlocks_Courses_CourseId", + column: x => x.CourseId, + principalTable: "Courses", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + table: "AspNetUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Courses_TeacherId", + table: "Courses", + column: "TeacherId"); + + migrationBuilder.CreateIndex( + name: "IX_CourseTag_TagsId", + table: "CourseTag", + column: "TagsId"); + + migrationBuilder.CreateIndex( + name: "IX_PracticalBlocks_CourseId", + table: "PracticalBlocks", + column: "CourseId"); + + migrationBuilder.CreateIndex( + name: "IX_PracticalBlocks_QuizId", + table: "PracticalBlocks", + column: "QuizId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_TheoryBlocks_CourseId", + table: "TheoryBlocks", + column: "CourseId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AspNetRoleClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserLogins"); + + migrationBuilder.DropTable( + name: "AspNetUserRoles"); + + migrationBuilder.DropTable( + name: "AspNetUserTokens"); + + migrationBuilder.DropTable( + name: "CourseTag"); + + migrationBuilder.DropTable( + name: "PracticalBlocks"); + + migrationBuilder.DropTable( + name: "TheoryBlocks"); + + migrationBuilder.DropTable( + name: "AspNetRoles"); + + migrationBuilder.DropTable( + name: "AspNetUsers"); + + migrationBuilder.DropTable( + name: "Tags"); + + migrationBuilder.DropTable( + name: "Quizzes"); + + migrationBuilder.DropTable( + name: "Courses"); + + migrationBuilder.DropTable( + name: "Teachers"); + } + } +} \ No newline at end of file diff --git a/server/StudySharp.DomainServices/Migrations/StudySharpDbContextModelSnapshot.cs b/server/StudySharp.DomainServices/Migrations/StudySharpDbContextModelSnapshot.cs new file mode 100644 index 0000000..1ac72d6 --- /dev/null +++ b/server/StudySharp.DomainServices/Migrations/StudySharpDbContextModelSnapshot.cs @@ -0,0 +1,493 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using StudySharp.DomainServices; + +namespace StudySharp.DomainServices.Migrations +{ + [DbContext(typeof(StudySharpDbContext))] + partial class StudySharpDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.10") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + modelBuilder.Entity("CourseTag", b => + { + b.Property("CoursesId") + .HasColumnType("integer"); + + b.Property("TagsId") + .HasColumnType("integer"); + + b.HasKey("CoursesId", "TagsId"); + + b.HasIndex("TagsId"); + + b.ToTable("CourseTag"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("integer"); + + b.Property("RoleId") + .HasColumnType("integer"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("integer"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Course", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("DateCreated") + .HasColumnType("timestamp with time zone"); + + b.Property("DateModified") + .HasColumnType("timestamp with time zone"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("TeacherId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("TeacherId"); + + b.ToTable("Courses"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.PracticalBlock", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("CourseId") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("QuizId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("CourseId"); + + b.HasIndex("QuizId") + .IsUnique(); + + b.ToTable("PracticalBlocks"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Quiz", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.HasKey("Id"); + + b.ToTable("Quizzes"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Tag", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Tags"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Teacher", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Teachers"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.TheoryBlock", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("CourseId") + .HasColumnType("integer"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("CourseId"); + + b.ToTable("TheoryBlocks"); + }); + + modelBuilder.Entity("StudySharp.DomainServices.ApplicationUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("CourseTag", b => + { + b.HasOne("StudySharp.Domain.Models.Course", null) + .WithMany() + .HasForeignKey("CoursesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("StudySharp.Domain.Models.Tag", null) + .WithMany() + .HasForeignKey("TagsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("StudySharp.DomainServices.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("StudySharp.DomainServices.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("StudySharp.DomainServices.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("StudySharp.DomainServices.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Course", b => + { + b.HasOne("StudySharp.Domain.Models.Teacher", "Teacher") + .WithMany("Courses") + .HasForeignKey("TeacherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Teacher"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.PracticalBlock", b => + { + b.HasOne("StudySharp.Domain.Models.Course", "Course") + .WithMany("PracticalBlocks") + .HasForeignKey("CourseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("StudySharp.Domain.Models.Quiz", "Quiz") + .WithOne("PracticalBlock") + .HasForeignKey("StudySharp.Domain.Models.PracticalBlock", "QuizId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Course"); + + b.Navigation("Quiz"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.TheoryBlock", b => + { + b.HasOne("StudySharp.Domain.Models.Course", "Course") + .WithMany("TheoryBlocks") + .HasForeignKey("CourseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Course"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Course", b => + { + b.Navigation("PracticalBlocks"); + + b.Navigation("TheoryBlocks"); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Quiz", b => + { + b.Navigation("PracticalBlock") + .IsRequired(); + }); + + modelBuilder.Entity("StudySharp.Domain.Models.Teacher", b => + { + b.Navigation("Courses"); + }); +#pragma warning restore 612, 618 + } + } +} \ No newline at end of file From 440fa696466b0eea40b2d0f5695083b7fcb1aeba Mon Sep 17 00:00:00 2001 From: zefirlover Date: Mon, 4 Oct 2021 21:32:32 +0300 Subject: [PATCH 26/30] Tests 3/2 Fixed CourseId validation in UpdateTheoryBlockCommand.cs Update now works correctly Other minor changes --- .../Controllers/TheoryBlockController.cs | 16 +++++++++------- .../MapperProfiles/TheoryBlockProfile.cs | 1 + .../TheoryBlocks/AddTheoryBlockRequest.cs | 3 +++ .../TheoryBlocks/GetTheoryBlockByIdRequest.cs | 1 + .../TheoryBlocks/RemoveTheoryBlockByIdRequest.cs | 1 + .../TheoryBlocks/UpdateTheoryBlockByIdRequest.cs | 3 --- .../Commands/AddTheoryBlockCommand.cs | 4 ++-- .../Commands/UpdateTheoryBlockCommand.cs | 6 ++---- 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index 2cc095d..5a0cff1 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -11,7 +11,7 @@ namespace StudySharp.API.Controllers { - [Authorize] + // [Authorize] [ApiController] [Route("api/courses")] @@ -34,15 +34,15 @@ public async Task Add([FromBody] AddTheoryBlockRequest addTheor return await _mediator.Send(addTheoryBlockCommand); } - // FromRoute do not works + // +2 works [HttpDelete("{courseId:int}/theory-blocks/{id:int}")] - public async Task Remove([FromBody] RemoveTheoryBlockByIdRequest removeTheoryBlockByIdRequest) + public async Task Remove([FromRoute] RemoveTheoryBlockByIdRequest removeTheoryBlockByIdRequest) { var removeTheoryBlockByIdCommand = _mapper.Map(removeTheoryBlockByIdRequest); return await _mediator.Send(removeTheoryBlockByIdCommand); } - // works, fail return partly correct + // +2 works, operation result fail needs to be reworked [HttpGet("{courseId:int}/theory-blocks/{id:int}")] public async Task> GetTheoryBlockById([FromRoute] GetTheoryBlockByIdRequest getTheoryBlockByIdRequest) { @@ -58,11 +58,13 @@ public async Task> GetTheoryBlockByI return OperationResult.Ok(response); } - // works, but without CourseId exception + // +2 works [HttpPut("{courseId:int}/theory-blocks/{id:int}")] - public async Task> Update([FromBody] UpdateTheoryBlockByIdRequest updateTheoryBlockByIdRequest) + public async Task> Update([FromRoute] int id, [FromRoute] int courseId, [FromBody] UpdateTheoryBlockByIdRequest updateTheoryBlockByIdRequest) { var updateTheoryBlockCommand = _mapper.Map(updateTheoryBlockByIdRequest); + updateTheoryBlockCommand.Id = id; + updateTheoryBlockCommand.CourseId = courseId; var operationResult = await _mediator.Send(updateTheoryBlockCommand); if (!operationResult.IsSucceeded) @@ -74,7 +76,7 @@ public async Task> Update([FromBody] return OperationResult.Ok(response); } - // works + // +2 works [HttpGet("{courseId:int}/theory-blocks")] public async Task> GetTheoryBlocksByCourseId([FromRoute] GetTheoryBlocksByCourseIdRequest getTheoryBlockByCourseIdRequest) { diff --git a/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs b/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs index 6f7ee8a..e37f904 100644 --- a/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs +++ b/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs @@ -1,3 +1,4 @@ +using System; using AutoMapper; using StudySharp.API.Requests.TheoryBlocks; using StudySharp.ApplicationServices.Commands; diff --git a/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs index 7c6b08c..b6abb27 100644 --- a/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs +++ b/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs @@ -1,9 +1,12 @@ +using Microsoft.AspNetCore.Mvc; + namespace StudySharp.API.Requests.TheoryBlocks { public class AddTheoryBlockRequest { public string Name { get; set; } public string Description { get; set; } + [BindProperty(Name = "courseId", SupportsGet = true)] public int CourseId { get; set; } } } \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs index e79eacc..fdc8e3f 100644 --- a/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs +++ b/server/StudySharp.API/Requests/TheoryBlocks/GetTheoryBlockByIdRequest.cs @@ -6,6 +6,7 @@ public class GetTheoryBlockByIdRequest { [BindProperty(Name = "id", SupportsGet = true)] public int Id { get; set; } + [BindProperty(Name = "courseId", SupportsGet = true)] public int CourseId { get; set; } } } \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs index 8943371..c7df964 100644 --- a/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs +++ b/server/StudySharp.API/Requests/TheoryBlocks/RemoveTheoryBlockByIdRequest.cs @@ -6,6 +6,7 @@ public class RemoveTheoryBlockByIdRequest { [BindProperty(Name = "id", SupportsGet = true)] public int Id { get; set; } + [BindProperty(Name = "courseId", SupportsGet = true)] public int CourseId { get; set; } } } \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs index 3122458..0ebe450 100644 --- a/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs +++ b/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs @@ -4,9 +4,6 @@ namespace StudySharp.API.Requests.TheoryBlocks { public class UpdateTheoryBlockByIdRequest { - [BindProperty(Name = "id", SupportsGet = true)] - public int Id { get; set; } - public int CourseId { get; set; } public string Name { get; set; } public string Description { get; set; } } diff --git a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs index febef84..e974ced 100644 --- a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs @@ -27,12 +27,12 @@ public AddTheoryBlockCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(AddTheoryBlockCommand request, CancellationToken cancellationToken) { - if (await _context.Courses.AnyAsync(_ => _.Id != request.CourseId, cancellationToken)) + if (await _context.Courses.AnyAsync(_ => _.Id != request.CourseId)) { return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); } - if (await _context.TheoryBlocks.AnyAsync(_ => _.Name.ToLower().Equals(request.Name.ToLower()) && _.CourseId == request.CourseId, cancellationToken)) + if (await _context.TheoryBlocks.AnyAsync(_ => _.Name.ToLower().Equals(request.Name.ToLower()), cancellationToken)) { return OperationResult.Fail(string.Format(ErrorConstants.EntityAlreadyExists, nameof(TheoryBlock), nameof(TheoryBlock.Name), request.Name)); } diff --git a/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs b/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs index c2774ed..d791782 100644 --- a/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs @@ -28,15 +28,13 @@ public UpdateTheoryBlockCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(UpdateTheoryBlockCommand request, CancellationToken cancellationToken) { - // do not work - if (await _context.Courses.AnyAsync(_ => _.Id != request.CourseId, cancellationToken)) + var course = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); + if (!course) { return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); } - // && _.CourseId == request.CourseId var theoryBlock = await _context.TheoryBlocks.FirstOrDefaultAsync(_ => _.Id == request.Id, cancellationToken); - if (theoryBlock == null) { return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Id), request.Id)); From 74fcf1796ddcc05d4185c002c7cc6d9c1df4cfb1 Mon Sep 17 00:00:00 2001 From: zefirlover Date: Mon, 4 Oct 2021 21:52:16 +0300 Subject: [PATCH 27/30] Add now works, rewrite operation result text in GetTheoryBlockByIdQuery Other minor changes --- .../StudySharp.API/Controllers/TheoryBlockController.cs | 8 ++++---- .../StudySharp.API/MapperProfiles/TheoryBlockProfile.cs | 1 - .../Requests/TheoryBlocks/AddTheoryBlockRequest.cs | 2 -- .../Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs | 2 -- .../Commands/AddTheoryBlockCommand.cs | 3 ++- .../Queries/GetTheoryBlockByIdQuery.cs | 2 +- 6 files changed, 7 insertions(+), 11 deletions(-) diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index 5a0cff1..e928136 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -1,7 +1,6 @@ using System.Threading.Tasks; using AutoMapper; using MediatR; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using StudySharp.API.Requests.TheoryBlocks; using StudySharp.API.Responses.TheoryBlocks; @@ -26,11 +25,12 @@ public TheoryBlockController(IMediator mediator, IMapper mapper) _mediator = mediator; } - // works + // +2 works [HttpPost("{courseId:int}/theory-blocks")] - public async Task Add([FromBody] AddTheoryBlockRequest addTheoryBlockRequest) + public async Task Add([FromRoute] int courseId, [FromBody] AddTheoryBlockRequest addTheoryBlockRequest) { var addTheoryBlockCommand = _mapper.Map(addTheoryBlockRequest); + addTheoryBlockCommand.CourseId = courseId; return await _mediator.Send(addTheoryBlockCommand); } @@ -42,7 +42,7 @@ public async Task Remove([FromRoute] RemoveTheoryBlockByIdReque return await _mediator.Send(removeTheoryBlockByIdCommand); } - // +2 works, operation result fail needs to be reworked + // +2 works [HttpGet("{courseId:int}/theory-blocks/{id:int}")] public async Task> GetTheoryBlockById([FromRoute] GetTheoryBlockByIdRequest getTheoryBlockByIdRequest) { diff --git a/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs b/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs index e37f904..6f7ee8a 100644 --- a/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs +++ b/server/StudySharp.API/MapperProfiles/TheoryBlockProfile.cs @@ -1,4 +1,3 @@ -using System; using AutoMapper; using StudySharp.API.Requests.TheoryBlocks; using StudySharp.ApplicationServices.Commands; diff --git a/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs index b6abb27..30922d6 100644 --- a/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs +++ b/server/StudySharp.API/Requests/TheoryBlocks/AddTheoryBlockRequest.cs @@ -6,7 +6,5 @@ public class AddTheoryBlockRequest { public string Name { get; set; } public string Description { get; set; } - [BindProperty(Name = "courseId", SupportsGet = true)] - public int CourseId { get; set; } } } \ No newline at end of file diff --git a/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs b/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs index 0ebe450..ce5f30a 100644 --- a/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs +++ b/server/StudySharp.API/Requests/TheoryBlocks/UpdateTheoryBlockByIdRequest.cs @@ -1,5 +1,3 @@ -using Microsoft.AspNetCore.Mvc; - namespace StudySharp.API.Requests.TheoryBlocks { public class UpdateTheoryBlockByIdRequest diff --git a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs index e974ced..315b960 100644 --- a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs @@ -27,7 +27,8 @@ public AddTheoryBlockCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(AddTheoryBlockCommand request, CancellationToken cancellationToken) { - if (await _context.Courses.AnyAsync(_ => _.Id != request.CourseId)) + var course = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); + if (!course) { return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); } diff --git a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs index f7de375..20358df 100644 --- a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs +++ b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs @@ -34,7 +34,7 @@ public async Task> Handle(GetTheoryBlockByIdQuery r var theoryBlock = await _context.TheoryBlocks.FirstOrDefaultAsync(_ => _.Id == request.Id && _.CourseId == request.CourseId, cancellationToken); if (theoryBlock == null) { - return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Id), nameof(TheoryBlock.CourseId), request.Id, request.CourseId)); + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(TheoryBlock), nameof(TheoryBlock.Id), request.Id)); } return OperationResult.Ok(theoryBlock); From 7ac7cfd0195a1c8f900f7e37ec6e76e0150d1356 Mon Sep 17 00:00:00 2001 From: zefirlover Date: Mon, 4 Oct 2021 22:12:19 +0300 Subject: [PATCH 28/30] Rework courseId exception in Remove, GetById, GetByCourseId, rework exception texts in GetByCourseId --- .../Controllers/TheoryBlockController.cs | 10 +++++----- .../Commands/RemoveTheoryBlockByIdCommand.cs | 5 +++-- .../Queries/GetTheoryBlockByIdQuery.cs | 3 ++- .../Queries/GetTheoryBlocksByCourseIdQuery.cs | 5 +++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index e928136..2874142 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -25,7 +25,7 @@ public TheoryBlockController(IMediator mediator, IMapper mapper) _mediator = mediator; } - // +2 works + // +3 works [HttpPost("{courseId:int}/theory-blocks")] public async Task Add([FromRoute] int courseId, [FromBody] AddTheoryBlockRequest addTheoryBlockRequest) { @@ -34,7 +34,7 @@ public async Task Add([FromRoute] int courseId, [FromBody] AddT return await _mediator.Send(addTheoryBlockCommand); } - // +2 works + // +2 works, courseId exception doesnt work (to test)(works) [HttpDelete("{courseId:int}/theory-blocks/{id:int}")] public async Task Remove([FromRoute] RemoveTheoryBlockByIdRequest removeTheoryBlockByIdRequest) { @@ -42,7 +42,7 @@ public async Task Remove([FromRoute] RemoveTheoryBlockByIdReque return await _mediator.Send(removeTheoryBlockByIdCommand); } - // +2 works + // +2 works, courseId exception doesnt work (to test)(works) [HttpGet("{courseId:int}/theory-blocks/{id:int}")] public async Task> GetTheoryBlockById([FromRoute] GetTheoryBlockByIdRequest getTheoryBlockByIdRequest) { @@ -58,7 +58,7 @@ public async Task> GetTheoryBlockByI return OperationResult.Ok(response); } - // +2 works + // +3 works [HttpPut("{courseId:int}/theory-blocks/{id:int}")] public async Task> Update([FromRoute] int id, [FromRoute] int courseId, [FromBody] UpdateTheoryBlockByIdRequest updateTheoryBlockByIdRequest) { @@ -76,7 +76,7 @@ public async Task> Update([FromRoute] return OperationResult.Ok(response); } - // +2 works + // +2 works, check exceptions (to test)(works), check courseId exception (works) [HttpGet("{courseId:int}/theory-blocks")] public async Task> GetTheoryBlocksByCourseId([FromRoute] GetTheoryBlocksByCourseIdRequest getTheoryBlockByCourseIdRequest) { diff --git a/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs b/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs index 9fba7f7..1cf5df5 100644 --- a/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs @@ -26,12 +26,13 @@ public RemoveTheoryBlockByIdCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(RemoveTheoryBlockByIdCommand request, CancellationToken cancellationToken) { - if (await _context.Courses.AnyAsync(_ => _.Id != request.CourseId, cancellationToken)) + var course = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); + if (!course) { return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); } - var theoryBlock = await _context.TheoryBlocks.FirstOrDefaultAsync(_ => _.Id == request.Id && _.CourseId == request.CourseId); + var theoryBlock = await _context.TheoryBlocks.FirstOrDefaultAsync(_ => _.Id == request.Id, cancellationToken); if (theoryBlock == null) { diff --git a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs index 20358df..074df83 100644 --- a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs +++ b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs @@ -26,7 +26,8 @@ public GetTheoryBlockByIdQueryHandler(StudySharpDbContext studySharpDbContext) public async Task> Handle(GetTheoryBlockByIdQuery request, CancellationToken cancellationToken) { - if (await _context.Courses.AnyAsync(_ => _.Id != request.CourseId, cancellationToken)) + var course = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); + if (!course) { return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); } diff --git a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlocksByCourseIdQuery.cs b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlocksByCourseIdQuery.cs index a00fee1..90d6573 100644 --- a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlocksByCourseIdQuery.cs +++ b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlocksByCourseIdQuery.cs @@ -25,7 +25,8 @@ public GetTheoryBlockByCourseIdQueryHandler(StudySharpDbContext studySharpDbCont public async Task> Handle(GetTheoryBlocksByCourseIdQuery request, CancellationToken cancellationToken) { - if (await _context.Courses.AnyAsync(_ => _.Id != request.CourseId, cancellationToken)) + var course = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); + if (!course) { return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); } @@ -33,7 +34,7 @@ public async Task> Handle(GetTheoryBlocksByCourseId var theoryBlock = await _context.TheoryBlocks.FindAsync(request.CourseId); if (theoryBlock == null) { - return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), request.CourseId, nameof(Course.TheoryBlocks))); + return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course.TheoryBlocks), nameof(TheoryBlock.CourseId), request.CourseId)); } return OperationResult.Ok(theoryBlock); From dce2fb485ae42839d27ecbaa2e968ae975447886 Mon Sep 17 00:00:00 2001 From: zefirlover Date: Mon, 4 Oct 2021 22:27:46 +0300 Subject: [PATCH 29/30] Unnecessary comments was removed --- .../StudySharp.API/Controllers/TheoryBlockController.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/server/StudySharp.API/Controllers/TheoryBlockController.cs b/server/StudySharp.API/Controllers/TheoryBlockController.cs index 2874142..8b84815 100644 --- a/server/StudySharp.API/Controllers/TheoryBlockController.cs +++ b/server/StudySharp.API/Controllers/TheoryBlockController.cs @@ -1,6 +1,7 @@ using System.Threading.Tasks; using AutoMapper; using MediatR; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using StudySharp.API.Requests.TheoryBlocks; using StudySharp.API.Responses.TheoryBlocks; @@ -10,7 +11,7 @@ namespace StudySharp.API.Controllers { - // [Authorize] + [Authorize] [ApiController] [Route("api/courses")] @@ -25,7 +26,6 @@ public TheoryBlockController(IMediator mediator, IMapper mapper) _mediator = mediator; } - // +3 works [HttpPost("{courseId:int}/theory-blocks")] public async Task Add([FromRoute] int courseId, [FromBody] AddTheoryBlockRequest addTheoryBlockRequest) { @@ -34,7 +34,6 @@ public async Task Add([FromRoute] int courseId, [FromBody] AddT return await _mediator.Send(addTheoryBlockCommand); } - // +2 works, courseId exception doesnt work (to test)(works) [HttpDelete("{courseId:int}/theory-blocks/{id:int}")] public async Task Remove([FromRoute] RemoveTheoryBlockByIdRequest removeTheoryBlockByIdRequest) { @@ -42,7 +41,6 @@ public async Task Remove([FromRoute] RemoveTheoryBlockByIdReque return await _mediator.Send(removeTheoryBlockByIdCommand); } - // +2 works, courseId exception doesnt work (to test)(works) [HttpGet("{courseId:int}/theory-blocks/{id:int}")] public async Task> GetTheoryBlockById([FromRoute] GetTheoryBlockByIdRequest getTheoryBlockByIdRequest) { @@ -58,7 +56,6 @@ public async Task> GetTheoryBlockByI return OperationResult.Ok(response); } - // +3 works [HttpPut("{courseId:int}/theory-blocks/{id:int}")] public async Task> Update([FromRoute] int id, [FromRoute] int courseId, [FromBody] UpdateTheoryBlockByIdRequest updateTheoryBlockByIdRequest) { @@ -76,7 +73,6 @@ public async Task> Update([FromRoute] return OperationResult.Ok(response); } - // +2 works, check exceptions (to test)(works), check courseId exception (works) [HttpGet("{courseId:int}/theory-blocks")] public async Task> GetTheoryBlocksByCourseId([FromRoute] GetTheoryBlocksByCourseIdRequest getTheoryBlockByCourseIdRequest) { From da94b00dd9846c84474c44b2806472577f275545 Mon Sep 17 00:00:00 2001 From: zefirlover Date: Mon, 4 Oct 2021 22:58:46 +0300 Subject: [PATCH 30/30] Change course to courseExistent --- .../Commands/AddTheoryBlockCommand.cs | 4 ++-- .../Commands/RemoveTheoryBlockByIdCommand.cs | 4 ++-- .../Commands/UpdateTheoryBlockCommand.cs | 4 ++-- .../Queries/GetTheoryBlockByIdQuery.cs | 4 ++-- .../Queries/GetTheoryBlocksByCourseIdQuery.cs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs index 315b960..566ef79 100644 --- a/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/AddTheoryBlockCommand.cs @@ -27,8 +27,8 @@ public AddTheoryBlockCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(AddTheoryBlockCommand request, CancellationToken cancellationToken) { - var course = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); - if (!course) + var courseExistent = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); + if (!courseExistent) { return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); } diff --git a/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs b/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs index 1cf5df5..b7dd2b8 100644 --- a/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/RemoveTheoryBlockByIdCommand.cs @@ -26,8 +26,8 @@ public RemoveTheoryBlockByIdCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(RemoveTheoryBlockByIdCommand request, CancellationToken cancellationToken) { - var course = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); - if (!course) + var courseExistent = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); + if (!courseExistent) { return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); } diff --git a/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs b/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs index d791782..4fe1a7e 100644 --- a/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs +++ b/server/StudySharp.ApplicationServices/Commands/UpdateTheoryBlockCommand.cs @@ -28,8 +28,8 @@ public UpdateTheoryBlockCommandHandler(StudySharpDbContext sharpDbContext) public async Task Handle(UpdateTheoryBlockCommand request, CancellationToken cancellationToken) { - var course = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); - if (!course) + var courseExistent = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); + if (!courseExistent) { return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); } diff --git a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs index 074df83..d0232bf 100644 --- a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs +++ b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlockByIdQuery.cs @@ -26,8 +26,8 @@ public GetTheoryBlockByIdQueryHandler(StudySharpDbContext studySharpDbContext) public async Task> Handle(GetTheoryBlockByIdQuery request, CancellationToken cancellationToken) { - var course = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); - if (!course) + var courseExistent = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); + if (!courseExistent) { return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); } diff --git a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlocksByCourseIdQuery.cs b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlocksByCourseIdQuery.cs index 90d6573..a05ffeb 100644 --- a/server/StudySharp.ApplicationServices/Queries/GetTheoryBlocksByCourseIdQuery.cs +++ b/server/StudySharp.ApplicationServices/Queries/GetTheoryBlocksByCourseIdQuery.cs @@ -25,8 +25,8 @@ public GetTheoryBlockByCourseIdQueryHandler(StudySharpDbContext studySharpDbCont public async Task> Handle(GetTheoryBlocksByCourseIdQuery request, CancellationToken cancellationToken) { - var course = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); - if (!course) + var courseExistent = await _context.Courses.AnyAsync(_ => _.Id == request.CourseId, cancellationToken); + if (!courseExistent) { return OperationResult.Fail(string.Format(ErrorConstants.EntityNotFound, nameof(Course), nameof(Course.Id), request.CourseId)); }