PromoteurController.java
package com.sintia.ffl.admin.audio.api.controllers;
import com.sintia.ffl.admin.audio.services.services.PromoteurService;
import com.sintia.ffl.adminui.commons.dto.PromoteurDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Optional;
@RestController
@RequestMapping("/api/v1/promoteur")
@Slf4j
@RequiredArgsConstructor(onConstructor = @__ ({@Autowired }))
public class PromoteurController {
private final PromoteurService promoteurService;
@PostMapping(value = "/logo")
@Operation(operationId = "uploadLogo", summary = "Uploader le logo",
description = "Uploader le logo du promoteur",
responses = {
@ApiResponse(responseCode = "200", description = "Traitement terminé normalement"),
@ApiResponse(responseCode = "204", description = "Données non-trouvées")
})
public ResponseEntity<Optional<PromoteurDTO>> uploadeLogoPromoteur(@RequestParam Integer idPromoteur, @RequestParam MultipartFile logoFile)
throws IOException {
if (logoFile != null && logoFile.getSize() > 0){
log.info("uploadeLogoPromoteur:idPromoteur: {} logoFile: {}",idPromoteur, logoFile);
Optional<PromoteurDTO> optionalPromoteurDTO = promoteurService.saveLogo(idPromoteur, logoFile.getBytes());
return ResponseEntity.ok(optionalPromoteurDTO);
}
return ResponseEntity.noContent().build();
}
@PostMapping(value = "/manuel")
@Operation(operationId = "uploadeManuel", summary = "Uploader le manuel",
description = "Uploader le manuel du promoteur",
responses = {
@ApiResponse(responseCode = "200", description = "Traitement terminé normalement"),
@ApiResponse(responseCode = "204", description = "Données non-trouvées")
})
public ResponseEntity<Optional<PromoteurDTO>> uploadeManuelPromoteur(@RequestParam Integer idPromoteur, @RequestParam MultipartFile docFile) throws IOException {
if (docFile !=null && docFile.getSize() >0) {
return ResponseEntity.ok(promoteurService.saveManuel(idPromoteur, docFile.getBytes()));
}
return ResponseEntity.noContent().build();
}
}