Skip to content

Commit d0e5806

Browse files
committed
feat(community): community 게시글, 댓글 controller 추가
1 parent bb916c9 commit d0e5806

File tree

4 files changed

+244
-0
lines changed

4 files changed

+244
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.somemore.community.controller;
2+
3+
import com.somemore.auth.annotation.CurrentUser;
4+
import com.somemore.community.dto.request.CommunityBoardCreateRequestDto;
5+
import com.somemore.community.dto.request.CommunityBoardUpdateRequestDto;
6+
import com.somemore.community.usecase.board.CreateCommunityBoardUseCase;
7+
import com.somemore.community.usecase.board.DeleteCommunityBoardUseCase;
8+
import com.somemore.community.usecase.board.UpdateCommunityBoardUseCase;
9+
import com.somemore.global.common.response.ApiResponse;
10+
import com.somemore.imageupload.dto.ImageUploadRequestDto;
11+
import com.somemore.imageupload.usecase.ImageUploadUseCase;
12+
import io.swagger.v3.oas.annotations.Operation;
13+
import io.swagger.v3.oas.annotations.tags.Tag;
14+
import jakarta.validation.Valid;
15+
import lombok.RequiredArgsConstructor;
16+
import org.springframework.security.access.annotation.Secured;
17+
import org.springframework.web.bind.annotation.*;
18+
import org.springframework.web.multipart.MultipartFile;
19+
20+
import java.util.UUID;
21+
22+
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
23+
24+
@Tag(name = "Community Board Command API", description = "커뮤니티 게시글 생성 수정 삭제 API")
25+
@RequiredArgsConstructor
26+
@RequestMapping("/api/community-board")
27+
@RestController
28+
public class CommunityBoardCommandApiController {
29+
30+
private final CreateCommunityBoardUseCase createCommunityBoardUseCase;
31+
private final UpdateCommunityBoardUseCase updateCommunityBoardUseCase;
32+
private final DeleteCommunityBoardUseCase deleteCommunityBoardUseCase;
33+
private final ImageUploadUseCase imageUploadUseCase;
34+
35+
@Secured("ROLE_VOLUNTEER")
36+
@Operation(summary = "커뮤니티 게시글 등록", description = "커뮤니티 게시글을 등록합니다.")
37+
@PostMapping(consumes = MULTIPART_FORM_DATA_VALUE)
38+
public ApiResponse<Long> createCommunityBoard(
39+
@CurrentUser UUID user_id,
40+
@Valid @RequestPart("data") CommunityBoardCreateRequestDto requestDto,
41+
@RequestPart(value = "img_file", required = false) MultipartFile image
42+
) {
43+
String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image));
44+
45+
return ApiResponse.ok(
46+
201,
47+
createCommunityBoardUseCase.createCommunityBoard(requestDto, user_id, imgUrl),
48+
"커뮤니티 게시글 등록 성공"
49+
);
50+
}
51+
52+
@Secured("ROLE_VOLUNTEER")
53+
@Operation(summary = "커뮤니티 게시글 수정", description = "커뮤니티 게시글을 수정합니다.")
54+
@PutMapping(value = "/{id}", consumes = MULTIPART_FORM_DATA_VALUE)
55+
public ApiResponse<String> updateCommunityBoard(
56+
@CurrentUser UUID user_id,
57+
@PathVariable Long id,
58+
@Valid @RequestPart("data") CommunityBoardUpdateRequestDto requestDto,
59+
@RequestPart(value = "img_file", required = false) MultipartFile image
60+
) {
61+
String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image));
62+
updateCommunityBoardUseCase.updateCommunityBoard(requestDto, id, user_id, imgUrl);
63+
64+
return ApiResponse.ok("커뮤니티 게시글 수정 성공");
65+
}
66+
67+
@Secured("ROLE_VOLUNTEER")
68+
@Operation(summary = "커뮤니티 게시글 삭제", description = "커뮤니티 게시글을 삭제합니다.")
69+
@DeleteMapping(value = "/{id}")
70+
public ApiResponse<String> deleteCommunityBoard(
71+
@CurrentUser UUID user_id,
72+
@PathVariable Long id
73+
) {
74+
deleteCommunityBoardUseCase.deleteCommunityBoard(user_id, id);
75+
76+
return ApiResponse.ok("커뮤니티 게시글 삭제 성공");
77+
}
78+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.somemore.community.controller;
2+
3+
import com.somemore.auth.annotation.CurrentUser;
4+
import com.somemore.community.dto.response.CommunityBoardDetailResponseDto;
5+
import com.somemore.community.dto.response.CommunityBoardResponseDto;
6+
import com.somemore.community.usecase.board.CommunityBoardQueryUseCase;
7+
import com.somemore.global.common.response.ApiResponse;
8+
import io.swagger.v3.oas.annotations.Operation;
9+
import io.swagger.v3.oas.annotations.tags.Tag;
10+
import lombok.RequiredArgsConstructor;
11+
import org.springframework.data.domain.Page;
12+
import org.springframework.data.domain.Pageable;
13+
import org.springframework.web.bind.annotation.*;
14+
15+
import java.util.UUID;
16+
17+
@Tag(name = "Community Board Query API", description = "커뮤니티 게시글 조회 관련 API")
18+
@RequiredArgsConstructor
19+
@RequestMapping("/api")
20+
@RestController
21+
public class CommunityBoardQueryApiController {
22+
23+
private final CommunityBoardQueryUseCase communityBoardQueryUseCase;
24+
25+
@GetMapping("/community-boards")
26+
@Operation(summary = "전체 커뮤니티 게시글 조회", description = "전체 커뮤니티 게시글 목록을 조회합니다.")
27+
public ApiResponse<Page<CommunityBoardResponseDto>> getAll(
28+
Pageable pageable
29+
) {
30+
return ApiResponse.ok(
31+
200,
32+
communityBoardQueryUseCase.getCommunityBoards(pageable.getPageNumber()),
33+
"전체 커뮤니티 게시글 리스트 조회 성공"
34+
);
35+
}
36+
37+
@GetMapping("/community-boards/{writer_id}")
38+
@Operation(summary = "작성자별 커뮤니티 게시글 조회", description = "작성자별 커뮤니티 게시글 목록을 조회합니다.")
39+
public ApiResponse<Page<CommunityBoardResponseDto>> getByWriterId(
40+
@PathVariable @CurrentUser UUID writer_id,
41+
Pageable pageable
42+
) {
43+
return ApiResponse.ok(
44+
200,
45+
communityBoardQueryUseCase.getCommunityBoardsByWriterId(writer_id, pageable.getPageNumber()),
46+
"작성자별 커뮤니티 게시글 리스트 조회 성공"
47+
);
48+
}
49+
50+
@GetMapping("/community-board/{id}")
51+
@Operation(summary = "커뮤니티 게시글 상세 조회", description = "커뮤니티 게시글의 상세 정보를 조회합니다.")
52+
public ApiResponse<CommunityBoardDetailResponseDto> getById(
53+
@PathVariable Long id
54+
) {
55+
return ApiResponse.ok(
56+
200,
57+
communityBoardQueryUseCase.getCommunityBoardDetail(id),
58+
"커뮤니티 게시글 상세 조회 성공"
59+
);
60+
}
61+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.somemore.community.controller;
2+
3+
import com.somemore.auth.annotation.CurrentUser;
4+
import com.somemore.community.dto.request.CommunityCommentCreateRequestDto;
5+
import com.somemore.community.dto.request.CommunityCommentUpdateRequestDto;
6+
import com.somemore.community.usecase.comment.CreateCommunityCommentUseCase;
7+
import com.somemore.community.usecase.comment.DeleteCommunityCommentUseCase;
8+
import com.somemore.community.usecase.comment.UpdateCommunityCommentUseCase;
9+
import com.somemore.global.common.response.ApiResponse;
10+
import io.swagger.v3.oas.annotations.Operation;
11+
import io.swagger.v3.oas.annotations.tags.Tag;
12+
import jakarta.validation.Valid;
13+
import lombok.RequiredArgsConstructor;
14+
import org.springframework.security.access.annotation.Secured;
15+
import org.springframework.web.bind.annotation.*;
16+
17+
import java.util.UUID;
18+
19+
@Tag(name = "Community Comment Command API", description = "커뮤니티 댓글 생성 수정 삭제 API")
20+
@RequiredArgsConstructor
21+
@RequestMapping("/api/community-board/{board_id}")
22+
@RestController
23+
public class CommunityCommentCommandApiController {
24+
25+
private final CreateCommunityCommentUseCase createCommunityCommentUseCase;
26+
private final UpdateCommunityCommentUseCase updateCommunityCommentUseCase;
27+
private final DeleteCommunityCommentUseCase deleteCommunityCommentUseCase;
28+
29+
@Secured("ROLE_VOLUNTEER")
30+
@Operation(summary = "커뮤니티 댓글 등록", description = "커뮤니티 게시글에 댓글을 등록합니다.")
31+
@PostMapping(value = "/comment")
32+
public ApiResponse<Long> createCommunityComment(
33+
@CurrentUser UUID user_id,
34+
@PathVariable Long board_id,
35+
@Valid @RequestPart("data") CommunityCommentCreateRequestDto requestDto) {
36+
37+
return ApiResponse.ok(
38+
201,
39+
createCommunityCommentUseCase.createCommunityComment(requestDto, user_id, board_id),
40+
"커뮤니티 댓글 등록 성공");
41+
}
42+
43+
@Secured("ROLE_VOLUNTEER")
44+
@Operation(summary = "커뮤니티 댓글 수정", description = "커뮤니티 댓글을 수정합니다.")
45+
@PutMapping(value = "/comment/{id}")
46+
public ApiResponse<String> updateCommunityComment(
47+
@CurrentUser UUID user_id,
48+
@PathVariable Long board_id,
49+
@PathVariable Long id,
50+
@Valid @RequestPart("data") CommunityCommentUpdateRequestDto requestDto
51+
) {
52+
updateCommunityCommentUseCase.updateCommunityComment(requestDto, id, user_id, board_id);
53+
54+
return ApiResponse.ok("커뮤니티 댓글 수정 성공");
55+
}
56+
57+
@Secured("ROLE_VOLUNTEER")
58+
@Operation(summary = "커뮤니티 댓글 삭제", description = "커뮤니티 댓글을 삭제합니다.")
59+
@DeleteMapping(value = "/comment/{id}")
60+
public ApiResponse<String> deleteCommunityComment(
61+
@CurrentUser UUID user_id,
62+
@PathVariable Long board_id,
63+
@PathVariable Long id
64+
) {
65+
deleteCommunityCommentUseCase.deleteCommunityComment(user_id, id, board_id);
66+
67+
return ApiResponse.ok("커뮤니티 댓글 삭제 성공");
68+
}
69+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.somemore.community.controller;
2+
3+
import com.somemore.community.dto.response.CommunityCommentResponseDto;
4+
import com.somemore.community.usecase.comment.CommunityCommentQueryUseCase;
5+
import com.somemore.global.common.response.ApiResponse;
6+
import io.swagger.v3.oas.annotations.Operation;
7+
import io.swagger.v3.oas.annotations.tags.Tag;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.data.domain.Page;
10+
import org.springframework.data.domain.Pageable;
11+
import org.springframework.web.bind.annotation.GetMapping;
12+
import org.springframework.web.bind.annotation.PathVariable;
13+
import org.springframework.web.bind.annotation.RequestMapping;
14+
import org.springframework.web.bind.annotation.RestController;
15+
16+
@Tag(name = "Community Comment Query API", description = "커뮤니티 댓글 조회 API")
17+
@RequiredArgsConstructor
18+
@RequestMapping("/api/community-board")
19+
@RestController
20+
public class CommunityCommentQueryApiController {
21+
22+
private final CommunityCommentQueryUseCase communityCommentQueryUseCase;
23+
24+
@GetMapping("/{board_id}/comments")
25+
@Operation(summary = "커뮤니티 댓글 조회", description = "커뮤니티 게시글의 댓글 목록을 조회합니다.")
26+
public ApiResponse<Page<CommunityCommentResponseDto>> getByBoardId(
27+
@PathVariable Long board_id,
28+
Pageable pageable
29+
) {
30+
return ApiResponse.ok(
31+
200,
32+
communityCommentQueryUseCase.getCommunityCommentsByBoardId(board_id, pageable.getPageNumber()),
33+
"커뮤니티 게시글의 댓글 리스트 조회 성공"
34+
);
35+
}
36+
}

0 commit comments

Comments
 (0)