-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/120 커뮤니티 게시글, 댓글 CRUD 엔드포인트 생성 #133
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 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bb916c9
test(community): community 게시글, 댓글 controller test 추가
ayoung-dev d0e5806
feat(community): community 게시글, 댓글 controller 추가
ayoung-dev bde087c
feat(community): community-comment boardId request 필드 -> Pathvariable
ayoung-dev 4d51e29
feat(community): community-comment 상세 조회 responseDto builder 추가
ayoung-dev 8247bde
refactor(community): sonar 반영
ayoung-dev e4ac068
Merge branch 'main' of https://github.com/prgrms-web-devcourse-final-…
ayoung-dev 0f7ed47
refactor(community): community 댓글 생성, 수정 requestDto @RequestPart("dat…
ayoung-dev 82f20f0
refactor(community): community 게시글 조회 컨트롤러 @CurrentUser 삭제
ayoung-dev cb26f4a
Merge branch 'main' of https://github.com/prgrms-web-devcourse-final-…
ayoung-dev 58e37d4
chore(community): 불필요한 import 제거
ayoung-dev 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
78 changes: 78 additions & 0 deletions
78
src/main/java/com/somemore/community/controller/CommunityBoardCommandApiController.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,78 @@ | ||
| package com.somemore.community.controller; | ||
|
|
||
| import com.somemore.auth.annotation.CurrentUser; | ||
| import com.somemore.community.dto.request.CommunityBoardCreateRequestDto; | ||
| import com.somemore.community.dto.request.CommunityBoardUpdateRequestDto; | ||
| import com.somemore.community.usecase.board.CreateCommunityBoardUseCase; | ||
| import com.somemore.community.usecase.board.DeleteCommunityBoardUseCase; | ||
| import com.somemore.community.usecase.board.UpdateCommunityBoardUseCase; | ||
| import com.somemore.global.common.response.ApiResponse; | ||
| import com.somemore.imageupload.dto.ImageUploadRequestDto; | ||
| import com.somemore.imageupload.usecase.ImageUploadUseCase; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.access.annotation.Secured; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; | ||
|
|
||
| @Tag(name = "Community Board Command API", description = "커뮤니티 게시글 생성 수정 삭제 API") | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/community-board") | ||
| @RestController | ||
| public class CommunityBoardCommandApiController { | ||
|
|
||
| private final CreateCommunityBoardUseCase createCommunityBoardUseCase; | ||
| private final UpdateCommunityBoardUseCase updateCommunityBoardUseCase; | ||
| private final DeleteCommunityBoardUseCase deleteCommunityBoardUseCase; | ||
| private final ImageUploadUseCase imageUploadUseCase; | ||
|
|
||
| @Secured("ROLE_VOLUNTEER") | ||
| @Operation(summary = "커뮤니티 게시글 등록", description = "커뮤니티 게시글을 등록합니다.") | ||
| @PostMapping(consumes = MULTIPART_FORM_DATA_VALUE) | ||
| public ApiResponse<Long> createCommunityBoard( | ||
| @CurrentUser UUID userId, | ||
| @Valid @RequestPart("data") CommunityBoardCreateRequestDto requestDto, | ||
| @RequestPart(value = "img_file", required = false) MultipartFile image | ||
| ) { | ||
| String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image)); | ||
|
|
||
| return ApiResponse.ok( | ||
| 201, | ||
| createCommunityBoardUseCase.createCommunityBoard(requestDto, userId, imgUrl), | ||
| "커뮤니티 게시글 등록 성공" | ||
| ); | ||
| } | ||
|
|
||
| @Secured("ROLE_VOLUNTEER") | ||
| @Operation(summary = "커뮤니티 게시글 수정", description = "커뮤니티 게시글을 수정합니다.") | ||
| @PutMapping(value = "/{id}", consumes = MULTIPART_FORM_DATA_VALUE) | ||
| public ApiResponse<String> updateCommunityBoard( | ||
| @CurrentUser UUID userId, | ||
| @PathVariable Long id, | ||
| @Valid @RequestPart("data") CommunityBoardUpdateRequestDto requestDto, | ||
| @RequestPart(value = "img_file", required = false) MultipartFile image | ||
| ) { | ||
| String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image)); | ||
| updateCommunityBoardUseCase.updateCommunityBoard(requestDto, id, userId, imgUrl); | ||
|
|
||
| return ApiResponse.ok("커뮤니티 게시글 수정 성공"); | ||
| } | ||
|
|
||
| @Secured("ROLE_VOLUNTEER") | ||
| @Operation(summary = "커뮤니티 게시글 삭제", description = "커뮤니티 게시글을 삭제합니다.") | ||
| @DeleteMapping(value = "/{id}") | ||
| public ApiResponse<String> deleteCommunityBoard( | ||
| @CurrentUser UUID userId, | ||
| @PathVariable Long id | ||
| ) { | ||
| deleteCommunityBoardUseCase.deleteCommunityBoard(userId, id); | ||
|
|
||
| return ApiResponse.ok("커뮤니티 게시글 삭제 성공"); | ||
| } | ||
| } |
61 changes: 61 additions & 0 deletions
61
src/main/java/com/somemore/community/controller/CommunityBoardQueryApiController.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,61 @@ | ||
| package com.somemore.community.controller; | ||
|
|
||
| import com.somemore.auth.annotation.CurrentUser; | ||
| import com.somemore.community.dto.response.CommunityBoardDetailResponseDto; | ||
| import com.somemore.community.dto.response.CommunityBoardResponseDto; | ||
| import com.somemore.community.usecase.board.CommunityBoardQueryUseCase; | ||
| import com.somemore.global.common.response.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Tag(name = "Community Board Query API", description = "커뮤니티 게시글 조회 관련 API") | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api") | ||
| @RestController | ||
| public class CommunityBoardQueryApiController { | ||
|
|
||
| private final CommunityBoardQueryUseCase communityBoardQueryUseCase; | ||
|
|
||
| @GetMapping("/community-boards") | ||
| @Operation(summary = "전체 커뮤니티 게시글 조회", description = "전체 커뮤니티 게시글 목록을 조회합니다.") | ||
| public ApiResponse<Page<CommunityBoardResponseDto>> getAll( | ||
| Pageable pageable | ||
| ) { | ||
| return ApiResponse.ok( | ||
| 200, | ||
| communityBoardQueryUseCase.getCommunityBoards(pageable.getPageNumber()), | ||
| "전체 커뮤니티 게시글 리스트 조회 성공" | ||
| ); | ||
| } | ||
|
|
||
| @GetMapping("/community-boards/{writerId}") | ||
| @Operation(summary = "작성자별 커뮤니티 게시글 조회", description = "작성자별 커뮤니티 게시글 목록을 조회합니다.") | ||
| public ApiResponse<Page<CommunityBoardResponseDto>> getByWriterId( | ||
| @PathVariable UUID writerId, | ||
| Pageable pageable | ||
| ) { | ||
| return ApiResponse.ok( | ||
| 200, | ||
| communityBoardQueryUseCase.getCommunityBoardsByWriterId(writerId, pageable.getPageNumber()), | ||
| "작성자별 커뮤니티 게시글 리스트 조회 성공" | ||
| ); | ||
| } | ||
|
|
||
| @GetMapping("/community-board/{id}") | ||
| @Operation(summary = "커뮤니티 게시글 상세 조회", description = "커뮤니티 게시글의 상세 정보를 조회합니다.") | ||
| public ApiResponse<CommunityBoardDetailResponseDto> getById( | ||
| @PathVariable Long id | ||
| ) { | ||
| return ApiResponse.ok( | ||
| 200, | ||
| communityBoardQueryUseCase.getCommunityBoardDetail(id), | ||
| "커뮤니티 게시글 상세 조회 성공" | ||
| ); | ||
| } | ||
| } | ||
69 changes: 69 additions & 0 deletions
69
src/main/java/com/somemore/community/controller/CommunityCommentCommandApiController.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,69 @@ | ||
| package com.somemore.community.controller; | ||
|
|
||
| import com.somemore.auth.annotation.CurrentUser; | ||
| import com.somemore.community.dto.request.CommunityCommentCreateRequestDto; | ||
| import com.somemore.community.dto.request.CommunityCommentUpdateRequestDto; | ||
| import com.somemore.community.usecase.comment.CreateCommunityCommentUseCase; | ||
| import com.somemore.community.usecase.comment.DeleteCommunityCommentUseCase; | ||
| import com.somemore.community.usecase.comment.UpdateCommunityCommentUseCase; | ||
| import com.somemore.global.common.response.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.security.access.annotation.Secured; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @Tag(name = "Community Comment Command API", description = "커뮤니티 댓글 생성 수정 삭제 API") | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/community-board/{boardId}") | ||
| @RestController | ||
|
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. 오.. 여기도 Pathvariable이 가능하군요 신기하네요 |
||
| public class CommunityCommentCommandApiController { | ||
|
|
||
| private final CreateCommunityCommentUseCase createCommunityCommentUseCase; | ||
| private final UpdateCommunityCommentUseCase updateCommunityCommentUseCase; | ||
| private final DeleteCommunityCommentUseCase deleteCommunityCommentUseCase; | ||
|
|
||
| @Secured("ROLE_VOLUNTEER") | ||
| @Operation(summary = "커뮤니티 댓글 등록", description = "커뮤니티 게시글에 댓글을 등록합니다.") | ||
| @PostMapping(value = "/comment") | ||
| public ApiResponse<Long> createCommunityComment( | ||
| @CurrentUser UUID userId, | ||
| @PathVariable Long boardId, | ||
| @Valid @RequestBody CommunityCommentCreateRequestDto requestDto) { | ||
|
|
||
| return ApiResponse.ok( | ||
| 201, | ||
| createCommunityCommentUseCase.createCommunityComment(requestDto, userId, boardId), | ||
| "커뮤니티 댓글 등록 성공"); | ||
| } | ||
|
|
||
| @Secured("ROLE_VOLUNTEER") | ||
| @Operation(summary = "커뮤니티 댓글 수정", description = "커뮤니티 댓글을 수정합니다.") | ||
| @PutMapping(value = "/comment/{id}") | ||
| public ApiResponse<String> updateCommunityComment( | ||
| @CurrentUser UUID userId, | ||
| @PathVariable Long boardId, | ||
| @PathVariable Long id, | ||
| @Valid @RequestBody CommunityCommentUpdateRequestDto requestDto | ||
| ) { | ||
| updateCommunityCommentUseCase.updateCommunityComment(requestDto, id, userId, boardId); | ||
|
|
||
| return ApiResponse.ok("커뮤니티 댓글 수정 성공"); | ||
| } | ||
|
|
||
| @Secured("ROLE_VOLUNTEER") | ||
| @Operation(summary = "커뮤니티 댓글 삭제", description = "커뮤니티 댓글을 삭제합니다.") | ||
| @DeleteMapping(value = "/comment/{id}") | ||
| public ApiResponse<String> deleteCommunityComment( | ||
| @CurrentUser UUID userId, | ||
| @PathVariable Long boardId, | ||
| @PathVariable Long id | ||
| ) { | ||
| deleteCommunityCommentUseCase.deleteCommunityComment(userId, id, boardId); | ||
|
|
||
| return ApiResponse.ok("커뮤니티 댓글 삭제 성공"); | ||
| } | ||
| } | ||
36 changes: 36 additions & 0 deletions
36
src/main/java/com/somemore/community/controller/CommunityCommentQueryApiController.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,36 @@ | ||
| package com.somemore.community.controller; | ||
|
|
||
| import com.somemore.community.dto.response.CommunityCommentResponseDto; | ||
| import com.somemore.community.usecase.comment.CommunityCommentQueryUseCase; | ||
| import com.somemore.global.common.response.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @Tag(name = "Community Comment Query API", description = "커뮤니티 댓글 조회 API") | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/community-board") | ||
| @RestController | ||
| public class CommunityCommentQueryApiController { | ||
|
|
||
| private final CommunityCommentQueryUseCase communityCommentQueryUseCase; | ||
|
|
||
| @GetMapping("/{boardId}/comments") | ||
| @Operation(summary = "커뮤니티 댓글 조회", description = "커뮤니티 게시글의 댓글 목록을 조회합니다.") | ||
| public ApiResponse<Page<CommunityCommentResponseDto>> getByBoardId( | ||
| @PathVariable Long boardId, | ||
| Pageable pageable | ||
| ) { | ||
| return ApiResponse.ok( | ||
| 200, | ||
| communityCommentQueryUseCase.getCommunityCommentsByBoardId(boardId, pageable.getPageNumber()), | ||
| "커뮤니티 게시글의 댓글 리스트 조회 성공" | ||
| ); | ||
| } | ||
| } |
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
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.
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.
@currentuser 없어도 될 것 같아요!
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.
수정했습니다!