Skip to content

Commit

Permalink
Merge pull request #16 from SoftTeam-Emergentes/feat/art-event-manage…
Browse files Browse the repository at this point in the history
…ment2

feat: add delete features
  • Loading branch information
FranchescoSoto authored Nov 13, 2023
2 parents 13a8e38 + 72cc50c commit 18ecebe
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using MediatR;
using PERUSTARS.AtEventManagement.Domain.Model.Aggregates;
using PERUSTARS.AtEventManagement.Domain.Model.Commads;
using PERUSTARS.AtEventManagement.Domain.Model.Repositories;
using PERUSTARS.Shared.Domain.Repositories;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace PERUSTARS.AtEventManagement.Application.Participant.Command
{
public class DeleteParticipantCommandHandler:IRequestHandler<DeleteParticipantCommand,string>
{
private readonly IParticipantRepository _participantRepository;
private readonly IUnitOfWork _unitOfWork;
public DeleteParticipantCommandHandler(IParticipantRepository participantRepository, IUnitOfWork unitOfWork)
{
_participantRepository = participantRepository;
_unitOfWork = unitOfWork;
}

public async Task<string> Handle(DeleteParticipantCommand request, CancellationToken cancellationToken)
{
try
{
PERUSTARS.AtEventManagement.Domain.Model.Aggregates.Participant p = _participantRepository.FindByIdAsync(request.id).Result;
if (p != null)
{
_participantRepository.Remove(p);
await _unitOfWork.CompleteAsync();
return "Participant deleted";
}
else {
return "Participant with the given Id doesn't exist";
}
}
catch (Exception e) {
throw new ApplicationException($"An error occurred while deleting the participant: {e.Message}");
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using MediatR;
using PERUSTARS.AtEventManagement.Domain.Model.Commads;
using PERUSTARS.AtEventManagement.Domain.Services.Participant;
using System.Threading.Tasks;

namespace PERUSTARS.AtEventManagement.Application.Participant.Command.Service
{
public class ParticipantCommandService:IParticipantCommandService
{
private readonly IMediator _mediator;
public ParticipantCommandService(IMediator mediator)
{
_mediator = mediator;
}

public async Task<string> deleteParticipant(DeleteParticipantCommand deleteParticipantCommand)
{
return await _mediator.Send(deleteParticipantCommand);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using MediatR;
using PERUSTARS.AtEventManagement.Domain.Model.Aggregates;
using PERUSTARS.AtEventManagement.Domain.Model.Commads;
using PERUSTARS.AtEventManagement.Domain.Model.Repositories;
using PERUSTARS.Shared.Domain.Repositories;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace PERUSTARS.AtEventManagement.Application.artevents.commands
{
public class DeleteArtEventCommandHandler : IRequestHandler<DeleteArtEventCommand, string>
{
private readonly IArtEventRepository _artEventRepository;
private readonly IUnitOfWork _unitOfWork;
public DeleteArtEventCommandHandler(IArtEventRepository artEventRepository, IUnitOfWork unitOfWork)
{
_artEventRepository = artEventRepository;
_unitOfWork = unitOfWork;
}

public async Task<string> Handle(DeleteArtEventCommand request, CancellationToken cancellationToken)
{
try
{
ArtEvent artEvent= _artEventRepository.FindByIdAsync(request.id).Result;
if (artEvent != null) {
_artEventRepository.Remove(artEvent);
await _unitOfWork.CompleteAsync();

}
}
catch(Exception e) {
throw new ApplicationException($"An error occurred while deleting the art event: {e.Message}");

}
return "Art event deleted";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using PERUSTARS.Shared.Domain.Repositories;
using System.Threading;
using System.Threading.Tasks;
using System;

namespace PERUSTARS.AtEventManagement.Application.artevents.commands
{
Expand Down Expand Up @@ -35,7 +36,7 @@ public async Task<string> Handle(RegisterParticipantToArtEventCommand request, C
id: 0,
userName: "A",
registerDateTime: new System.DateTime(),
checkInDateTime: null,
checkInDateTime: DateTime.UtcNow,
hobbyistId: request.hobbyistId,
artEventId: request.artEventId,
hobbyist: hobbyist,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,9 @@ public async Task<string> startArtEventCommand(StartArtEventCommand startArtEven
{
return await _mediator.Send(startArtEventCommand);
}

public async Task<string> deleteArtEvent(DeleteArtEventCommand deleteArtEventCommand) {
return await _mediator.Send(deleteArtEventCommand);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public Participant(long id, string userName, DateTime registerDateTime, DateTime
UserName = userName;
RegisterDateTime = registerDateTime;
CheckInDateTime = checkInDateTime;
ParticipantRegistrationDateTime = DateTime.UtcNow;
HobbyistId = hobbyistId;
ArtEventId = artEventId;
Hobyst = hobbyist;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using MediatR;

namespace PERUSTARS.AtEventManagement.Domain.Model.Commads
{
public class DeleteArtEventCommand:IRequest<string>
{
public int id { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using MediatR;

namespace PERUSTARS.AtEventManagement.Domain.Model.Commads
{
public class DeleteParticipantCommand:IRequest<string>
{
public int id { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public interface IArtEventCommandService
Task<string> finishArtEvent(FinishArtEventCommand finishArtEventCommand);
Task<string> rescheduleArtEvent(RescheduleArtEventCommand rescheduleArtEventCommand);
Task<string> startArtEventCommand(StartArtEventCommand startArtEventCommand);
Task<string> deleteArtEvent(DeleteArtEventCommand deleteArtEventCommand);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using PERUSTARS.AtEventManagement.Domain.Model.Commads;
using System.Threading.Tasks;

namespace PERUSTARS.AtEventManagement.Domain.Services.Participant
{
public interface IParticipantCommandService
{
Task<string> deleteParticipant(DeleteParticipantCommand deleteParticipantCommand);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,14 @@ public async Task<IActionResult> createParticipant([FromBody] RegisterParticipan
string response= await _artEventCommandService.registerParticipantToArtEvent(registerParticipantToArtEvent);
return Ok(response);
}

[HttpDelete("id")]
public async Task<IActionResult> deleteArtEvent(int id) {
DeleteArtEventCommand deleteArtEventCommand = new DeleteArtEventCommand();
deleteArtEventCommand.id=id;
string response = await _artEventCommandService.deleteArtEvent(deleteArtEventCommand);
return Ok(response);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata;
using PERUSTARS.AtEventManagement.Domain.Model.Aggregates;
using PERUSTARS.AtEventManagement.Domain.Model.Commads;
using PERUSTARS.AtEventManagement.Domain.Services.Participant;
using System.Collections;
using System.Collections.Generic;
Expand All @@ -14,10 +15,12 @@ public class ParticipantController : ControllerBase
{
private readonly IMapper _mapper;
private readonly IParticipantQueryService _participantQueryService;
public ParticipantController(IMapper mapper, IParticipantQueryService participantQueryService)
private readonly IParticipantCommandService _participantCommandService;
public ParticipantController(IMapper mapper, IParticipantQueryService participantQueryService, IParticipantCommandService participantCommandService)
{
_mapper = mapper;
_participantQueryService = participantQueryService;
_participantCommandService=participantCommandService;
}

[HttpGet]
Expand All @@ -27,17 +30,25 @@ public async Task<IActionResult> getParticipants()
return Ok(participants);
}

[HttpGet("/hobbyist/{id}")]
[HttpGet("hobbyist/{id}")]
public async Task<IActionResult> getParticipantsByHobbyistId(int id)
{
IEnumerable<Participant> participants = _participantQueryService.getParticipantByHobbyistId(id);
return Ok(participants);
}
[HttpGet("/artevent/{id}")]
[HttpGet("artevent/{id}")]
public async Task<IActionResult> getParticipantsByArtEventId(int id)
{
IEnumerable<Participant> participants = _participantQueryService.getParticipantByEventId(id);
return Ok(participants);
}

[HttpDelete("{id}")]
public async Task<IActionResult> deleteParticipant(int id) {
DeleteParticipantCommand d = new DeleteParticipantCommand();
d.id = id;
string response = _participantCommandService.deleteParticipant(d).Result;
return Ok(response);
}
}
}
4 changes: 3 additions & 1 deletion PERUSTARS/PERUSTARS/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
using PERUSTARS.DataAnalytics.Domain.Services;
using PERUSTARS.DataAnalytics.Application.Commands.Services;
using Microsoft.Extensions.Logging;
using PERUSTARS.AtEventManagement.Application.Participant.Command.Service;

using PERUSTARS.DataAnalytics.Application.Jobs;
using PERUSTARS.DataAnalytics.Infrastructure.FeignClients;

Expand Down Expand Up @@ -127,7 +129,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddScoped<IArtEventCommandService, ArtEventService>();
services.AddScoped<IArtEventQueryService, ArtEventQueryService>();
services.AddScoped<IParticipantQueryService, ParticipantQueryService>();

services.AddScoped<IParticipantCommandService, ParticipantCommandService>();

services.AddScoped<IArtworkCommandService, ArtworkCommandService>();
services.AddScoped<IArtworkRecommendationCommandService, ArtworkRecommendationCommandService>();
Expand Down

0 comments on commit 18ecebe

Please sign in to comment.