PromoteurController.java

  1. package com.sintia.ffl.admin.audio.api.controllers;

  2. import com.sintia.ffl.admin.audio.services.services.PromoteurService;
  3. import com.sintia.ffl.adminui.commons.dto.PromoteurDTO;
  4. import io.swagger.v3.oas.annotations.Operation;
  5. import io.swagger.v3.oas.annotations.responses.ApiResponse;
  6. import lombok.RequiredArgsConstructor;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.http.ResponseEntity;
  10. import org.springframework.web.bind.annotation.PostMapping;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RequestParam;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import org.springframework.web.multipart.MultipartFile;

  15. import java.io.IOException;
  16. import java.util.Optional;

  17. @RestController
  18. @RequestMapping("/api/v1/promoteur")
  19. @Slf4j
  20. @RequiredArgsConstructor(onConstructor = @__ ({@Autowired }))
  21. public class PromoteurController {
  22.    
  23.     private final PromoteurService promoteurService;
  24.    
  25.     @PostMapping(value = "/logo")
  26.     @Operation(operationId = "uploadLogo", summary = "Uploader le logo",
  27.             description = "Uploader le logo du promoteur",
  28.             responses = {
  29.                     @ApiResponse(responseCode = "200", description = "Traitement terminé normalement"),
  30.                     @ApiResponse(responseCode = "204", description = "Données non-trouvées")
  31.             })
  32.     public ResponseEntity<Optional<PromoteurDTO>> uploadeLogoPromoteur(@RequestParam Integer idPromoteur, @RequestParam MultipartFile logoFile)
  33.             throws IOException {
  34.         if (logoFile != null && logoFile.getSize() > 0){
  35.             log.info("uploadeLogoPromoteur:idPromoteur: {} logoFile: {}",idPromoteur,  logoFile);
  36.             Optional<PromoteurDTO> optionalPromoteurDTO = promoteurService.saveLogo(idPromoteur, logoFile.getBytes());
  37.             return ResponseEntity.ok(optionalPromoteurDTO);
  38.         }
  39.         return ResponseEntity.noContent().build();
  40.        
  41.     }
  42.    
  43.     @PostMapping(value = "/manuel")
  44.     @Operation(operationId = "uploadeManuel", summary = "Uploader le manuel",
  45.             description = "Uploader le manuel du promoteur",
  46.             responses = {
  47.                     @ApiResponse(responseCode = "200", description = "Traitement terminé normalement"),
  48.                     @ApiResponse(responseCode = "204", description = "Données non-trouvées")
  49.             })
  50.     public ResponseEntity<Optional<PromoteurDTO>> uploadeManuelPromoteur(@RequestParam Integer idPromoteur, @RequestParam MultipartFile docFile) throws IOException {
  51.         if (docFile !=null && docFile.getSize()  >0) {
  52.             return ResponseEntity.ok(promoteurService.saveManuel(idPromoteur, docFile.getBytes()));
  53.         }
  54.         return ResponseEntity.noContent().build();
  55.     }
  56.    
  57. }