Skip to content

Commit

Permalink
Merge pull request #2 from KevinAlvss/feat/post-musician-portifolio
Browse files Browse the repository at this point in the history
Feat/post musician portifolio
  • Loading branch information
RaianNolaco authored Nov 21, 2023
2 parents e66ac02 + 18ad980 commit 4938e52
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ public class ProcurarteApiApplication {
public static void main(String[] args) {
SpringApplication.run(ProcurarteApiApplication.class, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -69,6 +74,9 @@ public class MusicianController {
@Autowired
private UpdateMusicianMusicStylesServices updateMusicianMusicStylesServices;

@Autowired
private PostMusicianImagePortifolioService postMusicianImagePortifolioService;

@GetMapping
public ResponseEntity<?> list() throws Exception {
try {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> Images;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/pi/procurarteapi/infra/entities/Musician.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ public String getThumbnail() {

public List<String> getMedia() {
return media;
}

public void setMedia(List<String> media) {
this.media = media;
}

public static class Builder {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Instrument, String>{


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

@SpringBootTest
class ProcurarteApiApplicationTests {

@Test
void contextLoads() {
}

}

0 comments on commit 4938e52

Please sign in to comment.