Skip to content

Commit

Permalink
Merge pull request #19 from SoftTeam-Emergentes/hotfix-arte-event
Browse files Browse the repository at this point in the history
Hotfix arte event
  • Loading branch information
FranchescoSoto authored Nov 21, 2023
2 parents 9d8a9e1 + 736cc7f commit 3a166c3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using PERUSTARS.ArtEventManagement.Domain.Model.Commads;
using PERUSTARS.ArtEventManagement.Domain.Model.Repositories;
using PERUSTARS.ArtEventManagement.Domain.Model.ValueObjects;
using PERUSTARS.ProfileManagement.Domain.Model.Aggregates;
using PERUSTARS.ProfileManagement.Domain.Repositories;
using PERUSTARS.Shared.Domain.Repositories;

namespace PERUSTARS.ArtEventManagement.Application.ArtEvents.Commands
Expand All @@ -13,30 +15,32 @@ public class RegisterArtEventCommandHandler : IRequestHandler<RegisterArtEventCo
{
private readonly IArtEventRepository _artEventRepository;
private readonly IUnitOfWork _unitOfWork;
public RegisterArtEventCommandHandler(IArtEventRepository artEventRepository, IUnitOfWork unitOfWork)
private readonly IArtistRepository _artistRepository;
public RegisterArtEventCommandHandler(IArtEventRepository artEventRepository, IUnitOfWork unitOfWork,IArtistRepository artist)
{
_artEventRepository = artEventRepository;
_unitOfWork = unitOfWork;
_artistRepository = artist;
}

public async Task<string> Handle(RegisterArtEventCommand request, CancellationToken cancellationToken)
{
//Primero se debe validar si existe el artista con el Id dado

Artist artist=await _artistRepository.GetArtistByIdAsync(request.ArtistId);
//"return No existe el Artista con el Id dado"
//-----------------------------------
if(artist==null) {
return "This artist doesn't exist!!";
}

var artEvent = new ArtEvent(
id: 0,
title: request.Title,
description: request.Description,
startDateTime: request.StartDateTime,
Location: request.Location,
isOnline: request.IsOnline,
artistId: request.ArtistId,
currentStatus: ArtEventStatus.REGISTERED,
Participants:null,
Artist:null,
collected:false
Artist:artist
);
await _artEventRepository.AddAsync(artEvent);
await _unitOfWork.CompleteAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public RegisterParticipantToArtEventCommandHandler(IParticipantRepository partic
}
public async Task<string> Handle(RegisterParticipantToArtEventCommand request, CancellationToken cancellationToken)
{
ArtEvent artEvent = _artEventRepository.FindByIdAsync(request.artEventId).Result;
Hobbyist hobbyist = _hobbyistRepository.FindByIdAsync(request.hobbyistId).Result;
ArtEvent artEvent = await _artEventRepository.FindByIdAsync(request.artEventId);
Hobbyist hobbyist = await _hobbyistRepository.FindByIdAsync(request.hobbyistId);
Domain.Model.Aggregates.Participant participant = new Domain.Model.Aggregates.Participant(
id: 0,
userName: "A",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace PERUSTARS.ArtEventManagement.Domain.Model.Aggregates
public class ArtEvent
{

public long? Id { get; set; }
public long Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public DateTime? StartDateTime { get; set; }
Expand All @@ -18,10 +18,26 @@ public class ArtEvent
public Artist Artist { get; set; }
public ArtEventStatus? CurrentStatus { get; set; }
public IEnumerable<Participant> Participants { get; set; }
public bool Collected { get; set; }
public bool Collected { get; set; }=false;

public ArtEvent() { }
public ArtEvent(long? id,
public ArtEvent(string title,
string description,
DateTime? startDateTime,
Location Location, bool? isOnline,
long? artistId,
Artist Artist) {
Title = title;
Description = description;
StartDateTime = startDateTime;
this.Location = Location;
IsOnline = isOnline;
ArtistId = artistId;
this.Artist = Artist;
this.CurrentStatus = ArtEventStatus.REGISTERED;
this.Participants= new List<Participant>();
}
public ArtEvent(long id,
string title,
string description,
DateTime? startDateTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Participant(long id, string userName, DateTime registerDateTime, DateTime
ArtEventId = artEventId;
Hobyst = hobbyist;
ArtEvent = artEvent;
Collected = collected;
Collected = false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public async Task<IActionResult> getByArtist(int id) {
IEnumerable<ArtEvent> events= _artEventQueryService.getArtEventByArtistId(id);
return Ok(events);
}
[HttpPost("art-events/{id}/participant")]
[HttpPost("art-events/participant")]
public async Task<IActionResult> createParticipant([FromBody] RegisterParticipantToArtEventCommand registerParticipantToArtEvent) {
string response= await _artEventCommandService.registerParticipantToArtEvent(registerParticipantToArtEvent);
return Ok(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public ParticipantsController(IMapper mapper, IParticipantQueryService participa
_participantCommandService=participantCommandService;
}

[HttpGet]
[HttpGet("participants")]
public async Task<IActionResult> getParticipants()
{
IEnumerable<Participant> participants = _participantQueryService.GetParticipants();
Expand Down

0 comments on commit 3a166c3

Please sign in to comment.