-
Notifications
You must be signed in to change notification settings - Fork 1
[BUILD FAIL] Feature/81 봉사 모집글 생성, 수정, 삭제 컨트롤러 생성 #88
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
18ca0e0
refactor(recruit-board): ApiController 네이밍 변경
leebs0521 11fb0e3
feat(image-upload): multi-part 파일을 받기 위한 컨버터 클래스 생성
leebs0521 66371e6
feat(image-upload): 빈 이미지 파일일 경우 기본 이미지 URL 반환 하도록 변경
leebs0521 55c98f6
test(image-upload): 빈 이미지 파일일 경우 기본 이미지 URL 반환 하도록 변경에 따른 테스트
leebs0521 3be9210
chore: 기본 이미지 링크를 관리하기 위한 속성 추가
leebs0521 0589545
feat(recruit-board): 생성 수정 삭제 컨트롤러 생성
leebs0521 47e49dd
test(recruit-board): 생성 수정 삭제 컨트롤러 생성에 따른 테스트
leebs0521 b744386
refactor(recruit-board): 와일드 카드 제거
leebs0521 e50c176
refactor(recruit-board): 와일드 카드 제거
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
121 changes: 121 additions & 0 deletions
121
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,121 @@ | ||
| 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.prepost.PreAuthorize; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.security.core.context.SecurityContextHolder; | ||
| 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 = "RecruitBoard", 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; | ||
|
|
||
| @PreAuthorize("hasRole('CENTER')") | ||
| @Operation(summary = "봉사 활동 모집글 등록", description = "봉사 활동 모집글을 등록합니다.") | ||
| @PostMapping(value = "/recruit-board", consumes = MULTIPART_FORM_DATA_VALUE) | ||
| public ApiResponse<Long> createRecruitBoard( | ||
| @Valid @RequestPart("data") RecruitBoardCreateRequestDto requestDto, | ||
| @RequestPart("img_file") MultipartFile image | ||
| ) { | ||
|
|
||
| String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image)); | ||
| return ApiResponse.ok( | ||
| 201, | ||
| createRecruitBoardUseCase.createRecruitBoard(requestDto, getCenterId(), imgUrl), | ||
| "봉사 활동 모집글 등록 성공" | ||
| ); | ||
| } | ||
|
|
||
| @PreAuthorize("hasRole('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(), imgUrl); | ||
|
|
||
| return ApiResponse.ok("봉사 활동 모집글 수정 성공"); | ||
| } | ||
|
|
||
| @PreAuthorize("hasRole('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()); | ||
| return ApiResponse.ok("봉사 활동 모집글 위치 수정 성공"); | ||
| } | ||
|
|
||
| @PreAuthorize("hasRole('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(), | ||
| now); | ||
|
|
||
| return ApiResponse.ok("봉사 활동 모집글 상태 수정 성공"); | ||
| } | ||
|
|
||
| @PreAuthorize("hasRole('CENTER')") | ||
| @Operation(summary = "봉사 활동 모집글 삭제", description = "봉사 활동 모집글을 삭제합니다.") | ||
| @DeleteMapping(value = "/recruit-board/{id}") | ||
| public ApiResponse<String> deleteRecruitBoard( | ||
| @AuthenticationPrincipal String userId, | ||
| @PathVariable Long id | ||
| ) { | ||
| deleteRecruitBoardUseCase.deleteRecruitBoard(getCenterId(), id); | ||
| return ApiResponse.ok("봉사 활동 모집글 삭제 성공"); | ||
| } | ||
|
|
||
| private static UUID getCenterId() { | ||
| return UUID.fromString(SecurityContextHolder.getContext().getAuthentication().getName()); | ||
| } | ||
|
|
||
| } |
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} | ||
|
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. 환경변수 공유 부탁드립니다
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. 디스코드에 남겨드리겠습니다 |
||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.