Skip to content

Commit

Permalink
Merge pull request #178 from urinaner/refactor/177
Browse files Browse the repository at this point in the history
[BE] [REFACTOR] 파일 필드를 필수 필드에서 제외
  • Loading branch information
pillow12360 authored Nov 27, 2024
2 parents 42a2d43 + 313fd6e commit 0444519
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class BoardController {
@Operation(summary = "게시판 생성 API 입니다.", description = "게시판 생성입니다.")
@PostMapping(consumes = "multipart/form-data")
public ResponseEntity<Long> createBoard(@RequestPart(value = "boardReqDto") BoardReqDto boardReqDto,
@RequestPart(value = "boardFiles") List<MultipartFile> multipartFileList) {
@RequestPart(value = "boardFiles", required = false) List<MultipartFile> multipartFileList) {
Long boardId = boardService.saveBoard(boardReqDto, multipartFileList);
return new ResponseEntity<>(boardId, HttpStatus.OK);
}
Expand Down Expand Up @@ -64,7 +64,7 @@ public ResponseEntity<BoardResDto> getBoard(@PathVariable(name = "boardId") Long
@PostMapping("/{boardId}")
public ResponseEntity<BoardResDto> updateBoard(@PathVariable(name = "boardId") Long boardId,
@RequestPart(value = "boardReqDto") BoardReqDto boardReqDto,
@RequestPart(value = "boardFiles") List<MultipartFile> multipartFileList) {
@RequestPart(value = "boardFiles", required = false) List<MultipartFile> multipartFileList) {
BoardResDto boardResDto = boardService.updateBoard(boardId, boardReqDto, multipartFileList);
return new ResponseEntity<>(boardResDto, HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public Page<BoardResDto> getBoardsByCategory(Category category, Pageable pageabl
@Transactional
public BoardResDto updateBoard(Long boardId, BoardReqDto boardReqDto, List<MultipartFile> multipartFileList) {
fileUpload(boardReqDto, multipartFileList);

Board board = findBoardById(boardId);
board.update(boardReqDto);
return BoardResDto.of(board);
Expand All @@ -83,9 +84,9 @@ private Board findBoardById(Long boardId) {

private void fileUpload(BoardReqDto boardReqDto, List<MultipartFile> multipartFileList) {
List<String> updateImageUrlList = new ArrayList<>();
if (!multipartFileList.isEmpty()) {
if (multipartFileList != null && !multipartFileList.isEmpty()) {
for (MultipartFile multipartFile : multipartFileList) {
if (multipartFile.isEmpty()) {
if (multipartFile == null || multipartFile.isEmpty()) {
throw new BoardException(BoardExceptionType.REQUIRED_FILE);
}
String uploadImageUrl = s3Uploader.upload(multipartFile, dirName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class ProfessorController {
@PostMapping(consumes = "multipart/form-data")
public ResponseEntity<Long> createProfessor(
@RequestPart(value = "professorReqDto") ProfessorReqDto professorReqDto,
@RequestPart(value = "profileImage") MultipartFile multipartFile
@RequestPart(value = "profileImage", required = false) MultipartFile multipartFile
) {
Long professorId = professorService.saveProfessor(professorReqDto, multipartFile);
return new ResponseEntity<>(professorId, HttpStatus.OK);
Expand Down Expand Up @@ -69,7 +69,7 @@ public ResponseDto<List<ProfessorResDto>> getAllBoards(Pageable pageable) {
@PostMapping("/{professorId}")
public ResponseEntity<ProfessorResDto> updateProfessor(@PathVariable(name = "professorId") Long professorId,
@RequestPart(value = "professorReqDto") ProfessorReqDto professorReqDto,
@RequestPart(value = "profileImage") MultipartFile multipartFile) {
@RequestPart(value = "profileImage", required = false) MultipartFile multipartFile) {
ProfessorResDto professorResDto = professorService.updateProfessor(professorId, professorReqDto, multipartFile);
return new ResponseEntity<>(professorResDto, HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Long saveProfessor(ProfessorReqDto professorReqDto, MultipartFile multipa
validateUserRequiredFields(professorReqDto);
validateUserUniqueFields(professorReqDto);

if (!multipartFile.isEmpty()) {
if (multipartFile != null && !multipartFile.isEmpty()) {
String uploadImageUrl = s3Uploader.upload(multipartFile, dirName);
professorReqDto.setProfileImage(uploadImageUrl);
}
Expand Down Expand Up @@ -71,7 +71,7 @@ public Page<ProfessorResDto> getAllProfessors(Pageable pageable) {

@Transactional
public ProfessorResDto updateProfessor(Long professorId, ProfessorReqDto professorReqDto, MultipartFile multipartFile) {
if (!multipartFile.isEmpty()) {
if (multipartFile != null && !multipartFile.isEmpty()) {
String uploadImageUrl = s3Uploader.upload(multipartFile, dirName);
professorReqDto.setProfileImage(uploadImageUrl);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ThesisController {
@PostMapping(consumes = "multipart/form-data")
public ResponseEntity<Long> createThesis(
@RequestPart(value = "thesisReqDto") ThesisReqDto thesisReqDto,
@RequestPart(value = "thesis_image") MultipartFile multipartFile) {
@RequestPart(value = "thesis_image", required = false) MultipartFile multipartFile) {
Long thesisId = thesisService.saveThesis(thesisReqDto, multipartFile);
return new ResponseEntity<>(thesisId, HttpStatus.OK);
}
Expand All @@ -58,7 +58,7 @@ public ResponseDto<List<ThesisResDto>> getAllBoards(Pageable pageable) {
@PostMapping("/{thesisId}")
public ResponseEntity<ThesisResDto> updateThesis(@PathVariable(name = "thesisId") Long thesisId,
@RequestPart(value = "thesisReqDto") ThesisReqDto thesisReqDto,
@RequestPart(value = "thesis_image") MultipartFile multipartFile) {
@RequestPart(value = "thesis_image", required = false) MultipartFile multipartFile) {
ThesisResDto thesisResDto = thesisService.updateThesis(thesisId, thesisReqDto, multipartFile);
return new ResponseEntity<>(thesisResDto, HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Long saveThesis(ThesisReqDto thesisReqDto, MultipartFile multipartFile) {
validateUserRequiredFields(thesisReqDto);
Professor professor = findProfessorById(thesisReqDto.getProfessorId());

if (!multipartFile.isEmpty()) {
if (multipartFile != null && !multipartFile.isEmpty()) {
String uploadImageUrl = s3Uploader.upload(multipartFile, dirName);
thesisReqDto.setThesisImage(uploadImageUrl);
}
Expand Down Expand Up @@ -66,7 +66,7 @@ public Page<ThesisResDto> getAllTheses(Pageable pageable) {

@Transactional
public ThesisResDto updateThesis(Long thesisId, ThesisReqDto thesisReqDto, MultipartFile multipartFile) {
if (!multipartFile.isEmpty()) {
if (multipartFile != null && !multipartFile.isEmpty()) {
String uploadImageUrl = s3Uploader.upload(multipartFile, dirName);
thesisReqDto.setThesisImage(uploadImageUrl);
}
Expand Down

0 comments on commit 0444519

Please sign in to comment.