Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("커뮤니티 게시글 삭제 성공");
}
}
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@currentuser 없어도 될 것 같아요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정했습니다!

) {
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),
"커뮤니티 게시글 상세 조회 성공"
);
}
}
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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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("커뮤니티 댓글 삭제 성공");
}
}
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()),
"커뮤니티 게시글의 댓글 리스트 조회 성공"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,21 @@
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;

import java.util.UUID;

@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
@Builder
public record CommunityCommentCreateRequestDto(
@Schema(description = "커뮤니티 게시글 ID", example = "33")
@NotNull(message = "게시글 ID는 필수 값입니다.")
Long communityBoardId,
@Schema(description = "커뮤니티 댓글 내용", example = "저도 함께 하고 싶습니다.")
@NotBlank(message = "댓글 내용은 필수 값입니다.")
String content,
@Schema(description = "부모 댓글 ID", example = "1234", nullable = true)
@Nullable
Long parentCommentId
) {
public CommunityComment toEntity(UUID writerId) {
public CommunityComment toEntity(UUID writerId, Long communityBoardId) {
return CommunityComment.builder()
.communityBoardId(communityBoardId)
.writerId(writerId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.somemore.community.domain.CommunityBoard;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

import java.time.LocalDateTime;
import java.util.UUID;

@Builder
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
@Schema(description = "커뮤니티 게시글 상세 조회 응답 DTO")
public record CommunityBoardDetailResponseDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public class CreateCommunityCommentService implements CreateCommunityCommentUseC
private final CommunityCommentRepository communityCommentRepository;

@Override
public Long createCommunityComment(CommunityCommentCreateRequestDto requestDto, UUID writerId) {
CommunityComment communityComment = requestDto.toEntity(writerId);
public Long createCommunityComment(CommunityCommentCreateRequestDto requestDto, UUID writerId, Long communityBoardId) {
CommunityComment communityComment = requestDto.toEntity(writerId, communityBoardId);

validateCommunityBoardExists(communityComment.getCommunityBoardId());
validateCommunityBoardExists(communityBoardId);

if (requestDto.parentCommentId() != null) {
validateParentCommentExists(communityComment.getParentCommentId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DeleteCommunityCommentService implements DeleteCommunityCommentUseC
private final CommunityCommentRepository communityCommentRepository;

@Override
public void deleteCommunityComment(UUID writerId, Long id) {
public void deleteCommunityComment(UUID writerId, Long id, Long communityBoardId) {

CommunityComment communityComment = getCommunityCommentById(id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public class UpdateCommunityCommentService implements UpdateCommunityCommentUseC
private final CommunityBoardRepository communityBoardRepository;

@Override
public void updateCommunityComment(CommunityCommentUpdateRequestDto requestDto, Long communityCommentId, UUID writerId) {
public void updateCommunityComment(CommunityCommentUpdateRequestDto requestDto, Long communityCommentId, UUID writerId, Long communityBoardId) {

CommunityComment communityComment = getCommunityCommentById(communityCommentId);

validateCommunityBoardExists(communityComment.getCommunityBoardId());
validateCommunityBoardExists(communityBoardId);

validateWriter(communityComment, writerId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
public interface CreateCommunityCommentUseCase {
Long createCommunityComment(
CommunityCommentCreateRequestDto requestDto,
UUID writerId);
UUID writerId,
Long communityBoardId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
import java.util.UUID;

public interface DeleteCommunityCommentUseCase {
void deleteCommunityComment(UUID writerId, Long id);
void deleteCommunityComment(UUID writerId, Long id, Long communityBoardId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public interface UpdateCommunityCommentUseCase {
void updateCommunityComment(
CommunityCommentUpdateRequestDto requestDto,
Long communityCommentId,
UUID writerId);
UUID writerId,
Long communityBoardId);
}
Loading
Loading