public async Task <IActionResult> UpdateArtist( [FromRoute] string id, [FromBody] ArtistMessage artistMessage) { var artist = await _artistRepository.CreateOrUpdateArtist(artistMessage, id); return(AcceptedAtAction(nameof(GetArtist), new { id }, artist)); }
public static ArtistModel ToModel(ArtistMessage artist) { if (artist == null) { return(null); } return(new ArtistModel() { Id = new Guid(artist.Id), Name = artist.Name, UrlPicture = artist.UrlPicture, Albums = artist.Albums.Select(a => AlbumGrpcConverter.ToModel(a)).ToList() }); }
public async Task <Artist> CreateOrUpdateArtist(ArtistMessage artistMessage, string id = default) { var artistFromUser = _mapper.Map <Artist>(artistMessage); var value = id == default ? await _faunaClient.Query( Create( Collection(Collection), Obj("data", Encoder.Encode(artistFromUser)))) : await _faunaClient.Query( Replace( Ref(Collection(Collection), id), Obj("data", Encoder.Encode(artistFromUser)))); return(DecodeArtist(value)); }
public static ArtistMessage ToMessage(ArtistDTO artist) { if (artist == null) { return(null); } var art = new ArtistMessage() { Id = artist.Id.ToString(), Name = artist.Name, UrlPicture = artist.UrlPicture }; art.Albums.AddRange(artist.Albums.Select(a => AlbumGrpcConverter.ToMessage(a)).ToList()); return(art); }
public async Task <IActionResult> AddArtist(ArtistMessage artistMessage) { var artist = await _artistRepository.CreateOrUpdateArtist(artistMessage); return(CreatedAtAction(nameof(GetArtist), new { id = artist.Id }, artist)); }