Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -5,10 +5,8 @@
import com.somemore.domains.community.usecase.board.CreateCommunityBoardUseCase;
import com.somemore.domains.community.usecase.board.DeleteCommunityBoardUseCase;
import com.somemore.domains.community.usecase.board.UpdateCommunityBoardUseCase;
import com.somemore.global.auth.annotation.CurrentUser;
import com.somemore.global.auth.annotation.RoleId;
import com.somemore.global.common.response.ApiResponse;
import com.somemore.global.imageupload.dto.ImageUploadRequestDto;
import com.somemore.global.imageupload.usecase.ImageUploadUseCase;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
Expand All @@ -19,14 +17,11 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
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")
Expand All @@ -36,49 +31,41 @@ 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)
@PostMapping
public ApiResponse<Long> createCommunityBoard(
@CurrentUser UUID userId,
@Valid @RequestPart("data") CommunityBoardCreateRequestDto requestDto,
@RequestPart(value = "img_file", required = false) MultipartFile image
@RoleId UUID volunteerId,
@Valid @RequestBody CommunityBoardCreateRequestDto requestDto
) {
String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image));

return ApiResponse.ok(
201,
createCommunityBoardUseCase.createCommunityBoard(requestDto, userId, imgUrl),
createCommunityBoardUseCase.createCommunityBoard(requestDto, volunteerId),
"커뮤니티 게시글 등록 성공"
);
}

@Secured("ROLE_VOLUNTEER")
@Operation(summary = "커뮤니티 게시글 수정", description = "커뮤니티 게시글을 수정합니다.")
@PutMapping(value = "/{id}", consumes = MULTIPART_FORM_DATA_VALUE)
@PutMapping(value = "/{id}")
public ApiResponse<String> updateCommunityBoard(
@CurrentUser UUID userId,
@RoleId UUID volunteerId,
@PathVariable Long id,
@Valid @RequestPart("data") CommunityBoardUpdateRequestDto requestDto,
@RequestPart(value = "img_file", required = false) MultipartFile image
@Valid @RequestBody CommunityBoardUpdateRequestDto requestDto
) {
String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image));
updateCommunityBoardUseCase.updateCommunityBoard(requestDto, id, userId, imgUrl);

updateCommunityBoardUseCase.updateCommunityBoard(requestDto, id, volunteerId);
return ApiResponse.ok("커뮤니티 게시글 수정 성공");
}

