Skip to content

Commit

Permalink
Merge pull request #147 from machariamwangi/feature/backend-dashboard…
Browse files Browse the repository at this point in the history
…-admin-app

Feature/backend dashboard admin app
  • Loading branch information
Honeyloveet authored May 10, 2023
2 parents c397e64 + 5e6c40f commit 206f385
Show file tree
Hide file tree
Showing 60 changed files with 2,847 additions and 8 deletions.
27 changes: 25 additions & 2 deletions backend/src/mms.Application/Common/Mapper/AutoMapperInitializer.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,6 +13,16 @@
using FAQEntity = mms.Domain.Entities.FAQ;
using mms.Application.FAQ.Command;
using mms.Application.FAQ.Query;
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;
using mms.Application.Mentors.Query;
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
{
Expand All @@ -33,6 +42,20 @@ public AutoMapperInitializer()

CreateMap<AppUserEntity, GetProfileByIdResponse>().ReverseMap();

CreateMap<UserTask, GetUserTasksResponse>().ReverseMap();
CreateMap<UserTask, CreateTaskCommand>().ReverseMap();
CreateMap<UserTask, PutUserTaskCommand>().ReverseMap();

CreateMap<ProgrammeEntity, GetProgrammeResponse>().ReverseMap();
CreateMap<ProgrammeEntity, CreateProgrammeCommand>().ReverseMap();

CreateMap<Reports, GetReportsResponse>().ReverseMap();
CreateMap<Reports, CreateReportCommand>().ReverseMap();
CreateMap<Reports, PutReportCommand>().ReverseMap();

CreateMap<ProgramsMentor, GetMentorsResponse>().ReverseMap();
CreateMap<MentorManager, GetMentorManagersResponse>().ReverseMap();

CreateMap<FAQEntity, PostFAQCommand>().ReverseMap();
CreateMap<FAQEntity, PutFAQCommand>().ReverseMap();
CreateMap<FAQEntity, GetFAQsResponse>().ReverseMap();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using AspNetCoreHero.Results;
using MediatR;

namespace mms.Application.MentorManagers.Query
{
public class GetMentorManagersCommand : IRequest<IResult<List<GetMentorManagersResponse>>>
{
}
}
Original file line number Diff line number Diff line change
@@ -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<GetMentorManagersCommand,
IResult<List<GetMentorManagersResponse>>>
{
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<IResult<List<GetMentorManagersResponse>>> Handle(GetMentorManagersCommand request,
CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(_currentUserService.AppUserId))
{
return await Result<List<GetMentorManagersResponse>>.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<List<GetMentorManagersResponse>>.FailAsync("No Mentor Managers Available");
}

var result = _mapper.Map<List<GetMentorManagersResponse>>(mentors);

return await Result<List<GetMentorManagersResponse>>.SuccessAsync(result);
}
}
}
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using AspNetCoreHero.Results;
using MediatR;

namespace mms.Application.Mentors.Query
{
public class GetMentorsCommand : IRequest<IResult<List<GetMentorsResponse>>>
{
}
}
Original file line number Diff line number Diff line change
@@ -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<GetMentorsCommand,
IResult<List<GetMentorsResponse>>>
{
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<IResult<List<GetMentorsResponse>>> Handle(GetMentorsCommand request,
CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(_currentUserService.AppUserId))
{
return await Result<List<GetMentorsResponse>>.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<List<GetMentorsResponse>>.FailAsync("No Mentors Available");
}

var result = _mapper.Map<List<GetMentorsResponse>>(mentors);

return await Result<List<GetMentorsResponse>>.SuccessAsync(result);
}
}
}
18 changes: 18 additions & 0 deletions backend/src/mms.Application/Mentors/Query/GetMentorsResponse.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -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<IResult>
{
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<UserTask> 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<mms.Domain.Entities.Report> Reports { get; set; }
public IList<ProgramsMentor> ProgramsMentors { get; set; }
public IList<ProgrammeApplication> ProgrammeApplications { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -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<CreateProgrammeCommand, IResult>
{
private readonly ApplicationContext _context;
private readonly IMapper _mapper;

public CreateProgrammeCommandHandler(ApplicationContext context,
IMapper mapper)
{
_context = context;
_mapper = mapper;
}

public async Task<IResult> Handle(CreateProgrammeCommand request, CancellationToken cancellationToken)
{
var programme = _mapper.Map<Domain.Entities.Programme>(request);

programme.Id = Guid.NewGuid().ToString();
programme.CreatedAt = DateTime.Now;
await _context.Programmes.AddAsync(programme);
await _context.SaveChangesAsync(cancellationToken);
return await Result.SuccessAsync();
}
}
}
Original file line number Diff line number Diff line change
@@ -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<IResult<List<GetProgrammeResponse>>>
{
}
}
Original file line number Diff line number Diff line change
@@ -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<GetActiveProgrammesCommand,
IResult<List<GetProgrammeResponse>>>
{
private readonly ApplicationContext _context;
private readonly IMapper _mapper;

public GetActiveProgrammesCommandHandler(ApplicationContext context,
IMapper mapper)
{
_context = context;
_mapper = mapper;
}

public async Task<IResult<List<GetProgrammeResponse>>> 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<List<GetProgrammeResponse>>.FailAsync("No Active Programmes Available");
}

var result = _mapper.Map<List<GetProgrammeResponse>>(programmes);

return await Result<List<GetProgrammeResponse>>.SuccessAsync(result);
}
}
}

Original file line number Diff line number Diff line change
@@ -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; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using AspNetCoreHero.Results;
using MediatR;

namespace mms.Application.Programme.Query
{
public class GetProgrammesCommand : IRequest<IResult<List<GetProgrammeResponse>>>
{
}
}
Original file line number Diff line number Diff line change
@@ -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<GetProgrammesCommand,
IResult<List<GetProgrammeResponse>>>
{
private readonly ApplicationContext _context;
private readonly IMapper _mapper;

public GetProgrammesCommandHandler( ApplicationContext context,
IMapper mapper)
{
_context = context;
_mapper = mapper;
}

public async Task<IResult<List<GetProgrammeResponse>>> Handle(GetProgrammesCommand request,
CancellationToken cancellationToken)
{
var programmes = await _context.Programmes.OrderByDescending(x => x.DateCreated).ToListAsync();
if (programmes == null)
{
return await Result<List<GetProgrammeResponse>>.FailAsync("No Programme Available");
}

var result = _mapper.Map<List<GetProgrammeResponse>>(programmes);

return await Result<List<GetProgrammeResponse>>.SuccessAsync(result);
}
}
}
Loading

0 comments on commit 206f385

Please sign in to comment.