-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/81 봉사 모집글 생성, 수정, 삭제 컨트롤러 생성 #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b70f49b
refactor(recruit-board): ApiController 네이밍 변경
leebs0521 c14fdd4
feat(image-upload): multi-part 파일을 받기 위한 컨버터 클래스 생성
leebs0521 cd6382b
feat(image-upload): 빈 이미지 파일일 경우 기본 이미지 URL 반환 하도록 변경
leebs0521 030ac2a
test(image-upload): 빈 이미지 파일일 경우 기본 이미지 URL 반환 하도록 변경에 따른 테스트
leebs0521 7150e93
chore: 기본 이미지 링크를 관리하기 위한 속성 추가
leebs0521 de0e07c
feat(recruit-board): 생성 수정 삭제 컨트롤러 생성
leebs0521 e8aea84
test(recruit-board): 생성 수정 삭제 컨트롤러 생성에 따른 테스트
leebs0521 649f39d
refactor(recruit-board): 와일드 카드 제거
leebs0521 fdfc8af
refactor(recruit-board): 와일드 카드 제거
leebs0521 12df139
feat(test): 인증이 필요한 컨트롤러 테스트시 사용할 어노테이션 권한 추가
leebs0521 27ca040
feat(recruit-board): RecruitBoard Command Controller 추가
leebs0521 2efd1e3
test(recruit-board): RecruitBoard Command Controller 테스트
leebs0521 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/java/com/somemore/imageupload/converter/MultipartJackson2HttpMessageConverter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.somemore.imageupload.converter; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import java.lang.reflect.Type; | ||
| import org.springframework.http.MediaType; | ||
| import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class MultipartJackson2HttpMessageConverter extends AbstractJackson2HttpMessageConverter { | ||
|
|
||
| /** | ||
| * Converter for support http request with header Content-Type: multipart/form-data | ||
| */ | ||
| public MultipartJackson2HttpMessageConverter(ObjectMapper objectMapper) { | ||
| super(objectMapper, MediaType.APPLICATION_OCTET_STREAM); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canWrite(Class<?> clazz, MediaType mediaType) { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean canWrite(Type type, Class<?> clazz, MediaType mediaType) { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean canWrite(MediaType mediaType) { | ||
| return false; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/main/java/com/somemore/recruitboard/controller/RecruitBoardCommandApiController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| package com.somemore.recruitboard.controller; | ||
|
|
||
|
|
||
| import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; | ||
|
|
||
| import com.somemore.global.common.response.ApiResponse; | ||
| import com.somemore.imageupload.dto.ImageUploadRequestDto; | ||
| import com.somemore.imageupload.usecase.ImageUploadUseCase; | ||
| import com.somemore.recruitboard.dto.request.RecruitBoardCreateRequestDto; | ||
| import com.somemore.recruitboard.dto.request.RecruitBoardLocationUpdateRequestDto; | ||
| import com.somemore.recruitboard.dto.request.RecruitBoardStatusUpdateRequestDto; | ||
| import com.somemore.recruitboard.dto.request.RecruitBoardUpdateRequestDto; | ||
| import com.somemore.recruitboard.usecase.command.CreateRecruitBoardUseCase; | ||
| import com.somemore.recruitboard.usecase.command.DeleteRecruitBoardUseCase; | ||
| import com.somemore.recruitboard.usecase.command.UpdateRecruitBoardUseCase; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import java.time.LocalDateTime; | ||
| import java.util.UUID; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.access.annotation.Secured; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| 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.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestPart; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| @Tag(name = "Recruit Board Command API", description = "봉사 활동 모집글 생성 수정 삭제 API") | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api") | ||
| @RestController | ||
| public class RecruitBoardCommandApiController { | ||
|
|
||
| private final CreateRecruitBoardUseCase createRecruitBoardUseCase; | ||
| private final UpdateRecruitBoardUseCase updateRecruitBoardUseCase; | ||
| private final DeleteRecruitBoardUseCase deleteRecruitBoardUseCase; | ||
| private final ImageUploadUseCase imageUploadUseCase; | ||
|
|
||
| @Secured("ROLE_CENTER") | ||
| @Operation(summary = "봉사 활동 모집글 등록", description = "봉사 활동 모집글을 등록합니다.") | ||
| @PostMapping(value = "/recruit-board", consumes = MULTIPART_FORM_DATA_VALUE) | ||
| public ApiResponse<Long> createRecruitBoard( | ||
| @AuthenticationPrincipal String userId, | ||
| @Valid @RequestPart("data") RecruitBoardCreateRequestDto requestDto, | ||
| @RequestPart(value = "img_file", required = false) MultipartFile image | ||
| ) { | ||
|
|
||
| String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image)); | ||
| return ApiResponse.ok( | ||
| 201, | ||
| createRecruitBoardUseCase.createRecruitBoard(requestDto, getCenterId(userId), | ||
| imgUrl), | ||
|
Comment on lines
+58
to
+59
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 id만 반환하나요?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 아이디만 반환합니다 |
||
| "봉사 활동 모집글 등록 성공" | ||
| ); | ||
| } | ||
|
|
||
| @Secured("ROLE_CENTER") | ||
| @Operation(summary = "봉사 활동 모집글 수정", description = "봉사 활동 모집글을 수정합니다.") | ||
| @PutMapping(value = "/recruit-board/{id}", consumes = MULTIPART_FORM_DATA_VALUE) | ||
| public ApiResponse<String> updateRecruitBoard( | ||
| @AuthenticationPrincipal String userId, | ||
| @PathVariable Long id, | ||
| @Valid @RequestPart("data") RecruitBoardUpdateRequestDto requestDto, | ||
| @RequestPart("img_file") MultipartFile image | ||
| ) { | ||
| String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image)); | ||
| updateRecruitBoardUseCase.updateRecruitBoard(requestDto, id, getCenterId(userId), imgUrl); | ||
|
|
||
| return ApiResponse.ok("봉사 활동 모집글 수정 성공"); | ||
| } | ||
|
|
||
| @Secured("ROLE_CENTER") | ||
| @Operation(summary = "봉사 활동 모집글 위치 수정", description = "봉사 활동 모집글의 위치를 수정합니다.") | ||
| @PutMapping(value = "/recruit-board/{id}/location") | ||
| public ApiResponse<String> updateRecruitBoardLocation( | ||
| @AuthenticationPrincipal String userId, | ||
| @PathVariable Long id, | ||
| @Valid @RequestBody RecruitBoardLocationUpdateRequestDto requestDto | ||
| ) { | ||
|
|
||
| updateRecruitBoardUseCase.updateRecruitBoardLocation(requestDto, id, getCenterId(userId)); | ||
| return ApiResponse.ok("봉사 활동 모집글 위치 수정 성공"); | ||
| } | ||
|
|
||
| @Secured("ROLE_CENTER") | ||
| @Operation(summary = "봉사 활동 모집글 상태 수정", description = "봉사 활동 모집글의 상태를 수정합니다.") | ||
| @PatchMapping(value = "/recruit-board/{id}") | ||
| public ApiResponse<String> updateRecruitBoardStatus( | ||
| @AuthenticationPrincipal String userId, | ||
| @PathVariable Long id, | ||
| @RequestBody RecruitBoardStatusUpdateRequestDto requestDto | ||
| ) { | ||
| LocalDateTime now = LocalDateTime.now(); | ||
| updateRecruitBoardUseCase.updateRecruitBoardStatus(requestDto.status(), id, | ||
| getCenterId(userId), | ||
| now); | ||
|
|
||
| return ApiResponse.ok("봉사 활동 모집글 상태 수정 성공"); | ||
| } | ||
|
|
||
| @Secured("ROLE_CENTER") | ||
| @Operation(summary = "봉사 활동 모집글 삭제", description = "봉사 활동 모집글을 삭제합니다.") | ||
| @DeleteMapping(value = "/recruit-board/{id}") | ||
| public ApiResponse<String> deleteRecruitBoard( | ||
| @AuthenticationPrincipal String userId, | ||
| @PathVariable Long id | ||
| ) { | ||
| deleteRecruitBoardUseCase.deleteRecruitBoard(getCenterId(userId), id); | ||
| return ApiResponse.ok("봉사 활동 모집글 삭제 성공"); | ||
| } | ||
|
|
||
| private static UUID getCenterId(String userId) { | ||
| return UUID.fromString(userId); | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/com/somemore/recruitboard/dto/request/RecruitBoardStatusUpdateRequestDto.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.somemore.recruitboard.dto.request; | ||
|
|
||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| import com.somemore.recruitboard.domain.RecruitStatus; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| @JsonNaming(SnakeCaseStrategy.class) | ||
| @Schema(description = "봉사 활동 모집글 상태 수정 요청 DTO") | ||
| public record RecruitBoardStatusUpdateRequestDto( | ||
| @Schema(description = "변경할 봉사 활동 모집글의 상태", example = "CLOSED") | ||
| RecruitStatus status | ||
| ) { | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,3 +101,7 @@ server: | |
| charset: UTF-8 | ||
| enabled: true | ||
| force: true | ||
|
|
||
| default: | ||
| image: | ||
| url: ${DEFAULT_IMG_URL} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
참고하겠습니다!