@Secured("ROLE_VOLUNTEER")
@Operation(summary = "커뮤니티 게시글 삭제", description = "커뮤니티 게시글을 삭제합니다.")
@DeleteMapping(value = "/{id}")
public ApiResponse<String> deleteCommunityBoard(
@CurrentUser UUID userId,
@RoleId UUID volunteerId,
@PathVariable Long id
) {
deleteCommunityBoardUseCase.deleteCommunityBoard(userId, id);

deleteCommunityBoardUseCase.deleteCommunityBoard(volunteerId, id);
return ApiResponse.ok("커뮤니티 게시글 삭제 성공");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.somemore.domains.community.usecase.comment.CreateCommunityCommentUseCase;
import com.somemore.domains.community.usecase.comment.DeleteCommunityCommentUseCase;
import com.somemore.domains.community.usecase.comment.UpdateCommunityCommentUseCase;
import com.somemore.global.auth.annotation.CurrentUser;
import com.somemore.global.auth.annotation.RoleId;
import com.somemore.global.common.response.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down Expand Up @@ -36,26 +36,26 @@ public class CommunityCommentCommandApiController {
@Operation(summary = "커뮤니티 댓글 등록", description = "커뮤니티 게시글에 댓글을 등록합니다.")
@PostMapping(value = "/comment")
public ApiResponse<Long> createCommunityComment(
@CurrentUser UUID userId,
@RoleId UUID volunteerId,
@PathVariable Long boardId,
@Valid @RequestBody CommunityCommentCreateRequestDto requestDto) {

return ApiResponse.ok(
201,
createCommunityCommentUseCase.createCommunityComment(requestDto, userId, boardId),
createCommunityCommentUseCase.createCommunityComment(requestDto, volunteerId, boardId),
"커뮤니티 댓글 등록 성공");
}

@Secured("ROLE_VOLUNTEER")
@Operation(summary = "커뮤니티 댓글 수정", description = "커뮤니티 댓글을 수정합니다.")
@PutMapping(value = "/comment/{id}")
public ApiResponse<String> updateCommunityComment(
@CurrentUser UUID userId,
@RoleId UUID volunteerId,
@PathVariable Long boardId,
@PathVariable Long id,
@Valid @RequestBody CommunityCommentUpdateRequestDto requestDto
) {
updateCommunityCommentUseCase.updateCommunityComment(requestDto, id, userId, boardId);
updateCommunityCommentUseCase.updateCommunityComment(requestDto, id, volunteerId, boardId);

return ApiResponse.ok("커뮤니티 댓글 수정 성공");
}
Expand All @@ -64,11 +64,11 @@ public ApiResponse<String> updateCommunityComment(
@Operation(summary = "커뮤니티 댓글 삭제", description = "커뮤니티 댓글을 삭제합니다.")
@DeleteMapping(value = "/comment/{id}")
public ApiResponse<String> deleteCommunityComment(
@CurrentUser UUID userId,
@RoleId UUID volunteerId,
@PathVariable Long boardId,
@PathVariable Long id
) {
deleteCommunityCommentUseCase.deleteCommunityComment(userId, id, boardId);
deleteCommunityCommentUseCase.deleteCommunityComment(volunteerId, id, boardId);

return ApiResponse.ok("커뮤니티 댓글 삭제 성공");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,19 @@ public class CommunityBoard extends BaseEntity {
@Column(name = "content", length = 1000, nullable = false)
private String content;

@Column(name = "img_url", nullable = false)
private String imgUrl;

@Builder
public CommunityBoard(UUID writerId, String title, String content, String imgUrl) {
public CommunityBoard(UUID writerId, String title, String content) {
this.writerId = writerId;
this.title = title;
this.content = content;
this.imgUrl = imgUrl;
}

public boolean isWriter(UUID writerId) {
return this.writerId.equals(writerId);
}

public void updateWith(CommunityBoardUpdateRequestDto dto, String imgUrl) {
public void updateWith(CommunityBoardUpdateRequestDto dto) {
this.title = dto.title();
this.content = dto.content();
this.imgUrl = imgUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ public record CommunityBoardCreateRequestDto(
@NotBlank(message = "게시글 내용은 필수 값입니다.")
String content
) {
public CommunityBoard toEntity(UUID writerId, String imgUrl) {
public CommunityBoard toEntity(UUID writerId) {
return CommunityBoard.builder()
.writerId(writerId)
.title(title)
.content(content)
.imgUrl(imgUrl)
.build();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public record CommunityBoardDetailResponseDto(
String title,
@Schema(description = "커뮤니티 게시글 내용", example = "저 포함 5명이 같이 가면 좋을 거 같아요")
String content,
@Schema(description = "이미지 URL", example = "https://image.domain.com/links")
String imageUrl,
@Schema(description = "커뮤니티 게시글 생성 일시", example = "2023-12-02T11:00:00")
LocalDateTime createdAt,
@Schema(description = "커뮤니티 게시글 수정 일시", example = "2023-12-02T11:00:00")
Expand All @@ -34,7 +32,6 @@ public static CommunityBoardDetailResponseDto from(CommunityBoard board) {
board.getWriterId(),
board.getTitle(),
board.getContent(),
board.getImgUrl(),
board.getCreatedAt(),
board.getUpdatedAt()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public record CommunityCommentResponseDto(
@Schema(description = "커뮤니티 댓글 ID", example = "1234")
Long id,
@Schema(description = "작성자 ID", example = "123e4567-e89b-12d3-a456-426614174000")
UUID writerId,
@Schema(description = "작성자(봉사자) 닉네임", example = "dkdudab")
String writerNickname,
@Schema(description = "커뮤니티 댓글 내용", example = "저도 함께 하고 싶습니다.")
Expand All @@ -39,6 +42,7 @@ public record CommunityCommentResponseDto(
public static CommunityCommentResponseDto from(CommunityCommentView comment) {
return new CommunityCommentResponseDto(
comment.communityComment().getId(),
comment.communityComment().getWriterId(),
comment.writerNickname(),
comment.communityComment().getContent(),
comment.communityComment().getUpdatedAt(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.somemore.domains.community.domain.CommunityBoard;
import com.somemore.domains.community.domain.QCommunityBoard;
import com.somemore.domains.community.repository.mapper.CommunityBoardView;
import com.somemore.domains.volunteer.domain.QVolunteer;
import com.somemore.volunteer.domain.QNEWVolunteer;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
Expand All @@ -27,7 +27,7 @@ public class CommunityBoardRepositoryImpl implements CommunityBoardRepository {
private final CommunityBoardJpaRepository communityBoardJpaRepository;

private static final QCommunityBoard communityBoard = QCommunityBoard.communityBoard;
private static final QVolunteer volunteer = QVolunteer.volunteer;
private static final QNEWVolunteer volunteer = QNEWVolunteer.nEWVolunteer;

@Override
public CommunityBoard save(CommunityBoard communityBoard) {
Expand Down Expand Up @@ -91,6 +91,11 @@ public void deleteAllInBatch() {
communityBoardJpaRepository.deleteAllInBatch();
}

@Override
public List<CommunityBoard> findAllByDeletedFalse() {
return communityBoardJpaRepository.findAllByDeletedFalse();
}

private JPAQuery<CommunityBoardView> getCommunityBoardsQuery() {
return queryFactory
.select(Projections.constructor(CommunityBoardView.class,
Expand All @@ -101,11 +106,6 @@ private JPAQuery<CommunityBoardView> getCommunityBoardsQuery() {
.orderBy(communityBoard.createdAt.desc());
}

@Override
public List<CommunityBoard> findAllByDeletedFalse() {
return communityBoardJpaRepository.findAllByDeletedFalse();
}

private BooleanExpression isNotDeleted() {
return communityBoard.deleted.eq(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.somemore.domains.community.domain.CommunityComment;
import com.somemore.domains.community.domain.QCommunityComment;
import com.somemore.domains.community.repository.mapper.CommunityCommentView;
import com.somemore.domains.volunteer.domain.QVolunteer;
import com.somemore.volunteer.domain.QNEWVolunteer;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -24,7 +24,7 @@ public class CommunityCommentRepositoryImpl implements CommunityCommentRepositor
private final CommunityCommentJpaRepository communityCommentJpaRepository;

private static final QCommunityComment communityComment = QCommunityComment.communityComment;
private static final QVolunteer volunteer = QVolunteer.volunteer;
private static final QNEWVolunteer volunteer = QNEWVolunteer.nEWVolunteer;

@Override
public CommunityComment save(CommunityComment communityComment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class CreateCommunityBoardService implements CreateCommunityBoardUseCase
private final CommunityBoardRepository communityBoardRepository;

@Override
public Long createCommunityBoard(CommunityBoardCreateRequestDto requestDto, UUID writerId, String imgUrl) {
public Long createCommunityBoard(CommunityBoardCreateRequestDto requestDto, UUID writerId) {

CommunityBoard communityBoard = requestDto.toEntity(writerId, imgUrl == null ? "" : imgUrl);
CommunityBoard communityBoard = requestDto.toEntity(writerId);

communityBoardRepository.save(communityBoard);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public class UpdateCommunityBoardService implements UpdateCommunityBoardUseCase
private final CommunityBoardRepository communityBoardRepository;

@Override
public void updateCommunityBoard(CommunityBoardUpdateRequestDto requestDto, Long communityBoardId, UUID writerId, String imgUrl) {
public void updateCommunityBoard(CommunityBoardUpdateRequestDto requestDto, Long communityBoardId, UUID writerId) {
CommunityBoard communityBoard = getCommunityBoardById(communityBoardId);
validateWriter(communityBoard, writerId);
communityBoard.updateWith(requestDto, imgUrl);
communityBoard.updateWith(requestDto);

communityBoardRepository.save(communityBoard);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
public interface CreateCommunityBoardUseCase {
Long createCommunityBoard(
CommunityBoardCreateRequestDto requestDto,
UUID writerId,
String imgUrl);
UUID writerId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ public interface UpdateCommunityBoardUseCase {
void updateCommunityBoard(
CommunityBoardUpdateRequestDto requestDto,
Long communityBoardId,
UUID writerId,
String imgUrl);
UUID writerId);
}
Loading