From a2692d82d97211e15367ece2f0bc9fdf9cdd2cd9 Mon Sep 17 00:00:00 2001 From: ammwangi Date: Wed, 3 May 2023 08:32:22 +0300 Subject: [PATCH 01/11] get request for programmes, reports and user tasks --- .../Common/Mapper/AutoMapperInitializer.cs | 12 +++- .../Programme/Query/GetProgrammeResponse.cs | 25 +++++++++ .../Programme/Query/GetProgrammesCommand.cs | 9 +++ .../Query/GetProgrammesCommandHandler.cs | 39 +++++++++++++ .../Report/Query/GetReportsCommand.cs | 15 +++++ .../Report/Query/GetReportsCommandHandler.cs | 44 +++++++++++++++ .../Report/Query/GetReportsResponse.cs | 22 ++++++++ .../Query/GetCompletedUserTasksCommand.cs | 14 +++++ .../Query/GetCompletedUserTasksHandler.cs | 43 ++++++++++++++ .../Query/GetInProgressUserTasksCommand.cs | 14 +++++ .../Query/GetInProgressUserTasksHandler.cs | 43 ++++++++++++++ .../UserTasks/Query/GetUserTasksCommand.cs | 9 +++ .../Query/GetUserTasksCommandHandler.cs | 37 ++++++++++++ .../UserTasks/Query/GetUserTasksResponse.cs | 20 +++++++ .../mms.Application/mms.Application.csproj | 3 +- .../Controllers/ProgrammeController.cs | 20 +++++++ .../mms.api/Controllers/ReportController.cs | 21 +++++++ .../mms.api/Controllers/UserTaskController.cs | 56 +++++++++++++++++++ 18 files changed, 443 insertions(+), 3 deletions(-) create mode 100644 backend/src/mms.Application/Programme/Query/GetProgrammeResponse.cs create mode 100644 backend/src/mms.Application/Programme/Query/GetProgrammesCommand.cs create mode 100644 backend/src/mms.Application/Programme/Query/GetProgrammesCommandHandler.cs create mode 100644 backend/src/mms.Application/Report/Query/GetReportsCommand.cs create mode 100644 backend/src/mms.Application/Report/Query/GetReportsCommandHandler.cs create mode 100644 backend/src/mms.Application/Report/Query/GetReportsResponse.cs create mode 100644 backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksCommand.cs create mode 100644 backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksHandler.cs create mode 100644 backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksCommand.cs create mode 100644 backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksHandler.cs create mode 100644 backend/src/mms.Application/UserTasks/Query/GetUserTasksCommand.cs create mode 100644 backend/src/mms.Application/UserTasks/Query/GetUserTasksCommandHandler.cs create mode 100644 backend/src/mms.Application/UserTasks/Query/GetUserTasksResponse.cs create mode 100644 backend/src/mms.api/Controllers/ProgrammeController.cs create mode 100644 backend/src/mms.api/Controllers/ReportController.cs create mode 100644 backend/src/mms.api/Controllers/UserTaskController.cs diff --git a/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs b/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs index 2841d7e4..06ae166d 100644 --- a/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs +++ b/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs @@ -1,5 +1,4 @@ -using AutoMapper; -using mms.Application.Profile.Query.GetProfileById; +using mms.Application.Profile.Query.GetProfileById; using mms.Application.UserNotification.Command.EditUserNotification; using mms.Application.UserNotification.Query; using mms.Application.UserPrivacy.Command.EditUserPrivacy; @@ -7,6 +6,12 @@ using UserNotificationEntity = mms.Domain.Entities.UserNotification; using UserPrivacyEntity = mms.Domain.Entities.UserPrivacy; using AppUserEntity = mms.Domain.Entities.AppUser; +using Programmes = mms.Domain.Entities.Programme; +using Reports = mms.Domain.Entities.Report; +using mms.Application.UserTasks.Query; +using mms.Domain.Entities; +using mms.Application.Programme.Query; +using mms.Application.Report.Query; namespace mms.Application.Common.Mapper { @@ -19,6 +24,9 @@ public AutoMapperInitializer() CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); } } } \ No newline at end of file diff --git a/backend/src/mms.Application/Programme/Query/GetProgrammeResponse.cs b/backend/src/mms.Application/Programme/Query/GetProgrammeResponse.cs new file mode 100644 index 00000000..bc52d4e7 --- /dev/null +++ b/backend/src/mms.Application/Programme/Query/GetProgrammeResponse.cs @@ -0,0 +1,25 @@ +using mms.Domain.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.Programme.Query +{ + public class GetProgrammeResponse + { + + public string Name { get; set; } + public string Description { get; set; } + public string CreatedBy { get; set; } + public string Status { get; set; } + public string ArchivedBy { get; set; } + public string ProgrammePicture { get; set; } + public DateTime? UpdatedAt { get; set; } + public DateTime DateCreated { get; set; } + public DateTime? DateCompleted { get; set; } + public DateTime? DateArchived { get; set; } + public string Criteria { get; set; } + } +} diff --git a/backend/src/mms.Application/Programme/Query/GetProgrammesCommand.cs b/backend/src/mms.Application/Programme/Query/GetProgrammesCommand.cs new file mode 100644 index 00000000..af6714c8 --- /dev/null +++ b/backend/src/mms.Application/Programme/Query/GetProgrammesCommand.cs @@ -0,0 +1,9 @@ +using AspNetCoreHero.Results; +using MediatR; + +namespace mms.Application.Programme.Query +{ + public class GetProgrammesCommand : IRequest>> + { + } +} diff --git a/backend/src/mms.Application/Programme/Query/GetProgrammesCommandHandler.cs b/backend/src/mms.Application/Programme/Query/GetProgrammesCommandHandler.cs new file mode 100644 index 00000000..07cdc336 --- /dev/null +++ b/backend/src/mms.Application/Programme/Query/GetProgrammesCommandHandler.cs @@ -0,0 +1,39 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Application.UserPrivacy.Query; +using mms.Application.UserTasks.Query; +using mms.Infrastructure.Context; +using mms.Infrastructure.Interface; + +namespace mms.Application.Programme.Query +{ + public class GetProgrammesCommandHandler : IRequestHandler>> + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public GetProgrammesCommandHandler( ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task>> Handle(GetProgrammesCommand request, + CancellationToken cancellationToken) + { + var programmes = await _context.Programmes.OrderByDescending(x => x.DateCreated).ToListAsync(); + if (programmes == null) + { + return await Result>.FailAsync("No Programme Available"); + } + + var result = _mapper.Map>(programmes); + + return await Result>.SuccessAsync(result); + } + } +} diff --git a/backend/src/mms.Application/Report/Query/GetReportsCommand.cs b/backend/src/mms.Application/Report/Query/GetReportsCommand.cs new file mode 100644 index 00000000..eb692f00 --- /dev/null +++ b/backend/src/mms.Application/Report/Query/GetReportsCommand.cs @@ -0,0 +1,15 @@ +using AspNetCoreHero.Results; +using MediatR; +using mms.Application.UserTasks.Query; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.Report.Query +{ + public class GetReportsCommand : IRequest>> + { + } +} diff --git a/backend/src/mms.Application/Report/Query/GetReportsCommandHandler.cs b/backend/src/mms.Application/Report/Query/GetReportsCommandHandler.cs new file mode 100644 index 00000000..41d9673f --- /dev/null +++ b/backend/src/mms.Application/Report/Query/GetReportsCommandHandler.cs @@ -0,0 +1,44 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Application.UserTasks.Query; +using mms.Infrastructure.Context; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.Report.Query +{ + internal class GetReportsCommandHandler : IRequestHandler>> + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public GetReportsCommandHandler(ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task>> Handle(GetReportsCommand request, + CancellationToken cancellationToken) + { + + var reports = await _context.Reports.OrderByDescending(x => x.DateCreated).ToListAsync(); + if (reports == null) + { + return await Result>.FailAsync("No Reports Available"); + } + + var result = _mapper.Map>(reports); + + return await Result>.SuccessAsync(result); + } + } +} + diff --git a/backend/src/mms.Application/Report/Query/GetReportsResponse.cs b/backend/src/mms.Application/Report/Query/GetReportsResponse.cs new file mode 100644 index 00000000..c1268eee --- /dev/null +++ b/backend/src/mms.Application/Report/Query/GetReportsResponse.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.Report.Query +{ + public class GetReportsResponse + { + public string Type { get; set; } + public string ReportTitle { get; set; } + public string Achievements { get; set; } + public string Blocker { get; set; } + public string Recommendations { get; set; } + public DateTime DateCreated { get; set; } + public string CreatedBy { get; set; } + public DateTime? UpdatedAt { get; set; } + public string TaskId { get; set; } + public string ProgramId { get; set; } + } +} diff --git a/backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksCommand.cs b/backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksCommand.cs new file mode 100644 index 00000000..5fa233b1 --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksCommand.cs @@ -0,0 +1,14 @@ +using AspNetCoreHero.Results; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.UserTasks.Query +{ + public class GetCompletedUserTasksCommand : IRequest> + { + } +} diff --git a/backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksHandler.cs b/backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksHandler.cs new file mode 100644 index 00000000..6b85c88b --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksHandler.cs @@ -0,0 +1,43 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Infrastructure.Context; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.UserTasks.Query +{ + public class GetCompletedUserTasksHandler : IRequestHandler> + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public GetCompletedUserTasksHandler(ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task> Handle(GetCompletedUserTasksCommand request, + CancellationToken cancellationToken) + { + //TODO: + //Check how status are Inserted in the database for Tasks + var usertasks = await _context.UserTasks.Where(s => s.Status == "complete").OrderByDescending(x => x.DateCreated).ToListAsync(); + if (usertasks == null) + { + return await Result.FailAsync("No User Tasks Available"); + } + + var result = _mapper.Map(usertasks); + + return await Result.SuccessAsync(result); + } + } +} diff --git a/backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksCommand.cs b/backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksCommand.cs new file mode 100644 index 00000000..61664d04 --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksCommand.cs @@ -0,0 +1,14 @@ +using AspNetCoreHero.Results; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.UserTasks.Query +{ + public class GetInProgressUserTasksCommand:IRequest> + { + } +} diff --git a/backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksHandler.cs b/backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksHandler.cs new file mode 100644 index 00000000..a7eed7b1 --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksHandler.cs @@ -0,0 +1,43 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Infrastructure.Context; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.UserTasks.Query +{ + public class GetInProgressUserTasksHandler : IRequestHandler> + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public GetInProgressUserTasksHandler(ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task> Handle(GetInProgressUserTasksCommand request, + CancellationToken cancellationToken) + { + //TODO: + //Check how status are Inserted in the database for Tasks + var usertasks = await _context.UserTasks.Where(s => s.Status == "inprogress").OrderByDescending(x => x.DateCreated).ToListAsync(); + if (usertasks == null) + { + return await Result.FailAsync("No User Tasks Available"); + } + + var result = _mapper.Map(usertasks); + + return await Result.SuccessAsync(result); + } + } +} diff --git a/backend/src/mms.Application/UserTasks/Query/GetUserTasksCommand.cs b/backend/src/mms.Application/UserTasks/Query/GetUserTasksCommand.cs new file mode 100644 index 00000000..93670db8 --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Query/GetUserTasksCommand.cs @@ -0,0 +1,9 @@ +using AspNetCoreHero.Results; +using MediatR; + +namespace mms.Application.UserTasks.Query +{ + public class GetUserTasksCommand : IRequest>> + { + } +} diff --git a/backend/src/mms.Application/UserTasks/Query/GetUserTasksCommandHandler.cs b/backend/src/mms.Application/UserTasks/Query/GetUserTasksCommandHandler.cs new file mode 100644 index 00000000..389672e1 --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Query/GetUserTasksCommandHandler.cs @@ -0,0 +1,37 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Infrastructure.Context; + +namespace mms.Application.UserTasks.Query +{ + public class GetUserTasksCommandHandler : IRequestHandler>> + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public GetUserTasksCommandHandler( ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task>> Handle(GetUserTasksCommand request, + CancellationToken cancellationToken) + { + + var usertasks = await _context.UserTasks.OrderByDescending(x => x.DateCreated).ToListAsync(); + if (usertasks == null) + { + return await Result>.FailAsync("No User Tasks Available"); + } + + var result = _mapper.Map>(usertasks); + + return await Result>.SuccessAsync(result); + } + } +} diff --git a/backend/src/mms.Application/UserTasks/Query/GetUserTasksResponse.cs b/backend/src/mms.Application/UserTasks/Query/GetUserTasksResponse.cs new file mode 100644 index 00000000..55d52f50 --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Query/GetUserTasksResponse.cs @@ -0,0 +1,20 @@ +using mms.Domain.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.UserTasks.Query +{ + public class GetUserTasksResponse + { + public string Title { get; set; } + public string Description { get; set; } + public DateTime DateCreated { get; set; } + public string CreatedBy { get; set; } + public string Status { get; set; } + public string ProgramId { get; set; } + + } +} diff --git a/backend/src/mms.Application/mms.Application.csproj b/backend/src/mms.Application/mms.Application.csproj index b2e1eac0..63c54408 100644 --- a/backend/src/mms.Application/mms.Application.csproj +++ b/backend/src/mms.Application/mms.Application.csproj @@ -3,7 +3,7 @@ net7.0 enable - enable + disable @@ -30,5 +30,6 @@ + diff --git a/backend/src/mms.api/Controllers/ProgrammeController.cs b/backend/src/mms.api/Controllers/ProgrammeController.cs new file mode 100644 index 00000000..cb82d0a7 --- /dev/null +++ b/backend/src/mms.api/Controllers/ProgrammeController.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Mvc; +using mms.Application.Programme.Query; + +namespace mms.api.Controllers +{ + public class ProgrammeController:BaseController + { + [HttpGet("programmes")] + public async Task GetProgrammes() + { + var result = await Mediator.Send(new GetProgrammesCommand()); + if (result.Succeeded == false) + { + return BadRequest(result); + } + + return Ok(result); + } + } +} diff --git a/backend/src/mms.api/Controllers/ReportController.cs b/backend/src/mms.api/Controllers/ReportController.cs new file mode 100644 index 00000000..de5a02ad --- /dev/null +++ b/backend/src/mms.api/Controllers/ReportController.cs @@ -0,0 +1,21 @@ +using Microsoft.AspNetCore.Mvc; +using mms.Application.Programme.Query; +using mms.Application.Report.Query; + +namespace mms.api.Controllers +{ + public class ReportController : BaseController + { + [HttpGet("reports")] + public async Task GetReports() + { + var result = await Mediator.Send(new GetReportsCommand()); + if (result.Succeeded == false) + { + return BadRequest(result); + } + + return Ok(result); + } + } +} \ No newline at end of file diff --git a/backend/src/mms.api/Controllers/UserTaskController.cs b/backend/src/mms.api/Controllers/UserTaskController.cs new file mode 100644 index 00000000..fdea200f --- /dev/null +++ b/backend/src/mms.api/Controllers/UserTaskController.cs @@ -0,0 +1,56 @@ +using AspNetCoreHero.Results; +using Microsoft.AspNetCore.Mvc; +using mms.Application.UserTasks.Query; +using System.Net; + +namespace mms.api.Controllers +{ + public class UserTaskController: BaseController + { + [HttpGet("get-user-tasks")] + [ProducesResponseType(typeof(Result), (int)HttpStatusCode.OK)] + [ProducesResponseType(typeof(Result), (int)HttpStatusCode.BadRequest)] + public async Task GetUserTasks() + { + var result = await Mediator.Send(new GetUserTasksCommand()); + if (!result.Succeeded) + { + return BadRequest(result); + } + + return Ok(result); + } + + [HttpGet("get-completed-user-tasks")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetCompletedUserTasks() + { + var result = await Mediator.Send(new GetCompletedUserTasksCommand()); + if (!result.Succeeded) + { + return BadRequest(result); + } + + return Ok(result); + } + + [HttpGet("get-inprogress-user-tasks")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetInProgressUserTasks() + { + var result = await Mediator.Send(new GetInProgressUserTasksCommand()); + if (!result.Succeeded) + { + return BadRequest(result); + } + + return Ok(result); + } + + + + } + +} From 653eb5b738a252aa83227ae8774e19f65911350a Mon Sep 17 00:00:00 2001 From: ammwangi Date: Wed, 3 May 2023 09:17:27 +0300 Subject: [PATCH 02/11] get programme mentors --- .../Common/Mapper/AutoMapperInitializer.cs | 2 + .../Mentors/Query/GetMentorsCommand.cs | 9 ++++ .../Mentors/Query/GetMentorsCommandHandler.cs | 45 +++++++++++++++++++ .../Mentors/Query/GetMentorsResponse.cs | 18 ++++++++ .../mms.api/Controllers/MentorsController.cs | 20 +++++++++ 5 files changed, 94 insertions(+) create mode 100644 backend/src/mms.Application/Mentors/Query/GetMentorsCommand.cs create mode 100644 backend/src/mms.Application/Mentors/Query/GetMentorsCommandHandler.cs create mode 100644 backend/src/mms.Application/Mentors/Query/GetMentorsResponse.cs create mode 100644 backend/src/mms.api/Controllers/MentorsController.cs diff --git a/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs b/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs index 06ae166d..5409a136 100644 --- a/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs +++ b/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs @@ -12,6 +12,7 @@ using mms.Domain.Entities; using mms.Application.Programme.Query; using mms.Application.Report.Query; +using mms.Application.Mentors.Query; namespace mms.Application.Common.Mapper { @@ -27,6 +28,7 @@ public AutoMapperInitializer() CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); + CreateMap().ReverseMap(); } } } \ No newline at end of file diff --git a/backend/src/mms.Application/Mentors/Query/GetMentorsCommand.cs b/backend/src/mms.Application/Mentors/Query/GetMentorsCommand.cs new file mode 100644 index 00000000..1b2208dd --- /dev/null +++ b/backend/src/mms.Application/Mentors/Query/GetMentorsCommand.cs @@ -0,0 +1,9 @@ +using AspNetCoreHero.Results; +using MediatR; + +namespace mms.Application.Mentors.Query +{ + public class GetMentorsCommand : IRequest>> + { + } +} diff --git a/backend/src/mms.Application/Mentors/Query/GetMentorsCommandHandler.cs b/backend/src/mms.Application/Mentors/Query/GetMentorsCommandHandler.cs new file mode 100644 index 00000000..ff9375fd --- /dev/null +++ b/backend/src/mms.Application/Mentors/Query/GetMentorsCommandHandler.cs @@ -0,0 +1,45 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Infrastructure.Context; +using mms.Infrastructure.Interface; + +namespace mms.Application.Mentors.Query +{ + public class GetMentorsCommandHandler : IRequestHandler>> + { + private readonly ICurrentUserService _currentUserService; + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public GetMentorsCommandHandler(ICurrentUserService currentUserService, ApplicationContext context, + IMapper mapper) + { + _currentUserService = currentUserService; + _context = context; + _mapper = mapper; + } + + + public async Task>> Handle(GetMentorsCommand request, + CancellationToken cancellationToken) + { + if (string.IsNullOrEmpty(_currentUserService.AppUserId)) + { + return await Result>.FailAsync("Invalid user"); + } + + var mentors = await _context.ProgramsMentors.Include(y => y.Programme).Include(x => x.AppUser).Where(x => x.AppUserId == _currentUserService.AppUserId).ToListAsync(); + if (mentors == null) + { + return await Result>.FailAsync("No Mentors Available"); + } + + var result = _mapper.Map>(mentors); + + return await Result>.SuccessAsync(result); + } + } +} \ No newline at end of file diff --git a/backend/src/mms.Application/Mentors/Query/GetMentorsResponse.cs b/backend/src/mms.Application/Mentors/Query/GetMentorsResponse.cs new file mode 100644 index 00000000..4c888750 --- /dev/null +++ b/backend/src/mms.Application/Mentors/Query/GetMentorsResponse.cs @@ -0,0 +1,18 @@ +using mms.Domain.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProgrammEntity = mms.Domain.Entities.Programme; + +namespace mms.Application.Mentors.Query +{ + public class GetMentorsResponse + { + public string ProgramId { get; set; } + public string AppUserId { get; set; } + public ProgrammEntity Programme { get; set; } + public AppUser AppUser { get; set; } + } +} diff --git a/backend/src/mms.api/Controllers/MentorsController.cs b/backend/src/mms.api/Controllers/MentorsController.cs new file mode 100644 index 00000000..506270b0 --- /dev/null +++ b/backend/src/mms.api/Controllers/MentorsController.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Mvc; +using mms.Application.Mentors.Query; + +namespace mms.api.Controllers +{ + public class MentorsController : BaseController + { + [HttpGet("mentors")] + public async Task GetMentors() + { + var result = await Mediator.Send(new GetMentorsCommand()); + if (result.Succeeded == false) + { + return BadRequest(result); + } + + return Ok(result); + } + } +} From 882cbfec293f0659ec6595fe187900d079a51f0c Mon Sep 17 00:00:00 2001 From: ammwangi Date: Wed, 3 May 2023 09:42:52 +0300 Subject: [PATCH 03/11] get mentor Managers rest api --- .../Common/Mapper/AutoMapperInitializer.cs | 2 + .../Query/GetMentorManagersCommand.cs | 9 ++++ .../Query/GetMentorManagersCommandHandler.cs | 45 +++++++++++++++++++ .../Query/GetMentorManagersResponse.cs | 15 +++++++ .../src/mms.Domain/Entities/MentorManager.cs | 12 +++++ .../Context/ApplicationContext.cs | 1 + .../Controllers/MentorManagerController.cs | 20 +++++++++ .../Controllers/UserNotificationController.cs | 1 - 8 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 backend/src/mms.Application/MentorManagers/Query/GetMentorManagersCommand.cs create mode 100644 backend/src/mms.Application/MentorManagers/Query/GetMentorManagersCommandHandler.cs create mode 100644 backend/src/mms.Application/MentorManagers/Query/GetMentorManagersResponse.cs create mode 100644 backend/src/mms.Domain/Entities/MentorManager.cs create mode 100644 backend/src/mms.api/Controllers/MentorManagerController.cs diff --git a/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs b/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs index 5409a136..36f620d1 100644 --- a/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs +++ b/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs @@ -13,6 +13,7 @@ using mms.Application.Programme.Query; using mms.Application.Report.Query; using mms.Application.Mentors.Query; +using mms.Application.MentorManagers.Query; namespace mms.Application.Common.Mapper { @@ -29,6 +30,7 @@ public AutoMapperInitializer() CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); + CreateMap().ReverseMap(); } } } \ No newline at end of file diff --git a/backend/src/mms.Application/MentorManagers/Query/GetMentorManagersCommand.cs b/backend/src/mms.Application/MentorManagers/Query/GetMentorManagersCommand.cs new file mode 100644 index 00000000..e6db7834 --- /dev/null +++ b/backend/src/mms.Application/MentorManagers/Query/GetMentorManagersCommand.cs @@ -0,0 +1,9 @@ +using AspNetCoreHero.Results; +using MediatR; + +namespace mms.Application.MentorManagers.Query +{ + public class GetMentorManagersCommand : IRequest>> + { + } +} diff --git a/backend/src/mms.Application/MentorManagers/Query/GetMentorManagersCommandHandler.cs b/backend/src/mms.Application/MentorManagers/Query/GetMentorManagersCommandHandler.cs new file mode 100644 index 00000000..9f0d71b0 --- /dev/null +++ b/backend/src/mms.Application/MentorManagers/Query/GetMentorManagersCommandHandler.cs @@ -0,0 +1,45 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Infrastructure.Context; +using mms.Infrastructure.Interface; + +namespace mms.Application.MentorManagers.Query +{ + public class GetMentorManagersCommandHandler : IRequestHandler>> + { + private readonly ICurrentUserService _currentUserService; + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public GetMentorManagersCommandHandler(ICurrentUserService currentUserService, ApplicationContext context, + IMapper mapper) + { + _currentUserService = currentUserService; + _context = context; + _mapper = mapper; + } + + + public async Task>> Handle(GetMentorManagersCommand request, + CancellationToken cancellationToken) + { + if (string.IsNullOrEmpty(_currentUserService.AppUserId)) + { + return await Result>.FailAsync("Invalid user"); + } + + var mentors = await _context.MentorManagers.Include(M => M.ProgramsMentors).Include(y => y.Programmes).Include(x => x.AppUser).Where(x => x.AppUserId == _currentUserService.AppUserId).ToListAsync(); + if (mentors == null) + { + return await Result>.FailAsync("No Mentor Managers Available"); + } + + var result = _mapper.Map>(mentors); + + return await Result>.SuccessAsync(result); + } + } +} diff --git a/backend/src/mms.Application/MentorManagers/Query/GetMentorManagersResponse.cs b/backend/src/mms.Application/MentorManagers/Query/GetMentorManagersResponse.cs new file mode 100644 index 00000000..59d1d3dc --- /dev/null +++ b/backend/src/mms.Application/MentorManagers/Query/GetMentorManagersResponse.cs @@ -0,0 +1,15 @@ +using mms.Domain.Entities; +using ProgrammeEntity = mms.Domain.Entities.Programme; + +namespace mms.Application.MentorManagers.Query +{ + public class GetMentorManagersResponse + { + public string ProgramsMentorId { get; set; } + public string AppUserId { get; set; } + public string ProgramId { get; set; } + public ProgramsMentor ProgramsMentor { get; set; } + public ProgrammeEntity Programme { get; set; } + public AppUser AppUser { get; set; } + } +} diff --git a/backend/src/mms.Domain/Entities/MentorManager.cs b/backend/src/mms.Domain/Entities/MentorManager.cs new file mode 100644 index 00000000..58d69fb7 --- /dev/null +++ b/backend/src/mms.Domain/Entities/MentorManager.cs @@ -0,0 +1,12 @@ +using mms.Domain.Common; + +namespace mms.Domain.Entities +{ + public class MentorManager : BaseEntity + { + public string AppUserId { get; set; } + public IList ProgramsMentors { get; set; } + public IList Programmes { get; set; } + public AppUser AppUser { get; set; } + } +} diff --git a/backend/src/mms.Infrastructure/Context/ApplicationContext.cs b/backend/src/mms.Infrastructure/Context/ApplicationContext.cs index 052ffa17..e3044e40 100644 --- a/backend/src/mms.Infrastructure/Context/ApplicationContext.cs +++ b/backend/src/mms.Infrastructure/Context/ApplicationContext.cs @@ -16,6 +16,7 @@ public ApplicationContext(DbContextOptions options) : base(o public DbSet Programmes { get; set; } public DbSet ProgrammeApplications { get; set; } public DbSet ProgramsMentors { get; set; } + public DbSet MentorManagers { get; set; } public DbSet Reports { get; set; } public DbSet UserTasks { get; set; } public DbSet TechStacks { get; set; } diff --git a/backend/src/mms.api/Controllers/MentorManagerController.cs b/backend/src/mms.api/Controllers/MentorManagerController.cs new file mode 100644 index 00000000..e8ecd3d3 --- /dev/null +++ b/backend/src/mms.api/Controllers/MentorManagerController.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Mvc; +using mms.Application.MentorManagers.Query; + +namespace mms.api.Controllers +{ + public class MentorManagerController : BaseController + { + [HttpGet("mentor-managers")] + public async Task GetMentorManagers() + { + var result = await Mediator.Send(new GetMentorManagersCommand()); + if (result.Succeeded == false) + { + return BadRequest(result); + } + + return Ok(result); + } + } +} diff --git a/backend/src/mms.api/Controllers/UserNotificationController.cs b/backend/src/mms.api/Controllers/UserNotificationController.cs index d72796fa..60bcb350 100644 --- a/backend/src/mms.api/Controllers/UserNotificationController.cs +++ b/backend/src/mms.api/Controllers/UserNotificationController.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.Mvc; using mms.Application.UserNotification.Command.EditUserNotification; using mms.Application.UserNotification.Query; -using static Microsoft.EntityFrameworkCore.DbLoggerCategory.Database; namespace mms.api.Controllers { From 18b765a4aa69fdb11eb2e5a56b4cb04d3939513e Mon Sep 17 00:00:00 2001 From: ammwangi Date: Mon, 8 May 2023 06:49:21 +0300 Subject: [PATCH 04/11] Fix get requests --- .../Common/Mapper/AutoMapperInitializer.cs | 6 +++--- .../Command/CreateTask/CreateTaskCommand.cs | 12 +++++++++++ .../CreateTask/Requests/CreateTaskRequest.cs | 20 +++++++++++++++++++ .../Query/GetCompletedUserTasksCommand.cs | 2 +- .../Query/GetCompletedUserTasksHandler.cs | 15 +++++--------- .../Query/GetInProgressUserTasksCommand.cs | 2 +- .../Query/GetInProgressUserTasksHandler.cs | 10 +++++----- .../mms.api/Controllers/UserTaskController.cs | 18 ++++++++++++++--- 8 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 backend/src/mms.Application/UserTasks/Command/CreateTask/CreateTaskCommand.cs create mode 100644 backend/src/mms.Application/UserTasks/Command/CreateTask/Requests/CreateTaskRequest.cs diff --git a/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs b/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs index 36f620d1..20bfc456 100644 --- a/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs +++ b/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs @@ -28,9 +28,9 @@ public AutoMapperInitializer() CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); - CreateMap().ReverseMap(); - CreateMap().ReverseMap(); - CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); } } } \ No newline at end of file diff --git a/backend/src/mms.Application/UserTasks/Command/CreateTask/CreateTaskCommand.cs b/backend/src/mms.Application/UserTasks/Command/CreateTask/CreateTaskCommand.cs new file mode 100644 index 00000000..1085c8b2 --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Command/CreateTask/CreateTaskCommand.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.UserTasks.Command.CreateTask +{ + public class CreateTaskCommand + { + } +} diff --git a/backend/src/mms.Application/UserTasks/Command/CreateTask/Requests/CreateTaskRequest.cs b/backend/src/mms.Application/UserTasks/Command/CreateTask/Requests/CreateTaskRequest.cs new file mode 100644 index 00000000..0d9bfb95 --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Command/CreateTask/Requests/CreateTaskRequest.cs @@ -0,0 +1,20 @@ +using mms.Domain.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.UserTasks.Command.CreateTask.Requests +{ + public class CreateTaskRequest + { + public string Title { get; set; } + public string Description { get; set; } + public DateTime DateCreated { get; set; } + public string CreatedBy { get; set; } + public string Status { get; set; } + public string ProgramId { get; set; } + public IList Managers { get; set; } + } +} diff --git a/backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksCommand.cs b/backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksCommand.cs index 5fa233b1..55bd18a0 100644 --- a/backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksCommand.cs +++ b/backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksCommand.cs @@ -8,7 +8,7 @@ namespace mms.Application.UserTasks.Query { - public class GetCompletedUserTasksCommand : IRequest> + public class GetCompletedUserTasksCommand : IRequest>> { } } diff --git a/backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksHandler.cs b/backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksHandler.cs index 6b85c88b..d91e5a2c 100644 --- a/backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksHandler.cs +++ b/backend/src/mms.Application/UserTasks/Query/GetCompletedUserTasksHandler.cs @@ -3,16 +3,11 @@ using MediatR; using Microsoft.EntityFrameworkCore; using mms.Infrastructure.Context; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace mms.Application.UserTasks.Query { public class GetCompletedUserTasksHandler : IRequestHandler> + IResult>> { private readonly ApplicationContext _context; private readonly IMapper _mapper; @@ -24,7 +19,7 @@ public GetCompletedUserTasksHandler(ApplicationContext context, _mapper = mapper; } - public async Task> Handle(GetCompletedUserTasksCommand request, + public async Task>> Handle(GetCompletedUserTasksCommand request, CancellationToken cancellationToken) { //TODO: @@ -32,12 +27,12 @@ public async Task> Handle(GetCompletedUserTasksCom var usertasks = await _context.UserTasks.Where(s => s.Status == "complete").OrderByDescending(x => x.DateCreated).ToListAsync(); if (usertasks == null) { - return await Result.FailAsync("No User Tasks Available"); + return await Result>.FailAsync("No User Tasks Available"); } - var result = _mapper.Map(usertasks); + var result = _mapper.Map>(usertasks); - return await Result.SuccessAsync(result); + return await Result>.SuccessAsync(result); } } } diff --git a/backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksCommand.cs b/backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksCommand.cs index 61664d04..ab479366 100644 --- a/backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksCommand.cs +++ b/backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksCommand.cs @@ -8,7 +8,7 @@ namespace mms.Application.UserTasks.Query { - public class GetInProgressUserTasksCommand:IRequest> + public class GetInProgressUserTasksCommand:IRequest>> { } } diff --git a/backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksHandler.cs b/backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksHandler.cs index a7eed7b1..22d56784 100644 --- a/backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksHandler.cs +++ b/backend/src/mms.Application/UserTasks/Query/GetInProgressUserTasksHandler.cs @@ -12,7 +12,7 @@ namespace mms.Application.UserTasks.Query { public class GetInProgressUserTasksHandler : IRequestHandler> + IResult>> { private readonly ApplicationContext _context; private readonly IMapper _mapper; @@ -24,7 +24,7 @@ public GetInProgressUserTasksHandler(ApplicationContext context, _mapper = mapper; } - public async Task> Handle(GetInProgressUserTasksCommand request, + public async Task>> Handle(GetInProgressUserTasksCommand request, CancellationToken cancellationToken) { //TODO: @@ -32,12 +32,12 @@ public async Task> Handle(GetInProgressUserTasksCo var usertasks = await _context.UserTasks.Where(s => s.Status == "inprogress").OrderByDescending(x => x.DateCreated).ToListAsync(); if (usertasks == null) { - return await Result.FailAsync("No User Tasks Available"); + return await Result>.FailAsync("No User Tasks Available"); } - var result = _mapper.Map(usertasks); + var result = _mapper.Map>(usertasks); - return await Result.SuccessAsync(result); + return await Result>.SuccessAsync(result); } } } diff --git a/backend/src/mms.api/Controllers/UserTaskController.cs b/backend/src/mms.api/Controllers/UserTaskController.cs index fdea200f..db50d874 100644 --- a/backend/src/mms.api/Controllers/UserTaskController.cs +++ b/backend/src/mms.api/Controllers/UserTaskController.cs @@ -1,5 +1,6 @@ using AspNetCoreHero.Results; using Microsoft.AspNetCore.Mvc; +using mms.Application.UserTasks.Command.CreateTask; using mms.Application.UserTasks.Query; using System.Net; @@ -7,7 +8,7 @@ namespace mms.api.Controllers { public class UserTaskController: BaseController { - [HttpGet("get-user-tasks")] + [HttpGet("get-tasks")] [ProducesResponseType(typeof(Result), (int)HttpStatusCode.OK)] [ProducesResponseType(typeof(Result), (int)HttpStatusCode.BadRequest)] public async Task GetUserTasks() @@ -21,7 +22,7 @@ public async Task GetUserTasks() return Ok(result); } - [HttpGet("get-completed-user-tasks")] + [HttpGet("get-completed-tasks")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task GetCompletedUserTasks() @@ -35,7 +36,7 @@ public async Task GetCompletedUserTasks() return Ok(result); } - [HttpGet("get-inprogress-user-tasks")] + [HttpGet("get-inprogress-tasks")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task GetInProgressUserTasks() @@ -49,6 +50,17 @@ public async Task GetInProgressUserTasks() return Ok(result); } + [HttpPost] + public async Task CreateTask([FromBody] CreateTaskRequest request) + { + var task = await Mediator.Send(new CreateTaskCommand( + request.Title, + request.Description, + request.Genre, + request.Rating)); + + return Ok(task); + } } From 074037b5c4f54f9739305e2dfcb1338203a4a8ae Mon Sep 17 00:00:00 2001 From: ammwangi Date: Mon, 8 May 2023 21:22:13 +0300 Subject: [PATCH 05/11] Create and edit for Tasks and reports --- .../Common/Mapper/AutoMapperInitializer.cs | 10 +++++ .../Report/Command/CreateReportCommand.cs | 19 +++++++++ .../Command/CreateReportCommandHandler.cs | 31 ++++++++++++++ .../Report/Command/PutReportCommand.cs | 25 +++++++++++ .../Report/Command/PutReportCommandHandler.cs | 38 +++++++++++++++++ .../Report/Command/UpdateReportRequest.cs | 21 ++++++++++ .../Command/CreateTask/CreateTaskCommand.cs | 14 ++++++- .../CreateTask/CreateTaskCommandHandler.cs | 37 +++++++++++++++++ .../Command/CreateTask/PutUserTaskCommand.cs | 25 +++++++++++ .../CreateTask/PutUserTaskCommandHandler.cs | 39 ++++++++++++++++++ ...askRequest.cs => UpdateUserTaskRequest.cs} | 4 +- backend/src/mms.Domain/Entities/Report.cs | 1 + backend/src/mms.Domain/Entities/UserTask.cs | 1 + .../mms.api/Controllers/ReportController.cs | 39 ++++++++++++++++++ .../mms.api/Controllers/UserTaskController.cs | 41 +++++++++++++++---- 15 files changed, 333 insertions(+), 12 deletions(-) create mode 100644 backend/src/mms.Application/Report/Command/CreateReportCommand.cs create mode 100644 backend/src/mms.Application/Report/Command/CreateReportCommandHandler.cs create mode 100644 backend/src/mms.Application/Report/Command/PutReportCommand.cs create mode 100644 backend/src/mms.Application/Report/Command/PutReportCommandHandler.cs create mode 100644 backend/src/mms.Application/Report/Command/UpdateReportRequest.cs create mode 100644 backend/src/mms.Application/UserTasks/Command/CreateTask/CreateTaskCommandHandler.cs create mode 100644 backend/src/mms.Application/UserTasks/Command/CreateTask/PutUserTaskCommand.cs create mode 100644 backend/src/mms.Application/UserTasks/Command/CreateTask/PutUserTaskCommandHandler.cs rename backend/src/mms.Application/UserTasks/Command/CreateTask/{Requests/CreateTaskRequest.cs => UpdateUserTaskRequest.cs} (83%) diff --git a/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs b/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs index 8005a0f7..2385c632 100644 --- a/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs +++ b/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs @@ -21,6 +21,8 @@ using mms.Application.Report.Query; using mms.Application.Mentors.Query; using mms.Application.MentorManagers.Query; +using mms.Application.UserTasks.Command.CreateTask; +using mms.Application.Report.Command; namespace mms.Application.Common.Mapper { @@ -39,9 +41,17 @@ public AutoMapperInitializer() CreateMap().ReverseMap(); CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); CreateMap().ReverseMap(); diff --git a/backend/src/mms.Application/Report/Command/CreateReportCommand.cs b/backend/src/mms.Application/Report/Command/CreateReportCommand.cs new file mode 100644 index 00000000..cc3139c8 --- /dev/null +++ b/backend/src/mms.Application/Report/Command/CreateReportCommand.cs @@ -0,0 +1,19 @@ +using AspNetCoreHero.Results; +using MediatR; + +namespace mms.Application.Report.Command +{ + public class CreateReportCommand : IRequest + { + public string Type { get; set; } + public string ReportTitle { get; set; } + public string Achievements { get; set; } + public string Blocker { get; set; } + public string Recommendations { get; set; } + public DateTime DateCreated { get; set; } + public string CreatedBy { get; set; } + public string TaskId { get; set; } + public string ProgramId { get; set; } + + } +} diff --git a/backend/src/mms.Application/Report/Command/CreateReportCommandHandler.cs b/backend/src/mms.Application/Report/Command/CreateReportCommandHandler.cs new file mode 100644 index 00000000..dc34276a --- /dev/null +++ b/backend/src/mms.Application/Report/Command/CreateReportCommandHandler.cs @@ -0,0 +1,31 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using mms.Infrastructure.Context; + +namespace mms.Application.Report.Command +{ + public class CreateReportCommandHandler : IRequestHandler + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public CreateReportCommandHandler(ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task Handle(CreateReportCommand request, CancellationToken cancellationToken) + { + var report = _mapper.Map(request); + + report.Id = Guid.NewGuid().ToString(); + report.CreatedAt = DateTime.Now; + await _context.Reports.AddAsync(report); + await _context.SaveChangesAsync(cancellationToken); + return await Result.SuccessAsync(); + } + } +} diff --git a/backend/src/mms.Application/Report/Command/PutReportCommand.cs b/backend/src/mms.Application/Report/Command/PutReportCommand.cs new file mode 100644 index 00000000..db71f6a1 --- /dev/null +++ b/backend/src/mms.Application/Report/Command/PutReportCommand.cs @@ -0,0 +1,25 @@ +using AspNetCoreHero.Results; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.Report.Command +{ + public class PutReportCommand : IRequest> + { + public string Id { get; set; } + public string Type { get; set; } + public string ReportTitle { get; set; } + public string Achievements { get; set; } + public string Blocker { get; set; } + public string Recommendations { get; set; } + public DateTime DateCreated { get; set; } + public string CreatedBy { get; set; } + public string TaskId { get; set; } + public string ProgramId { get; set; } + public DateTime UpdatedAt { get; set; } + } +} diff --git a/backend/src/mms.Application/Report/Command/PutReportCommandHandler.cs b/backend/src/mms.Application/Report/Command/PutReportCommandHandler.cs new file mode 100644 index 00000000..9f9700dc --- /dev/null +++ b/backend/src/mms.Application/Report/Command/PutReportCommandHandler.cs @@ -0,0 +1,38 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Infrastructure.Context; + +namespace mms.Application.Report.Command +{ + public class PutReportCommandHandler : IRequestHandler> + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public PutReportCommandHandler(ApplicationContext context, IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task> Handle(PutReportCommand request, CancellationToken cancellationToken) + { + + var report = + await _context.Reports.FirstOrDefaultAsync(x => x.Id.Equals(request.Id), + cancellationToken); + if (report == null) + { + return await Result.FailAsync($"Report with Id {request.Id} does not exist"); + } + + var entity = _mapper.Map(request, report); + + _context.Reports.Update(entity); + await _context.SaveChangesAsync(cancellationToken); + return await Result.SuccessAsync("Successful"); + } + } +} \ No newline at end of file diff --git a/backend/src/mms.Application/Report/Command/UpdateReportRequest.cs b/backend/src/mms.Application/Report/Command/UpdateReportRequest.cs new file mode 100644 index 00000000..926aa3c2 --- /dev/null +++ b/backend/src/mms.Application/Report/Command/UpdateReportRequest.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.Report.Command +{ + public class UpdateReportRequest + { + public string Type { get; set; } + public string ReportTitle { get; set; } + public string Achievements { get; set; } + public string Blocker { get; set; } + public string Recommendations { get; set; } + public DateTime DateCreated { get; set; } + public string CreatedBy { get; set; } + public string TaskId { get; set; } + public string ProgramId { get; set; } + } +} diff --git a/backend/src/mms.Application/UserTasks/Command/CreateTask/CreateTaskCommand.cs b/backend/src/mms.Application/UserTasks/Command/CreateTask/CreateTaskCommand.cs index 1085c8b2..18e7422a 100644 --- a/backend/src/mms.Application/UserTasks/Command/CreateTask/CreateTaskCommand.cs +++ b/backend/src/mms.Application/UserTasks/Command/CreateTask/CreateTaskCommand.cs @@ -1,4 +1,7 @@ -using System; +using AspNetCoreHero.Results; +using MediatR; +using mms.Domain.Entities; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +9,14 @@ namespace mms.Application.UserTasks.Command.CreateTask { - public class CreateTaskCommand + public class CreateTaskCommand: IRequest> { + public string Title { get; set; } + public string Description { get; set; } + public DateTime DateCreated { get; set; } + public string CreatedBy { get; set; } + public string Status { get; set; } + public string ProgramId { get; set; } + public IList Managers { get; set; } } } diff --git a/backend/src/mms.Application/UserTasks/Command/CreateTask/CreateTaskCommandHandler.cs b/backend/src/mms.Application/UserTasks/Command/CreateTask/CreateTaskCommandHandler.cs new file mode 100644 index 00000000..fe2339fc --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Command/CreateTask/CreateTaskCommandHandler.cs @@ -0,0 +1,37 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using mms.Application.Support.Command; +using mms.Infrastructure.Context; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.UserTasks.Command.CreateTask +{ + public class CreateTaskCommandHandler : IRequestHandler + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public CreateTaskCommandHandler(ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task Handle(CreateTaskCommand request, CancellationToken cancellationToken) + { + var taskEntity = _mapper.Map(request); + + taskEntity.Id = Guid.NewGuid().ToString(); + taskEntity.CreatedAt = DateTime.Now; + await _context.UserTasks.AddAsync(taskEntity); + await _context.SaveChangesAsync(cancellationToken); + return await Result.SuccessAsync(); + } + } +} diff --git a/backend/src/mms.Application/UserTasks/Command/CreateTask/PutUserTaskCommand.cs b/backend/src/mms.Application/UserTasks/Command/CreateTask/PutUserTaskCommand.cs new file mode 100644 index 00000000..7f5300f8 --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Command/CreateTask/PutUserTaskCommand.cs @@ -0,0 +1,25 @@ +using AspNetCoreHero.Results; +using MediatR; +using mms.Domain.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.UserTasks.Command.CreateTask +{ + public class PutUserTaskCommand : IRequest> + { + public string Id { get; set; } + public string Title { get; set; } + public string Description { get; set; } + public DateTime DateCreated { get; set; } + public string CreatedBy { get; set; } + public string Status { get; set; } + public string ProgramId { get; set; } + public DateTime UpdatedAt { get; set; } + public IList Managers { get; set; } + + } +} diff --git a/backend/src/mms.Application/UserTasks/Command/CreateTask/PutUserTaskCommandHandler.cs b/backend/src/mms.Application/UserTasks/Command/CreateTask/PutUserTaskCommandHandler.cs new file mode 100644 index 00000000..81f0f0de --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Command/CreateTask/PutUserTaskCommandHandler.cs @@ -0,0 +1,39 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Infrastructure.Context; +using mms.Infrastructure.Interface; + +namespace mms.Application.UserTasks.Command.CreateTask +{ + public class PutUserTaskCommandHandler : IRequestHandler> + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public PutUserTaskCommandHandler(ApplicationContext context, IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task> Handle(PutUserTaskCommand request, CancellationToken cancellationToken) + { + + var task = + await _context.UserTasks.FirstOrDefaultAsync(x => x.Id.Equals(request.Id), + cancellationToken); + if (task == null) + { + return await Result.FailAsync($"Task with Id {request.Id} does not exist"); + } + + var entity = _mapper.Map(request, task); + + _context.UserTasks.Update(entity); + await _context.SaveChangesAsync(cancellationToken); + return await Result.SuccessAsync("Successful"); + } + } +} diff --git a/backend/src/mms.Application/UserTasks/Command/CreateTask/Requests/CreateTaskRequest.cs b/backend/src/mms.Application/UserTasks/Command/CreateTask/UpdateUserTaskRequest.cs similarity index 83% rename from backend/src/mms.Application/UserTasks/Command/CreateTask/Requests/CreateTaskRequest.cs rename to backend/src/mms.Application/UserTasks/Command/CreateTask/UpdateUserTaskRequest.cs index 0d9bfb95..eeee86bf 100644 --- a/backend/src/mms.Application/UserTasks/Command/CreateTask/Requests/CreateTaskRequest.cs +++ b/backend/src/mms.Application/UserTasks/Command/CreateTask/UpdateUserTaskRequest.cs @@ -5,9 +5,9 @@ using System.Text; using System.Threading.Tasks; -namespace mms.Application.UserTasks.Command.CreateTask.Requests +namespace mms.Application.UserTasks.Command.CreateTask { - public class CreateTaskRequest + public class UpdateUserTaskRequest { public string Title { get; set; } public string Description { get; set; } diff --git a/backend/src/mms.Domain/Entities/Report.cs b/backend/src/mms.Domain/Entities/Report.cs index 0fdee6e0..e4393f1f 100644 --- a/backend/src/mms.Domain/Entities/Report.cs +++ b/backend/src/mms.Domain/Entities/Report.cs @@ -13,5 +13,6 @@ public class Report : BaseEntity public string CreatedBy { get; set; } public string TaskId { get; set; } public string ProgramId { get; set; } + public Programme Programme { get; set; } } } \ No newline at end of file diff --git a/backend/src/mms.Domain/Entities/UserTask.cs b/backend/src/mms.Domain/Entities/UserTask.cs index 07f3a735..c5b906e7 100644 --- a/backend/src/mms.Domain/Entities/UserTask.cs +++ b/backend/src/mms.Domain/Entities/UserTask.cs @@ -11,5 +11,6 @@ public class UserTask : BaseEntity public string Status { get; set; } public string ProgramId { get; set; } public IList Managers { get; set; } + public Programme Programme { get; set; } } } \ No newline at end of file diff --git a/backend/src/mms.api/Controllers/ReportController.cs b/backend/src/mms.api/Controllers/ReportController.cs index de5a02ad..4377c3ab 100644 --- a/backend/src/mms.api/Controllers/ReportController.cs +++ b/backend/src/mms.api/Controllers/ReportController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using mms.Application.Programme.Query; +using mms.Application.Report.Command; using mms.Application.Report.Query; namespace mms.api.Controllers @@ -17,5 +18,43 @@ public async Task GetReports() return Ok(result); } + + [HttpPost("report")] + public async Task CreateTask(CreateReportCommand command) + { + var result = await Mediator.Send(command); + if (result.Succeeded == false) + { + return BadRequest(result); + } + + return Ok(result); + } + + [HttpPut("report/{id}")] + public async Task PutReport(string id, [FromBody] UpdateReportRequest request) + { + PutReportCommand command = new() + { + Id = id, + UpdatedAt = DateTime.Now, + CreatedBy = request.CreatedBy, + Achievements = request.Achievements, + Blocker = request.Blocker, + Recommendations = request.Recommendations, + ReportTitle = request.ReportTitle, + TaskId = request.TaskId, + Type = request.Type, + ProgramId = request.ProgramId, + }; + + var result = await Mediator.Send(command); + if (result.Succeeded == false) + { + return BadRequest(result); + } + + return Ok(result); + } } } \ No newline at end of file diff --git a/backend/src/mms.api/Controllers/UserTaskController.cs b/backend/src/mms.api/Controllers/UserTaskController.cs index db50d874..20f6b9cd 100644 --- a/backend/src/mms.api/Controllers/UserTaskController.cs +++ b/backend/src/mms.api/Controllers/UserTaskController.cs @@ -50,19 +50,44 @@ public async Task GetInProgressUserTasks() return Ok(result); } - [HttpPost] - public async Task CreateTask([FromBody] CreateTaskRequest request) + [HttpPost("task")] + public async Task CreateTask(CreateTaskCommand command) { - var task = await Mediator.Send(new CreateTaskCommand( - request.Title, - request.Description, - request.Genre, - request.Rating)); + var result = await Mediator.Send(command); + if (result.Succeeded == false) + { + return BadRequest(result); + } - return Ok(task); + return Ok(result); } + + [HttpPut("task/{id}")] + public async Task PutTask(string id, [FromBody] UpdateUserTaskRequest request) + { + PutUserTaskCommand command = new() + { + Id = id, + UpdatedAt = DateTime.Now, + Description = request.Description, + CreatedBy = request.CreatedBy, + Status = request.Status, + ProgramId = request.ProgramId, + Title = request.Title, + Managers = request.Managers, + }; + + var result = await Mediator.Send(command); + if (result.Succeeded == false) + { + return BadRequest(result); + } + + return Ok(result); + } + } } From 64f699eacb26c23436ac2ad65869d5b1d04caf32 Mon Sep 17 00:00:00 2001 From: ammwangi Date: Mon, 8 May 2023 21:48:28 +0300 Subject: [PATCH 06/11] Create programme --- .../Command/CreateProgrammeCommand.cs | 29 ++++++++++++++ .../Command/CreateProgrammeCommandHandler.cs | 38 +++++++++++++++++++ .../mms.Application/mms.Application.csproj | 1 - .../Controllers/ProgrammeController.cs | 16 +++++++- 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 backend/src/mms.Application/Programme/Command/CreateProgrammeCommand.cs create mode 100644 backend/src/mms.Application/Programme/Command/CreateProgrammeCommandHandler.cs diff --git a/backend/src/mms.Application/Programme/Command/CreateProgrammeCommand.cs b/backend/src/mms.Application/Programme/Command/CreateProgrammeCommand.cs new file mode 100644 index 00000000..da5acea5 --- /dev/null +++ b/backend/src/mms.Application/Programme/Command/CreateProgrammeCommand.cs @@ -0,0 +1,29 @@ +using AspNetCoreHero.Results; +using MediatR; +using mms.Domain.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.Programme.Command +{ + public class CreateProgrammeCommand : IRequest + { + public string Name { get; set; } + public string Description { get; set; } + public string CreatedBy { get; set; } + public string Status { get; set; } + public string ArchivedBy { get; set; } + public string ProgrammePicture { get; set; } + public IList UserTasks { get; set; } + public DateTime DateCreated { get; set; } + public DateTime? DateCompleted { get; set; } + public DateTime? DateArchived { get; set; } + public string Criteria { get; set; } + public IList Reports { get; set; } + public IList ProgramsMentors { get; set; } + public IList ProgrammeApplications { get; set; } + } +} diff --git a/backend/src/mms.Application/Programme/Command/CreateProgrammeCommandHandler.cs b/backend/src/mms.Application/Programme/Command/CreateProgrammeCommandHandler.cs new file mode 100644 index 00000000..ffeaa5d8 --- /dev/null +++ b/backend/src/mms.Application/Programme/Command/CreateProgrammeCommandHandler.cs @@ -0,0 +1,38 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using mms.Application.Report.Command; +using mms.Domain.Entities; +using mms.Infrastructure.Context; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.Programme.Command +{ + public class CreateProgrammeCommandHandler : IRequestHandler + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public CreateProgrammeCommandHandler(ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task Handle(CreateProgrammeCommand request, CancellationToken cancellationToken) + { + var programme = _mapper.Map(request); + + programme.Id = Guid.NewGuid().ToString(); + programme.CreatedAt = DateTime.Now; + await _context.Programmes.AddAsync(programme); + await _context.SaveChangesAsync(cancellationToken); + return await Result.SuccessAsync(); + } + } +} diff --git a/backend/src/mms.Application/mms.Application.csproj b/backend/src/mms.Application/mms.Application.csproj index 8da42df1..c7c1df88 100644 --- a/backend/src/mms.Application/mms.Application.csproj +++ b/backend/src/mms.Application/mms.Application.csproj @@ -44,6 +44,5 @@ - diff --git a/backend/src/mms.api/Controllers/ProgrammeController.cs b/backend/src/mms.api/Controllers/ProgrammeController.cs index cb82d0a7..27a3bcc3 100644 --- a/backend/src/mms.api/Controllers/ProgrammeController.cs +++ b/backend/src/mms.api/Controllers/ProgrammeController.cs @@ -1,11 +1,13 @@ using Microsoft.AspNetCore.Mvc; +using mms.Application.Programme.Command; using mms.Application.Programme.Query; +using mms.Application.Report.Command; namespace mms.api.Controllers { public class ProgrammeController:BaseController { - [HttpGet("programmes")] + [HttpGet("programme")] public async Task GetProgrammes() { var result = await Mediator.Send(new GetProgrammesCommand()); @@ -16,5 +18,17 @@ public async Task GetProgrammes() return Ok(result); } + + [HttpPost("programme")] + public async Task CreateTask(CreateProgrammeCommand command) + { + var result = await Mediator.Send(command); + if (result.Succeeded == false) + { + return BadRequest(result); + } + + return Ok(result); + } } } From 1d6e9738ee4d833b7c14958f6b14efab8fc7dd29 Mon Sep 17 00:00:00 2001 From: ammwangi Date: Mon, 8 May 2023 21:50:32 +0300 Subject: [PATCH 07/11] edit for mapper ProgrammeEntity --- .../mms.Application/Common/Mapper/AutoMapperInitializer.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs b/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs index 2385c632..152fcec0 100644 --- a/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs +++ b/backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs @@ -13,7 +13,6 @@ using FAQEntity = mms.Domain.Entities.FAQ; using mms.Application.FAQ.Command; using mms.Application.FAQ.Query; -using Programmes = mms.Domain.Entities.Programme; using Reports = mms.Domain.Entities.Report; using mms.Application.UserTasks.Query; using mms.Domain.Entities; @@ -23,6 +22,7 @@ using mms.Application.MentorManagers.Query; using mms.Application.UserTasks.Command.CreateTask; using mms.Application.Report.Command; +using mms.Application.Programme.Command; namespace mms.Application.Common.Mapper { @@ -46,7 +46,8 @@ public AutoMapperInitializer() CreateMap().ReverseMap(); CreateMap().ReverseMap(); - CreateMap().ReverseMap(); + CreateMap().ReverseMap(); + CreateMap().ReverseMap(); CreateMap().ReverseMap(); CreateMap().ReverseMap(); From 6ebc8deb1164247d72a9cda3f6057f102c81202b Mon Sep 17 00:00:00 2001 From: ammwangi Date: Tue, 9 May 2023 14:34:42 +0300 Subject: [PATCH 08/11] Migrartions for the entites Update --- .../20230509112714_ProgramUpdate.Designer.cs | 1010 +++++++++++++++++ .../20230509112714_ProgramUpdate.cs | 214 ++++ .../ApplicationContextModelSnapshot.cs | 79 +- 3 files changed, 1299 insertions(+), 4 deletions(-) create mode 100644 backend/src/mms.Infrastructure/Migrations/20230509112714_ProgramUpdate.Designer.cs create mode 100644 backend/src/mms.Infrastructure/Migrations/20230509112714_ProgramUpdate.cs diff --git a/backend/src/mms.Infrastructure/Migrations/20230509112714_ProgramUpdate.Designer.cs b/backend/src/mms.Infrastructure/Migrations/20230509112714_ProgramUpdate.Designer.cs new file mode 100644 index 00000000..701f48f6 --- /dev/null +++ b/backend/src/mms.Infrastructure/Migrations/20230509112714_ProgramUpdate.Designer.cs @@ -0,0 +1,1010 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using mms.Infrastructure.Context; + +#nullable disable + +namespace mms.Infrastructure.Migrations +{ + [DbContext(typeof(ApplicationContext))] + [Migration("20230509112714_ProgramUpdate")] + partial class ProgramUpdate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.5") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("longtext"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("ClaimType") + .HasColumnType("longtext"); + + b.Property("ClaimValue") + .HasColumnType("longtext"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("ClaimType") + .HasColumnType("longtext"); + + b.Property("ClaimValue") + .HasColumnType("longtext"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("varchar(255)"); + + b.Property("ProviderKey") + .HasColumnType("varchar(255)"); + + b.Property("ProviderDisplayName") + .HasColumnType("longtext"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("varchar(255)"); + + b.Property("RoleId") + .HasColumnType("varchar(255)"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("varchar(255)"); + + b.Property("LoginProvider") + .HasColumnType("varchar(255)"); + + b.Property("Name") + .HasColumnType("varchar(255)"); + + b.Property("Value") + .HasColumnType("longtext"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("mms.Domain.Entities.AppUser", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("About") + .HasColumnType("longtext"); + + b.Property("AccessFailedCount") + .HasColumnType("int"); + + b.Property("Bio") + .HasColumnType("longtext"); + + b.Property("City") + .HasColumnType("longtext"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("longtext"); + + b.Property("Country") + .HasColumnType("longtext"); + + b.Property("DateCreated") + .HasColumnType("datetime(6)"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("tinyint(1)"); + + b.Property("FirstName") + .HasColumnType("longtext"); + + b.Property("Github") + .HasColumnType("longtext"); + + b.Property("Headline") + .HasColumnType("longtext"); + + b.Property("Instagram") + .HasColumnType("longtext"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("LastName") + .HasColumnType("longtext"); + + b.Property("LinkedIn") + .HasColumnType("longtext"); + + b.Property("LockoutEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("LockoutEnd") + .HasColumnType("datetime(6)"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("PasswordHash") + .HasColumnType("longtext"); + + b.Property("PhoneNumber") + .HasColumnType("longtext"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("tinyint(1)"); + + b.Property("ProfileComplete") + .HasColumnType("tinyint(1)"); + + b.Property("ProfilePicture") + .HasColumnType("longtext"); + + b.Property("RefreshToken") + .HasColumnType("longtext"); + + b.Property("RefreshTokenExpiryTime") + .HasColumnType("datetime(6)"); + + b.Property("SecurityStamp") + .HasColumnType("longtext"); + + b.Property("State") + .HasColumnType("longtext"); + + b.Property("Twitter") + .HasColumnType("longtext"); + + b.Property("TwoFactorEnabled") + .HasColumnType("tinyint(1)"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("varchar(256)"); + + b.Property("UserTaskId") + .HasColumnType("varchar(255)"); + + b.Property("Website") + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.HasIndex("UserTaskId"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("mms.Domain.Entities.Certificate", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ApprovedBy") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CertificateCode") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("CreatedBy") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("IssueDate") + .HasColumnType("datetime(6)"); + + b.Property("ProgramId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Status") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("Certificates"); + }); + + modelBuilder.Entity("mms.Domain.Entities.FAQ", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Answer") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("IsGeneral") + .HasColumnType("tinyint(1)"); + + b.Property("Question") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.ToTable("FAQs"); + }); + + modelBuilder.Entity("mms.Domain.Entities.JobRole", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.ToTable("JobRoles"); + }); + + modelBuilder.Entity("mms.Domain.Entities.MentorManager", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("AppUserId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("AppUserId"); + + b.ToTable("MentorManagers"); + }); + + modelBuilder.Entity("mms.Domain.Entities.Programme", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("ArchivedBy") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("CreatedBy") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Criteria") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DateArchived") + .HasColumnType("datetime(6)"); + + b.Property("DateCompleted") + .HasColumnType("datetime(6)"); + + b.Property("DateCreated") + .HasColumnType("datetime(6)"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("MentorManagerId") + .HasColumnType("varchar(255)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ProgrammePicture") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Status") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("MentorManagerId"); + + b.ToTable("Programmes"); + }); + + modelBuilder.Entity("mms.Domain.Entities.ProgrammeApplication", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Answers") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("AppUserId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("ApprovedDeclinedBy") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("ProgrammeId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Status") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("AppUserId"); + + b.HasIndex("ProgrammeId"); + + b.ToTable("ProgrammeApplications"); + }); + + modelBuilder.Entity("mms.Domain.Entities.ProgramsMentor", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("AppUserId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("MentorManagerId") + .HasColumnType("varchar(255)"); + + b.Property("ProgramId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ProgrammeId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("AppUserId"); + + b.HasIndex("MentorManagerId"); + + b.HasIndex("ProgrammeId"); + + b.ToTable("ProgramsMentors"); + }); + + modelBuilder.Entity("mms.Domain.Entities.Report", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Achievements") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Blocker") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("CreatedBy") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DateCreated") + .HasColumnType("datetime(6)"); + + b.Property("ProgramId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ProgrammeId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Recommendations") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ReportTitle") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("TaskId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Type") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("ProgrammeId"); + + b.ToTable("Reports"); + }); + + modelBuilder.Entity("mms.Domain.Entities.Support", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("Attachment") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Body") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Title") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.ToTable("Supports"); + }); + + modelBuilder.Entity("mms.Domain.Entities.TechStack", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.ToTable("TechStacks"); + }); + + modelBuilder.Entity("mms.Domain.Entities.UserDetail", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("AppUserId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Approved") + .HasColumnType("tinyint(1)"); + + b.Property("BeenMentorBefore") + .HasColumnType("tinyint(1)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("Document") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("PreviousHeldRole") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("PreviousProgram") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ProgrammeOfInterestId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Status") + .HasColumnType("tinyint(1)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.Property("YearOfTechnicalExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("AppUserId"); + + b.ToTable("UserDetails"); + }); + + modelBuilder.Entity("mms.Domain.Entities.UserNotification", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("AllNotificationEmail") + .HasColumnType("tinyint(1)"); + + b.Property("AllNotificationInApp") + .HasColumnType("tinyint(1)"); + + b.Property("AppUserId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("ApprovalRequestEmail") + .HasColumnType("tinyint(1)"); + + b.Property("ApprovalRequestInApp") + .HasColumnType("tinyint(1)"); + + b.Property("CommentsEmail") + .HasColumnType("tinyint(1)"); + + b.Property("CommentsInApp") + .HasColumnType("tinyint(1)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("DirectMessageEmail") + .HasColumnType("tinyint(1)"); + + b.Property("DirectMessageInApp") + .HasColumnType("tinyint(1)"); + + b.Property("MentionsEmail") + .HasColumnType("tinyint(1)"); + + b.Property("MentionsInApp") + .HasColumnType("tinyint(1)"); + + b.Property("PostCommentsEmail") + .HasColumnType("tinyint(1)"); + + b.Property("PostCommentsInApp") + .HasColumnType("tinyint(1)"); + + b.Property("PostsEmail") + .HasColumnType("tinyint(1)"); + + b.Property("PostsInApp") + .HasColumnType("tinyint(1)"); + + b.Property("ProgramEmail") + .HasColumnType("tinyint(1)"); + + b.Property("ProgramInApp") + .HasColumnType("tinyint(1)"); + + b.Property("ReportsEmail") + .HasColumnType("tinyint(1)"); + + b.Property("ReportsInApp") + .HasColumnType("tinyint(1)"); + + b.Property("TaskEmail") + .HasColumnType("tinyint(1)"); + + b.Property("TaskInApp") + .HasColumnType("tinyint(1)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("AppUserId"); + + b.ToTable("UserNotifications"); + }); + + modelBuilder.Entity("mms.Domain.Entities.UserPrivacy", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("AppUserId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("ShowContactInfo") + .HasColumnType("tinyint(1)"); + + b.Property("ShowGithub") + .HasColumnType("tinyint(1)"); + + b.Property("ShowInstagram") + .HasColumnType("tinyint(1)"); + + b.Property("ShowLinkedIn") + .HasColumnType("tinyint(1)"); + + b.Property("ShowTwitter") + .HasColumnType("tinyint(1)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("AppUserId"); + + b.ToTable("UserPrivacy"); + }); + + modelBuilder.Entity("mms.Domain.Entities.UserTask", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("CreatedBy") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DateCreated") + .HasColumnType("datetime(6)"); + + b.Property("Description") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ProgramId") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ProgrammeId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("Status") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Title") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("ProgrammeId"); + + b.ToTable("UserTasks"); + }); + + 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("mms.Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("mms.Domain.Entities.AppUser", 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("mms.Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("mms.Domain.Entities.AppUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("mms.Domain.Entities.AppUser", b => + { + b.HasOne("mms.Domain.Entities.UserTask", null) + .WithMany("Managers") + .HasForeignKey("UserTaskId"); + }); + + modelBuilder.Entity("mms.Domain.Entities.MentorManager", b => + { + b.HasOne("mms.Domain.Entities.AppUser", "AppUser") + .WithMany() + .HasForeignKey("AppUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("AppUser"); + }); + + modelBuilder.Entity("mms.Domain.Entities.Programme", b => + { + b.HasOne("mms.Domain.Entities.MentorManager", null) + .WithMany("Programmes") + .HasForeignKey("MentorManagerId"); + }); + + modelBuilder.Entity("mms.Domain.Entities.ProgrammeApplication", b => + { + b.HasOne("mms.Domain.Entities.Programme", "Programme") + .WithMany("ProgrammeApplications") + .HasForeignKey("ProgrammeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Programme"); + }); + + modelBuilder.Entity("mms.Domain.Entities.ProgramsMentor", b => + { + b.HasOne("mms.Domain.Entities.AppUser", "AppUser") + .WithMany() + .HasForeignKey("AppUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("mms.Domain.Entities.MentorManager", null) + .WithMany("ProgramsMentors") + .HasForeignKey("MentorManagerId"); + + b.HasOne("mms.Domain.Entities.Programme", "Programme") + .WithMany("ProgramsMentors") + .HasForeignKey("ProgrammeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("AppUser"); + + b.Navigation("Programme"); + }); + + modelBuilder.Entity("mms.Domain.Entities.Report", b => + { + b.HasOne("mms.Domain.Entities.Programme", "Programme") + .WithMany("Reports") + .HasForeignKey("ProgrammeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Programme"); + }); + + modelBuilder.Entity("mms.Domain.Entities.UserTask", b => + { + b.HasOne("mms.Domain.Entities.Programme", "Programme") + .WithMany("UserTasks") + .HasForeignKey("ProgrammeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Programme"); + }); + + modelBuilder.Entity("mms.Domain.Entities.MentorManager", b => + { + b.Navigation("Programmes"); + + b.Navigation("ProgramsMentors"); + }); + + modelBuilder.Entity("mms.Domain.Entities.Programme", b => + { + b.Navigation("ProgrammeApplications"); + + b.Navigation("ProgramsMentors"); + + b.Navigation("Reports"); + + b.Navigation("UserTasks"); + }); + + modelBuilder.Entity("mms.Domain.Entities.UserTask", b => + { + b.Navigation("Managers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/backend/src/mms.Infrastructure/Migrations/20230509112714_ProgramUpdate.cs b/backend/src/mms.Infrastructure/Migrations/20230509112714_ProgramUpdate.cs new file mode 100644 index 00000000..4e7461ca --- /dev/null +++ b/backend/src/mms.Infrastructure/Migrations/20230509112714_ProgramUpdate.cs @@ -0,0 +1,214 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace mms.Infrastructure.Migrations +{ + /// + public partial class ProgramUpdate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Reports_Programmes_ProgrammeId", + table: "Reports"); + + migrationBuilder.DropForeignKey( + name: "FK_UserTasks_Programmes_ProgrammeId", + table: "UserTasks"); + + migrationBuilder.UpdateData( + table: "UserTasks", + keyColumn: "ProgrammeId", + keyValue: null, + column: "ProgrammeId", + value: ""); + + migrationBuilder.AlterColumn( + name: "ProgrammeId", + table: "UserTasks", + type: "varchar(255)", + nullable: false, + oldClrType: typeof(string), + oldType: "varchar(255)", + oldNullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.UpdateData( + table: "Reports", + keyColumn: "ProgrammeId", + keyValue: null, + column: "ProgrammeId", + value: ""); + + migrationBuilder.AlterColumn( + name: "ProgrammeId", + table: "Reports", + type: "varchar(255)", + nullable: false, + oldClrType: typeof(string), + oldType: "varchar(255)", + oldNullable: true) + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AddColumn( + name: "MentorManagerId", + table: "ProgramsMentors", + type: "varchar(255)", + nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AddColumn( + name: "MentorManagerId", + table: "Programmes", + type: "varchar(255)", + nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "MentorManagers", + columns: table => new + { + Id = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + AppUserId = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + CreatedAt = table.Column(type: "datetime(6)", nullable: false), + UpdatedAt = table.Column(type: "datetime(6)", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_MentorManagers", x => x.Id); + table.ForeignKey( + name: "FK_MentorManagers_AspNetUsers_AppUserId", + column: x => x.AppUserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_ProgramsMentors_MentorManagerId", + table: "ProgramsMentors", + column: "MentorManagerId"); + + migrationBuilder.CreateIndex( + name: "IX_Programmes_MentorManagerId", + table: "Programmes", + column: "MentorManagerId"); + + migrationBuilder.CreateIndex( + name: "IX_MentorManagers_AppUserId", + table: "MentorManagers", + column: "AppUserId"); + + migrationBuilder.AddForeignKey( + name: "FK_Programmes_MentorManagers_MentorManagerId", + table: "Programmes", + column: "MentorManagerId", + principalTable: "MentorManagers", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_ProgramsMentors_MentorManagers_MentorManagerId", + table: "ProgramsMentors", + column: "MentorManagerId", + principalTable: "MentorManagers", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Reports_Programmes_ProgrammeId", + table: "Reports", + column: "ProgrammeId", + principalTable: "Programmes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_UserTasks_Programmes_ProgrammeId", + table: "UserTasks", + column: "ProgrammeId", + principalTable: "Programmes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Programmes_MentorManagers_MentorManagerId", + table: "Programmes"); + + migrationBuilder.DropForeignKey( + name: "FK_ProgramsMentors_MentorManagers_MentorManagerId", + table: "ProgramsMentors"); + + migrationBuilder.DropForeignKey( + name: "FK_Reports_Programmes_ProgrammeId", + table: "Reports"); + + migrationBuilder.DropForeignKey( + name: "FK_UserTasks_Programmes_ProgrammeId", + table: "UserTasks"); + + migrationBuilder.DropTable( + name: "MentorManagers"); + + migrationBuilder.DropIndex( + name: "IX_ProgramsMentors_MentorManagerId", + table: "ProgramsMentors"); + + migrationBuilder.DropIndex( + name: "IX_Programmes_MentorManagerId", + table: "Programmes"); + + migrationBuilder.DropColumn( + name: "MentorManagerId", + table: "ProgramsMentors"); + + migrationBuilder.DropColumn( + name: "MentorManagerId", + table: "Programmes"); + + migrationBuilder.AlterColumn( + name: "ProgrammeId", + table: "UserTasks", + type: "varchar(255)", + nullable: true, + oldClrType: typeof(string), + oldType: "varchar(255)") + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AlterColumn( + name: "ProgrammeId", + table: "Reports", + type: "varchar(255)", + nullable: true, + oldClrType: typeof(string), + oldType: "varchar(255)") + .Annotation("MySql:CharSet", "utf8mb4") + .OldAnnotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AddForeignKey( + name: "FK_Reports_Programmes_ProgrammeId", + table: "Reports", + column: "ProgrammeId", + principalTable: "Programmes", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_UserTasks_Programmes_ProgrammeId", + table: "UserTasks", + column: "ProgrammeId", + principalTable: "Programmes", + principalColumn: "Id"); + } + } +} diff --git a/backend/src/mms.Infrastructure/Migrations/ApplicationContextModelSnapshot.cs b/backend/src/mms.Infrastructure/Migrations/ApplicationContextModelSnapshot.cs index 71db2b0f..eb0c437a 100644 --- a/backend/src/mms.Infrastructure/Migrations/ApplicationContextModelSnapshot.cs +++ b/backend/src/mms.Infrastructure/Migrations/ApplicationContextModelSnapshot.cs @@ -363,6 +363,28 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("JobRoles"); }); + modelBuilder.Entity("mms.Domain.Entities.MentorManager", b => + { + b.Property("Id") + .HasColumnType("varchar(255)"); + + b.Property("AppUserId") + .IsRequired() + .HasColumnType("varchar(255)"); + + b.Property("CreatedAt") + .HasColumnType("datetime(6)"); + + b.Property("UpdatedAt") + .HasColumnType("datetime(6)"); + + b.HasKey("Id"); + + b.HasIndex("AppUserId"); + + b.ToTable("MentorManagers"); + }); + modelBuilder.Entity("mms.Domain.Entities.Programme", b => { b.Property("Id") @@ -396,6 +418,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) .IsRequired() .HasColumnType("longtext"); + b.Property("MentorManagerId") + .HasColumnType("varchar(255)"); + b.Property("Name") .IsRequired() .HasColumnType("longtext"); @@ -413,6 +438,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasKey("Id"); + b.HasIndex("MentorManagerId"); + b.ToTable("Programmes"); }); @@ -468,6 +495,9 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("CreatedAt") .HasColumnType("datetime(6)"); + b.Property("MentorManagerId") + .HasColumnType("varchar(255)"); + b.Property("ProgramId") .IsRequired() .HasColumnType("longtext"); @@ -483,6 +513,8 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.HasIndex("AppUserId"); + b.HasIndex("MentorManagerId"); + b.HasIndex("ProgrammeId"); b.ToTable("ProgramsMentors"); @@ -516,6 +548,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("longtext"); b.Property("ProgrammeId") + .IsRequired() .HasColumnType("varchar(255)"); b.Property("Recommendations") @@ -793,6 +826,7 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasColumnType("longtext"); b.Property("ProgrammeId") + .IsRequired() .HasColumnType("varchar(255)"); b.Property("Status") @@ -871,6 +905,24 @@ protected override void BuildModel(ModelBuilder modelBuilder) .HasForeignKey("UserTaskId"); }); + modelBuilder.Entity("mms.Domain.Entities.MentorManager", b => + { + b.HasOne("mms.Domain.Entities.AppUser", "AppUser") + .WithMany() + .HasForeignKey("AppUserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("AppUser"); + }); + + modelBuilder.Entity("mms.Domain.Entities.Programme", b => + { + b.HasOne("mms.Domain.Entities.MentorManager", null) + .WithMany("Programmes") + .HasForeignKey("MentorManagerId"); + }); + modelBuilder.Entity("mms.Domain.Entities.ProgrammeApplication", b => { b.HasOne("mms.Domain.Entities.Programme", "Programme") @@ -890,6 +942,10 @@ protected override void BuildModel(ModelBuilder modelBuilder) .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("mms.Domain.Entities.MentorManager", null) + .WithMany("ProgramsMentors") + .HasForeignKey("MentorManagerId"); + b.HasOne("mms.Domain.Entities.Programme", "Programme") .WithMany("ProgramsMentors") .HasForeignKey("ProgrammeId") @@ -903,16 +959,31 @@ protected override void BuildModel(ModelBuilder modelBuilder) modelBuilder.Entity("mms.Domain.Entities.Report", b => { - b.HasOne("mms.Domain.Entities.Programme", null) + b.HasOne("mms.Domain.Entities.Programme", "Programme") .WithMany("Reports") - .HasForeignKey("ProgrammeId"); + .HasForeignKey("ProgrammeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Programme"); }); modelBuilder.Entity("mms.Domain.Entities.UserTask", b => { - b.HasOne("mms.Domain.Entities.Programme", null) + b.HasOne("mms.Domain.Entities.Programme", "Programme") .WithMany("UserTasks") - .HasForeignKey("ProgrammeId"); + .HasForeignKey("ProgrammeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Programme"); + }); + + modelBuilder.Entity("mms.Domain.Entities.MentorManager", b => + { + b.Navigation("Programmes"); + + b.Navigation("ProgramsMentors"); }); modelBuilder.Entity("mms.Domain.Entities.Programme", b => From 70915d3e4a759b19119448f829ff158f24394027 Mon Sep 17 00:00:00 2001 From: ammwangi Date: Tue, 9 May 2023 16:11:51 +0300 Subject: [PATCH 09/11] get tasks by month, year and week --- .../UserTasks/Query/GetMonthlyTasksCommand.cs | 14 ++++++ .../UserTasks/Query/GetMonthlyTasksHandler.cs | 42 ++++++++++++++++++ .../UserTasks/Query/GetWeeklyTasksCommand.cs | 14 ++++++ .../UserTasks/Query/GetWeeklyTasksHandler.cs | 44 +++++++++++++++++++ .../UserTasks/Query/GetYearlyTasksCommand.cs | 14 ++++++ .../UserTasks/Query/GetYearlyTasksHandler.cs | 38 ++++++++++++++++ .../mms.api/Controllers/UserTaskController.cs | 42 ++++++++++++++++++ 7 files changed, 208 insertions(+) create mode 100644 backend/src/mms.Application/UserTasks/Query/GetMonthlyTasksCommand.cs create mode 100644 backend/src/mms.Application/UserTasks/Query/GetMonthlyTasksHandler.cs create mode 100644 backend/src/mms.Application/UserTasks/Query/GetWeeklyTasksCommand.cs create mode 100644 backend/src/mms.Application/UserTasks/Query/GetWeeklyTasksHandler.cs create mode 100644 backend/src/mms.Application/UserTasks/Query/GetYearlyTasksCommand.cs create mode 100644 backend/src/mms.Application/UserTasks/Query/GetYearlyTasksHandler.cs diff --git a/backend/src/mms.Application/UserTasks/Query/GetMonthlyTasksCommand.cs b/backend/src/mms.Application/UserTasks/Query/GetMonthlyTasksCommand.cs new file mode 100644 index 00000000..a5192e74 --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Query/GetMonthlyTasksCommand.cs @@ -0,0 +1,14 @@ +using AspNetCoreHero.Results; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.UserTasks.Query +{ + public class GetMonthlyTasksCommand : IRequest>> + { + } +} diff --git a/backend/src/mms.Application/UserTasks/Query/GetMonthlyTasksHandler.cs b/backend/src/mms.Application/UserTasks/Query/GetMonthlyTasksHandler.cs new file mode 100644 index 00000000..3db38d7a --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Query/GetMonthlyTasksHandler.cs @@ -0,0 +1,42 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Infrastructure.Context; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.UserTasks.Query +{ + public class GetMonthlyTasksHandler : IRequestHandler>> + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public GetMonthlyTasksHandler(ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task>> Handle(GetMonthlyTasksCommand request, + CancellationToken cancellationToken) + { + //TODO: + //Check how status are Inserted in the database for Tasks + var usertasks = await _context.UserTasks.Where(m => m.DateCreated.Month == DateTime.UtcNow.Month).OrderByDescending(x => x.DateCreated).ToListAsync(); + if (usertasks == null) + { + return await Result>.FailAsync("No Monthly Tasks Available"); + } + + var result = _mapper.Map>(usertasks); + + return await Result>.SuccessAsync(result); + } + } +} \ No newline at end of file diff --git a/backend/src/mms.Application/UserTasks/Query/GetWeeklyTasksCommand.cs b/backend/src/mms.Application/UserTasks/Query/GetWeeklyTasksCommand.cs new file mode 100644 index 00000000..c634e4c5 --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Query/GetWeeklyTasksCommand.cs @@ -0,0 +1,14 @@ +using AspNetCoreHero.Results; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.UserTasks.Query +{ + public class GetWeeklyTasksCommand : IRequest>> + { + } +} diff --git a/backend/src/mms.Application/UserTasks/Query/GetWeeklyTasksHandler.cs b/backend/src/mms.Application/UserTasks/Query/GetWeeklyTasksHandler.cs new file mode 100644 index 00000000..23943c35 --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Query/GetWeeklyTasksHandler.cs @@ -0,0 +1,44 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Infrastructure.Context; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.UserTasks.Query +{ + public class GetWeeklyTasksHandler : IRequestHandler>> + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public GetWeeklyTasksHandler(ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task>> Handle(GetWeeklyTasksCommand request, + CancellationToken cancellationToken) + { + var startOfWeek = DateTime.Today.AddDays(-7); + var today = DateTime.Today; + var usertasks = await _context.UserTasks.Where(t => t.DateCreated >= startOfWeek && t.DateCreated <= today).OrderByDescending(x => x.DateCreated).ToListAsync(); + if (usertasks == null) + { + return await Result>.FailAsync("No Weekly Tasks Available"); + } + + var result = _mapper.Map>(usertasks); + + return await Result>.SuccessAsync(result); + } + } +} \ No newline at end of file diff --git a/backend/src/mms.Application/UserTasks/Query/GetYearlyTasksCommand.cs b/backend/src/mms.Application/UserTasks/Query/GetYearlyTasksCommand.cs new file mode 100644 index 00000000..701c8488 --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Query/GetYearlyTasksCommand.cs @@ -0,0 +1,14 @@ +using AspNetCoreHero.Results; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.UserTasks.Query +{ + public class GetYearlyTasksCommand : IRequest>> + { + } +} diff --git a/backend/src/mms.Application/UserTasks/Query/GetYearlyTasksHandler.cs b/backend/src/mms.Application/UserTasks/Query/GetYearlyTasksHandler.cs new file mode 100644 index 00000000..08bfdba3 --- /dev/null +++ b/backend/src/mms.Application/UserTasks/Query/GetYearlyTasksHandler.cs @@ -0,0 +1,38 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Infrastructure.Context; + +namespace mms.Application.UserTasks.Query +{ + public class GetYearlyTasksHandler : IRequestHandler>> + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public GetYearlyTasksHandler(ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task>> Handle(GetYearlyTasksCommand request, + CancellationToken cancellationToken) + { + //TODO: + //Check how status are Inserted in the database for Tasks + var usertasks = await _context.UserTasks.Where(y => y.DateCreated.Year == DateTime.UtcNow.Year).ToListAsync(); + if (usertasks == null) + { + return await Result>.FailAsync("No Yearly Tasks Available"); + } + + var result = _mapper.Map>(usertasks); + + return await Result>.SuccessAsync(result); + } + } +} \ No newline at end of file diff --git a/backend/src/mms.api/Controllers/UserTaskController.cs b/backend/src/mms.api/Controllers/UserTaskController.cs index 20f6b9cd..da2ed0d5 100644 --- a/backend/src/mms.api/Controllers/UserTaskController.cs +++ b/backend/src/mms.api/Controllers/UserTaskController.cs @@ -50,6 +50,48 @@ public async Task GetInProgressUserTasks() return Ok(result); } + [HttpGet("get-weekly-tasks")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetWeeklyTasks() + { + var result = await Mediator.Send(new GetWeeklyTasksCommand()); + if (!result.Succeeded) + { + return BadRequest(result); + } + + return Ok(result); + } + + [HttpGet("get-Monthly-tasks")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetMonthlyTasks() + { + var result = await Mediator.Send(new GetMonthlyTasksCommand()); + if (!result.Succeeded) + { + return BadRequest(result); + } + + return Ok(result); + } + + [HttpGet("get-yearly-tasks")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetYearlyTasks() + { + var result = await Mediator.Send(new GetYearlyTasksCommand()); + if (!result.Succeeded) + { + return BadRequest(result); + } + + return Ok(result); + } + [HttpPost("task")] public async Task CreateTask(CreateTaskCommand command) { From 5359512d0f29a00e656b163b047be486961b2851 Mon Sep 17 00:00:00 2001 From: ammwangi Date: Tue, 9 May 2023 16:24:52 +0300 Subject: [PATCH 10/11] get reports on yearly , monthly and weekly basis --- .../Report/Query/GetMonthlyReportsCommand.cs | 9 ++++ .../Query/GetMonthlyReportsCommandHandler.cs | 42 ++++++++++++++++ .../Report/Query/GetWeeklyReportsCommand.cs | 9 ++++ .../Query/GetWeeklyReportsCommandHandler.cs | 39 +++++++++++++++ .../Report/Query/GetYearlyReportsCommand.cs | 9 ++++ .../Query/GetYearlyReportsCommandHandler.cs | 36 ++++++++++++++ .../mms.api/Controllers/ReportController.cs | 48 ++++++++++++++++++- 7 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 backend/src/mms.Application/Report/Query/GetMonthlyReportsCommand.cs create mode 100644 backend/src/mms.Application/Report/Query/GetMonthlyReportsCommandHandler.cs create mode 100644 backend/src/mms.Application/Report/Query/GetWeeklyReportsCommand.cs create mode 100644 backend/src/mms.Application/Report/Query/GetWeeklyReportsCommandHandler.cs create mode 100644 backend/src/mms.Application/Report/Query/GetYearlyReportsCommand.cs create mode 100644 backend/src/mms.Application/Report/Query/GetYearlyReportsCommandHandler.cs diff --git a/backend/src/mms.Application/Report/Query/GetMonthlyReportsCommand.cs b/backend/src/mms.Application/Report/Query/GetMonthlyReportsCommand.cs new file mode 100644 index 00000000..a0085678 --- /dev/null +++ b/backend/src/mms.Application/Report/Query/GetMonthlyReportsCommand.cs @@ -0,0 +1,9 @@ +using AspNetCoreHero.Results; +using MediatR; + +namespace mms.Application.Report.Query +{ + public class GetMonthlyReportsCommand : IRequest>> + { + } +} diff --git a/backend/src/mms.Application/Report/Query/GetMonthlyReportsCommandHandler.cs b/backend/src/mms.Application/Report/Query/GetMonthlyReportsCommandHandler.cs new file mode 100644 index 00000000..1774a611 --- /dev/null +++ b/backend/src/mms.Application/Report/Query/GetMonthlyReportsCommandHandler.cs @@ -0,0 +1,42 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Infrastructure.Context; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.Report.Query +{ + public class GetMonthlyReportsCommandHandler : IRequestHandler>> + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public GetMonthlyReportsCommandHandler(ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task>> Handle(GetMonthlyReportsCommand request, + CancellationToken cancellationToken) + { + + var reports = await _context.Reports.Where(m => m.DateCreated.Month == DateTime.UtcNow.Month).OrderByDescending(x => x.DateCreated).ToListAsync(); + if (reports == null) + { + return await Result>.FailAsync("No Reports Available"); + } + + var result = _mapper.Map>(reports); + + return await Result>.SuccessAsync(result); + } + } +} \ No newline at end of file diff --git a/backend/src/mms.Application/Report/Query/GetWeeklyReportsCommand.cs b/backend/src/mms.Application/Report/Query/GetWeeklyReportsCommand.cs new file mode 100644 index 00000000..93390ed2 --- /dev/null +++ b/backend/src/mms.Application/Report/Query/GetWeeklyReportsCommand.cs @@ -0,0 +1,9 @@ +using AspNetCoreHero.Results; +using MediatR; + +namespace mms.Application.Report.Query +{ + public class GetWeeklyReportsCommand : IRequest>> + { + } +} diff --git a/backend/src/mms.Application/Report/Query/GetWeeklyReportsCommandHandler.cs b/backend/src/mms.Application/Report/Query/GetWeeklyReportsCommandHandler.cs new file mode 100644 index 00000000..f8e3cceb --- /dev/null +++ b/backend/src/mms.Application/Report/Query/GetWeeklyReportsCommandHandler.cs @@ -0,0 +1,39 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Infrastructure.Context; + +namespace mms.Application.Report.Query +{ + public class GetWeeklyReportsCommandHandler : IRequestHandler>> + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public GetWeeklyReportsCommandHandler(ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task>> Handle(GetWeeklyReportsCommand request, + CancellationToken cancellationToken) + { + var startOfWeek = DateTime.Today.AddDays(-7); + var today = DateTime.Today; + + var reports = await _context.Reports.OrderByDescending(t => t.DateCreated >= startOfWeek && t.DateCreated <= today).ToListAsync(); + if (reports == null) + { + return await Result>.FailAsync("No Reports Available"); + } + + var result = _mapper.Map>(reports); + + return await Result>.SuccessAsync(result); + } + } +} \ No newline at end of file diff --git a/backend/src/mms.Application/Report/Query/GetYearlyReportsCommand.cs b/backend/src/mms.Application/Report/Query/GetYearlyReportsCommand.cs new file mode 100644 index 00000000..857728b4 --- /dev/null +++ b/backend/src/mms.Application/Report/Query/GetYearlyReportsCommand.cs @@ -0,0 +1,9 @@ +using AspNetCoreHero.Results; +using MediatR; + +namespace mms.Application.Report.Query +{ + public class GetYearlyReportsCommand : IRequest>> + { + } +} diff --git a/backend/src/mms.Application/Report/Query/GetYearlyReportsCommandHandler.cs b/backend/src/mms.Application/Report/Query/GetYearlyReportsCommandHandler.cs new file mode 100644 index 00000000..0cf26d26 --- /dev/null +++ b/backend/src/mms.Application/Report/Query/GetYearlyReportsCommandHandler.cs @@ -0,0 +1,36 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Infrastructure.Context; + +namespace mms.Application.Report.Query +{ + public class GetYearlyReportsCommandHandler : IRequestHandler>> + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public GetYearlyReportsCommandHandler(ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task>> Handle(GetYearlyReportsCommand request, + CancellationToken cancellationToken) + { + var reports = await _context.Reports.Where(y => y.DateCreated.Year == DateTime.UtcNow.Year).OrderByDescending(x => x.DateCreated).ToListAsync(); + if (reports == null) + { + return await Result>.FailAsync("No Reports Available"); + } + + var result = _mapper.Map>(reports); + + return await Result>.SuccessAsync(result); + } + } +} \ No newline at end of file diff --git a/backend/src/mms.api/Controllers/ReportController.cs b/backend/src/mms.api/Controllers/ReportController.cs index 4377c3ab..866be2d0 100644 --- a/backend/src/mms.api/Controllers/ReportController.cs +++ b/backend/src/mms.api/Controllers/ReportController.cs @@ -1,5 +1,4 @@ using Microsoft.AspNetCore.Mvc; -using mms.Application.Programme.Query; using mms.Application.Report.Command; using mms.Application.Report.Query; @@ -19,6 +18,53 @@ public async Task GetReports() return Ok(result); } + + + [HttpGet("get-weekly-reports")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetWeeklyReports() + { + var result = await Mediator.Send(new GetWeeklyReportsCommand()); + if (!result.Succeeded) + { + return BadRequest(result); + } + + return Ok(result); + } + + [HttpGet("get-Monthly-reports")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetMonthlyReports() + { + var result = await Mediator.Send(new GetMonthlyReportsCommand()); + if (!result.Succeeded) + { + return BadRequest(result); + } + + return Ok(result); + } + + [HttpGet("get-yearly-reports")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetYearlyReports() + { + var result = await Mediator.Send(new GetYearlyReportsCommand()); + if (!result.Succeeded) + { + return BadRequest(result); + } + + return Ok(result); + } + + + + [HttpPost("report")] public async Task CreateTask(CreateReportCommand command) { From 5e6c40f6a1509fb37fbd168bf2db810630cb168d Mon Sep 17 00:00:00 2001 From: ammwangi Date: Tue, 9 May 2023 16:28:57 +0300 Subject: [PATCH 11/11] get active programs request --- .../Query/GetActiveProgrammesCommand.cs | 14 +++++++ .../GetActiveProgrammesCommandHandler.cs | 42 +++++++++++++++++++ .../Query/GetMonthlyReportsCommandHandler.cs | 2 +- .../Query/GetWeeklyReportsCommandHandler.cs | 2 +- .../Query/GetYearlyReportsCommandHandler.cs | 2 +- .../Controllers/ProgrammeController.cs | 12 ++++++ 6 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 backend/src/mms.Application/Programme/Query/GetActiveProgrammesCommand.cs create mode 100644 backend/src/mms.Application/Programme/Query/GetActiveProgrammesCommandHandler.cs diff --git a/backend/src/mms.Application/Programme/Query/GetActiveProgrammesCommand.cs b/backend/src/mms.Application/Programme/Query/GetActiveProgrammesCommand.cs new file mode 100644 index 00000000..35ee289f --- /dev/null +++ b/backend/src/mms.Application/Programme/Query/GetActiveProgrammesCommand.cs @@ -0,0 +1,14 @@ +using AspNetCoreHero.Results; +using MediatR; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.Programme.Query +{ + public class GetActiveProgrammesCommand : IRequest>> + { + } +} diff --git a/backend/src/mms.Application/Programme/Query/GetActiveProgrammesCommandHandler.cs b/backend/src/mms.Application/Programme/Query/GetActiveProgrammesCommandHandler.cs new file mode 100644 index 00000000..4dfc5593 --- /dev/null +++ b/backend/src/mms.Application/Programme/Query/GetActiveProgrammesCommandHandler.cs @@ -0,0 +1,42 @@ +using AspNetCoreHero.Results; +using AutoMapper; +using MediatR; +using Microsoft.EntityFrameworkCore; +using mms.Infrastructure.Context; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace mms.Application.Programme.Query +{ + public class GetActiveProgrammesCommandHandler : IRequestHandler>> + { + private readonly ApplicationContext _context; + private readonly IMapper _mapper; + + public GetActiveProgrammesCommandHandler(ApplicationContext context, + IMapper mapper) + { + _context = context; + _mapper = mapper; + } + + public async Task>> Handle(GetActiveProgrammesCommand request, + CancellationToken cancellationToken) + { + var programmes = await _context.Programmes.Where(x => x.Status == "Active").OrderByDescending(x => x.DateCreated).ToListAsync(); + if (programmes == null) + { + return await Result>.FailAsync("No Active Programmes Available"); + } + + var result = _mapper.Map>(programmes); + + return await Result>.SuccessAsync(result); + } + } +} + diff --git a/backend/src/mms.Application/Report/Query/GetMonthlyReportsCommandHandler.cs b/backend/src/mms.Application/Report/Query/GetMonthlyReportsCommandHandler.cs index 1774a611..7ed6b81f 100644 --- a/backend/src/mms.Application/Report/Query/GetMonthlyReportsCommandHandler.cs +++ b/backend/src/mms.Application/Report/Query/GetMonthlyReportsCommandHandler.cs @@ -31,7 +31,7 @@ public async Task>> Handle(GetMonthlyReportsCom var reports = await _context.Reports.Where(m => m.DateCreated.Month == DateTime.UtcNow.Month).OrderByDescending(x => x.DateCreated).ToListAsync(); if (reports == null) { - return await Result>.FailAsync("No Reports Available"); + return await Result>.FailAsync("No Monthly Reports Available"); } var result = _mapper.Map>(reports); diff --git a/backend/src/mms.Application/Report/Query/GetWeeklyReportsCommandHandler.cs b/backend/src/mms.Application/Report/Query/GetWeeklyReportsCommandHandler.cs index f8e3cceb..19181327 100644 --- a/backend/src/mms.Application/Report/Query/GetWeeklyReportsCommandHandler.cs +++ b/backend/src/mms.Application/Report/Query/GetWeeklyReportsCommandHandler.cs @@ -28,7 +28,7 @@ public async Task>> Handle(GetWeeklyReportsComm var reports = await _context.Reports.OrderByDescending(t => t.DateCreated >= startOfWeek && t.DateCreated <= today).ToListAsync(); if (reports == null) { - return await Result>.FailAsync("No Reports Available"); + return await Result>.FailAsync("No weekly Reports Available"); } var result = _mapper.Map>(reports); diff --git a/backend/src/mms.Application/Report/Query/GetYearlyReportsCommandHandler.cs b/backend/src/mms.Application/Report/Query/GetYearlyReportsCommandHandler.cs index 0cf26d26..484920e4 100644 --- a/backend/src/mms.Application/Report/Query/GetYearlyReportsCommandHandler.cs +++ b/backend/src/mms.Application/Report/Query/GetYearlyReportsCommandHandler.cs @@ -25,7 +25,7 @@ public async Task>> Handle(GetYearlyReportsComm var reports = await _context.Reports.Where(y => y.DateCreated.Year == DateTime.UtcNow.Year).OrderByDescending(x => x.DateCreated).ToListAsync(); if (reports == null) { - return await Result>.FailAsync("No Reports Available"); + return await Result>.FailAsync("No Yearly Reports Available"); } var result = _mapper.Map>(reports); diff --git a/backend/src/mms.api/Controllers/ProgrammeController.cs b/backend/src/mms.api/Controllers/ProgrammeController.cs index 27a3bcc3..cb3ea77c 100644 --- a/backend/src/mms.api/Controllers/ProgrammeController.cs +++ b/backend/src/mms.api/Controllers/ProgrammeController.cs @@ -19,6 +19,18 @@ public async Task GetProgrammes() return Ok(result); } + [HttpGet("active-programme")] + public async Task GetActiveProgrammes() + { + var result = await Mediator.Send(new GetActiveProgrammesCommand()); + if (result.Succeeded == false) + { + return BadRequest(result); + } + + return Ok(result); + } + [HttpPost("programme")] public async Task CreateTask(CreateProgrammeCommand command) {