diff --git a/src/main/java/pi/procurarteapi/ProcurarteApiApplication.java b/src/main/java/pi/procurarteapi/ProcurarteApiApplication.java index 685a3dc..78677fb 100644 --- a/src/main/java/pi/procurarteapi/ProcurarteApiApplication.java +++ b/src/main/java/pi/procurarteapi/ProcurarteApiApplication.java @@ -14,5 +14,4 @@ public class ProcurarteApiApplication { public static void main(String[] args) { SpringApplication.run(ProcurarteApiApplication.class, args); } - } diff --git a/src/main/java/pi/procurarteapi/api/controllers/MusicianController.java b/src/main/java/pi/procurarteapi/api/controllers/MusicianController.java index 8373143..51ff947 100644 --- a/src/main/java/pi/procurarteapi/api/controllers/MusicianController.java +++ b/src/main/java/pi/procurarteapi/api/controllers/MusicianController.java @@ -7,6 +7,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -15,6 +16,9 @@ import pi.procurarteapi.app.musician.dtos.ListMusician.ListMusicianResponseDto; import pi.procurarteapi.app.musician.dtos.ListMusicianImages.ListMusicianImagesRequestDto; import pi.procurarteapi.app.musician.dtos.ListMusicianImages.ListMusicianImagesResponseDto; +import pi.procurarteapi.app.musician.dtos.PostImagesPortifolio.ImagesRequestDto; +import pi.procurarteapi.app.musician.dtos.PostImagesPortifolio.PostImagesPortifolioRequestDto; +import pi.procurarteapi.app.musician.dtos.PostImagesPortifolio.PostImagesPortifolioResponseDto; import pi.procurarteapi.app.musician.dtos.ShowMusician.ShowMusicianRequestDto; import pi.procurarteapi.app.musician.dtos.ShowMusician.ShowMusicianResponseDto; import pi.procurarteapi.app.musician.dtos.ShowMusicianPortfolio.ShowMusicianPortfolioRequestDto; @@ -27,11 +31,12 @@ import pi.procurarteapi.app.musician.dtos.UpdateMusicianMusicStyles.UpdateMusicStyleListRequestDto; import pi.procurarteapi.app.musician.dtos.UpdateMusicianMusicStyles.UpdateMusicianMusicStylesRequestDto; import pi.procurarteapi.app.musician.dtos.UpdateMusicianMusicStyles.UpdateMusicianMusicStylesResponseDto; -import pi.procurarteapi.app.musician.dtos.UpdatePortfolio.UpdatePortfolioRequestDto; import pi.procurarteapi.app.musician.dtos.UpdatePortfolio.PortfolioRequestDto; +import pi.procurarteapi.app.musician.dtos.UpdatePortfolio.UpdatePortfolioRequestDto; import pi.procurarteapi.app.musician.dtos.UpdatePortfolio.UpdatePortfolioResponseDto; import pi.procurarteapi.app.musician.services.ListMusicianImagesService; import pi.procurarteapi.app.musician.services.ListMusicianService; +import pi.procurarteapi.app.musician.services.PostMusicianImagePortifolioService; import pi.procurarteapi.app.musician.services.ShowMusicianPortfolioService; import pi.procurarteapi.app.musician.services.ShowMusicianService; import pi.procurarteapi.app.musician.services.ShowWhatsappLinkService; @@ -69,6 +74,9 @@ public class MusicianController { @Autowired private UpdateMusicianMusicStylesServices updateMusicianMusicStylesServices; + @Autowired + private PostMusicianImagePortifolioService postMusicianImagePortifolioService; + @GetMapping public ResponseEntity list() throws Exception { try { @@ -95,6 +103,17 @@ public ResponseEntity show(@PathVariable String id) throws Exception { } } + @PostMapping("{id}/images") + public ResponseEntity postImages(@PathVariable String id,@RequestBody ImagesRequestDto images) throws Exception { + try { + + PostImagesPortifolioResponseDto response = postMusicianImagePortifolioService.execute(new PostImagesPortifolioRequestDto(id, images)); + return ResponseEntity.status(HttpStatus.OK).body(response); + }catch(Exception e){ + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage()); + } + } + @GetMapping("{id}/images") public ResponseEntity listImages(@PathVariable String id) throws Exception { try { diff --git a/src/main/java/pi/procurarteapi/app/musician/dtos/PostImagesPortifolio/ImagesRequestDto.java b/src/main/java/pi/procurarteapi/app/musician/dtos/PostImagesPortifolio/ImagesRequestDto.java new file mode 100644 index 0000000..6c3f3f1 --- /dev/null +++ b/src/main/java/pi/procurarteapi/app/musician/dtos/PostImagesPortifolio/ImagesRequestDto.java @@ -0,0 +1,16 @@ +package pi.procurarteapi.app.musician.dtos.PostImagesPortifolio; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Setter +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class ImagesRequestDto { + private List Images; +} diff --git a/src/main/java/pi/procurarteapi/app/musician/dtos/PostImagesPortifolio/PostImagesPortifolioRequestDto.java b/src/main/java/pi/procurarteapi/app/musician/dtos/PostImagesPortifolio/PostImagesPortifolioRequestDto.java new file mode 100644 index 0000000..e77ec40 --- /dev/null +++ b/src/main/java/pi/procurarteapi/app/musician/dtos/PostImagesPortifolio/PostImagesPortifolioRequestDto.java @@ -0,0 +1,15 @@ +package pi.procurarteapi.app.musician.dtos.PostImagesPortifolio; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Setter +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class PostImagesPortifolioRequestDto { + private String id; + private ImagesRequestDto Images; +} diff --git a/src/main/java/pi/procurarteapi/app/musician/dtos/PostImagesPortifolio/PostImagesPortifolioResponseDto.java b/src/main/java/pi/procurarteapi/app/musician/dtos/PostImagesPortifolio/PostImagesPortifolioResponseDto.java new file mode 100644 index 0000000..0f8a489 --- /dev/null +++ b/src/main/java/pi/procurarteapi/app/musician/dtos/PostImagesPortifolio/PostImagesPortifolioResponseDto.java @@ -0,0 +1,16 @@ +package pi.procurarteapi.app.musician.dtos.PostImagesPortifolio; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import pi.procurarteapi.infra.entities.Musician; + +@Setter +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class PostImagesPortifolioResponseDto { + private Musician musician; +} diff --git a/src/main/java/pi/procurarteapi/app/musician/interfaces/IPostMusicianImagePortifolioService.java b/src/main/java/pi/procurarteapi/app/musician/interfaces/IPostMusicianImagePortifolioService.java new file mode 100644 index 0000000..fb827f0 --- /dev/null +++ b/src/main/java/pi/procurarteapi/app/musician/interfaces/IPostMusicianImagePortifolioService.java @@ -0,0 +1,8 @@ +package pi.procurarteapi.app.musician.interfaces; + +import pi.procurarteapi.app.musician.dtos.PostImagesPortifolio.PostImagesPortifolioRequestDto; +import pi.procurarteapi.app.musician.dtos.PostImagesPortifolio.PostImagesPortifolioResponseDto; + +public interface IPostMusicianImagePortifolioService { + public PostImagesPortifolioResponseDto execute(PostImagesPortifolioRequestDto images)throws Exception; +} diff --git a/src/main/java/pi/procurarteapi/app/musician/services/PostMusicianImagePortifolioService.java b/src/main/java/pi/procurarteapi/app/musician/services/PostMusicianImagePortifolioService.java new file mode 100644 index 0000000..3c2f28d --- /dev/null +++ b/src/main/java/pi/procurarteapi/app/musician/services/PostMusicianImagePortifolioService.java @@ -0,0 +1,45 @@ +package pi.procurarteapi.app.musician.services; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import pi.procurarteapi.app.musician.dtos.PostImagesPortifolio.PostImagesPortifolioRequestDto; +import pi.procurarteapi.app.musician.dtos.PostImagesPortifolio.PostImagesPortifolioResponseDto; +import pi.procurarteapi.app.musician.interfaces.IPostMusicianImagePortifolioService; +import pi.procurarteapi.infra.entities.Musician; +import pi.procurarteapi.infra.entities.Musician.Portfolio; +import pi.procurarteapi.infra.repositories.IMusicianRepository; + +@Service +public class PostMusicianImagePortifolioService implements IPostMusicianImagePortifolioService{ + + @Autowired + private IMusicianRepository musicianRepository; + + public PostMusicianImagePortifolioService(IMusicianRepository musicianRepository) { + this.musicianRepository = musicianRepository; + } + + @Override + public PostImagesPortifolioResponseDto execute(PostImagesPortifolioRequestDto request) throws Exception { + + try { + Musician musician = musicianRepository.findById(request.getId()) + .orElseThrow(() -> new Exception("Musician Not Found")); + + Portfolio portfolio = musician.getPortfolio(); + portfolio.setMedia(request.getImages().getImages()); + musician.setPortfolio(portfolio); + + Musician savedMusician = musicianRepository.save(musician); + + PostImagesPortifolioResponseDto response = new PostImagesPortifolioResponseDto(); + response.setMusician(savedMusician); + + + return response; + } catch (Exception e) { + throw new Exception(e.getMessage()); + } + } +} diff --git a/src/main/java/pi/procurarteapi/infra/entities/Musician.java b/src/main/java/pi/procurarteapi/infra/entities/Musician.java index 85fedff..915074b 100644 --- a/src/main/java/pi/procurarteapi/infra/entities/Musician.java +++ b/src/main/java/pi/procurarteapi/infra/entities/Musician.java @@ -187,6 +187,10 @@ public String getThumbnail() { public List getMedia() { return media; + } + + public void setMedia(List media) { + this.media = media; } public static class Builder { diff --git a/src/main/java/pi/procurarteapi/infra/repositories/IImagesRepository.java b/src/main/java/pi/procurarteapi/infra/repositories/IImagesRepository.java new file mode 100644 index 0000000..cd955b0 --- /dev/null +++ b/src/main/java/pi/procurarteapi/infra/repositories/IImagesRepository.java @@ -0,0 +1,10 @@ +package pi.procurarteapi.infra.repositories; + +import org.springframework.data.mongodb.repository.MongoRepository; + +import pi.procurarteapi.infra.entities.Instrument; + +public interface IImagesRepository extends MongoRepository{ + + +} diff --git a/src/test/java/pi/procurarteapi/ProcurarteApiApplicationTests.java b/src/test/java/pi/procurarteapi/ProcurarteApiApplicationTests.java index cfede15..0efd5cb 100644 --- a/src/test/java/pi/procurarteapi/ProcurarteApiApplicationTests.java +++ b/src/test/java/pi/procurarteapi/ProcurarteApiApplicationTests.java @@ -5,9 +5,7 @@ @SpringBootTest class ProcurarteApiApplicationTests { - @Test void contextLoads() { } - }