Skip to content

Commit 934cfd1

Browse files
authored
refactor: 커뮤니티 리팩토링 (#363)
* refactor(community): command controller 수정 - @currentuser -> @RoleId - 명확성을 위해 userId -> volunteerId로 변경 * refactor(community): imgUrl 삭제 * refactor(community): 커뮤니티 댓글 반환값에 작성자 ID 추가 * refactor(community): volunteer -> NewVolunteer * test(community): imgUrl 삭제 및 NewVolunteer로 변경으로 인한 test 수정 * test(community): sonarqube 반영 - 이미지 링크와 관련된 test 삭제
1 parent 58396fb commit 934cfd1

25 files changed

+92
-220
lines changed

src/main/java/com/somemore/domains/community/controller/CommunityBoardCommandApiController.java

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import com.somemore.domains.community.usecase.board.CreateCommunityBoardUseCase;
66
import com.somemore.domains.community.usecase.board.DeleteCommunityBoardUseCase;
77
import com.somemore.domains.community.usecase.board.UpdateCommunityBoardUseCase;
8-
import com.somemore.global.auth.annotation.CurrentUser;
8+
import com.somemore.global.auth.annotation.RoleId;
99
import com.somemore.global.common.response.ApiResponse;
10-
import com.somemore.global.imageupload.dto.ImageUploadRequestDto;
11-
import com.somemore.global.imageupload.usecase.ImageUploadUseCase;
1210
import io.swagger.v3.oas.annotations.Operation;
1311
import io.swagger.v3.oas.annotations.tags.Tag;
1412
import jakarta.validation.Valid;
@@ -19,14 +17,11 @@
1917
import org.springframework.web.bind.annotation.PostMapping;
2018
import org.springframework.web.bind.annotation.PutMapping;
2119
import org.springframework.web.bind.annotation.RequestMapping;
22-
import org.springframework.web.bind.annotation.RequestPart;
20+
import org.springframework.web.bind.annotation.RequestBody;
2321
import org.springframework.web.bind.annotation.RestController;
24-
import org.springframework.web.multipart.MultipartFile;
2522

2623
import java.util.UUID;
2724

28-
import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE;
29-
3025
@Tag(name = "Community Board Command API", description = "커뮤니티 게시글 생성 수정 삭제 API")
3126
@RequiredArgsConstructor
3227
@RequestMapping("/api/community-board")
@@ -36,49 +31,41 @@ public class CommunityBoardCommandApiController {
3631
private final CreateCommunityBoardUseCase createCommunityBoardUseCase;
3732
private final UpdateCommunityBoardUseCase updateCommunityBoardUseCase;
3833
private final DeleteCommunityBoardUseCase deleteCommunityBoardUseCase;
39-
private final ImageUploadUseCase imageUploadUseCase;
4034

4135
@Secured("ROLE_VOLUNTEER")
4236
@Operation(summary = "커뮤니티 게시글 등록", description = "커뮤니티 게시글을 등록합니다.")
43-
@PostMapping(consumes = MULTIPART_FORM_DATA_VALUE)
37+
@PostMapping
4438
public ApiResponse<Long> createCommunityBoard(
45-
@CurrentUser UUID userId,
46-
@Valid @RequestPart("data") CommunityBoardCreateRequestDto requestDto,
47-
@RequestPart(value = "img_file", required = false) MultipartFile image
39+
@RoleId UUID volunteerId,
40+
@Valid @RequestBody CommunityBoardCreateRequestDto requestDto
4841
) {
49-
String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image));
50-
5142
return ApiResponse.ok(
5243
201,
53-
createCommunityBoardUseCase.createCommunityBoard(requestDto, userId, imgUrl),
44+
createCommunityBoardUseCase.createCommunityBoard(requestDto, volunteerId),
5445
"커뮤니티 게시글 등록 성공"
5546
);
5647
}
5748

5849
@Secured("ROLE_VOLUNTEER")
5950
@Operation(summary = "커뮤니티 게시글 수정", description = "커뮤니티 게시글을 수정합니다.")
60-
@PutMapping(value = "/{id}", consumes = MULTIPART_FORM_DATA_VALUE)
51+
@PutMapping(value = "/{id}")
6152
public ApiResponse<String> updateCommunityBoard(
62-
@CurrentUser UUID userId,
53+
@RoleId UUID volunteerId,
6354
@PathVariable Long id,
64-
@Valid @RequestPart("data") CommunityBoardUpdateRequestDto requestDto,
65-
@RequestPart(value = "img_file", required = false) MultipartFile image
55+
@Valid @RequestBody CommunityBoardUpdateRequestDto requestDto
6656
) {
67-
String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image));
68-
updateCommunityBoardUseCase.updateCommunityBoard(requestDto, id, userId, imgUrl);
69-
57+
updateCommunityBoardUseCase.updateCommunityBoard(requestDto, id, volunteerId);
7058
return ApiResponse.ok("커뮤니티 게시글 수정 성공");
7159
}
7260

7361
@Secured("ROLE_VOLUNTEER")
7462
@Operation(summary = "커뮤니티 게시글 삭제", description = "커뮤니티 게시글을 삭제합니다.")
7563
@DeleteMapping(value = "/{id}")
7664
public ApiResponse<String> deleteCommunityBoard(
77-
@CurrentUser UUID userId,
65+
@RoleId UUID volunteerId,
7866
@PathVariable Long id
7967
) {
80-
deleteCommunityBoardUseCase.deleteCommunityBoard(userId, id);
81-
68+
deleteCommunityBoardUseCase.deleteCommunityBoard(volunteerId, id);
8269
return ApiResponse.ok("커뮤니티 게시글 삭제 성공");
8370
}
8471
}

src/main/java/com/somemore/domains/community/controller/CommunityCommentCommandApiController.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.somemore.domains.community.usecase.comment.CreateCommunityCommentUseCase;
66
import com.somemore.domains.community.usecase.comment.DeleteCommunityCommentUseCase;
77
import com.somemore.domains.community.usecase.comment.UpdateCommunityCommentUseCase;
8-
import com.somemore.global.auth.annotation.CurrentUser;
8+
import com.somemore.global.auth.annotation.RoleId;
99
import com.somemore.global.common.response.ApiResponse;
1010
import io.swagger.v3.oas.annotations.Operation;
1111
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -36,26 +36,26 @@ public class CommunityCommentCommandApiController {
3636
@Operation(summary = "커뮤니티 댓글 등록", description = "커뮤니티 게시글에 댓글을 등록합니다.")
3737
@PostMapping(value = "/comment")
3838
public ApiResponse<Long> createCommunityComment(
39-
@CurrentUser UUID userId,
39+
@RoleId UUID volunteerId,
4040
@PathVariable Long boardId,
4141
@Valid @RequestBody CommunityCommentCreateRequestDto requestDto) {
4242

4343
return ApiResponse.ok(
4444
201,
45-
createCommunityCommentUseCase.createCommunityComment(requestDto, userId, boardId),
45+
createCommunityCommentUseCase.createCommunityComment(requestDto, volunteerId, boardId),
4646
"커뮤니티 댓글 등록 성공");
4747
}
4848

4949
@Secured("ROLE_VOLUNTEER")
5050
@Operation(summary = "커뮤니티 댓글 수정", description = "커뮤니티 댓글을 수정합니다.")
5151
@PutMapping(value = "/comment/{id}")
5252
public ApiResponse<String> updateCommunityComment(
53-
@CurrentUser UUID userId,
53+
@RoleId UUID volunteerId,
5454
@PathVariable Long boardId,
5555
@PathVariable Long id,
5656
@Valid @RequestBody CommunityCommentUpdateRequestDto requestDto
5757
) {
58-
updateCommunityCommentUseCase.updateCommunityComment(requestDto, id, userId, boardId);
58+
updateCommunityCommentUseCase.updateCommunityComment(requestDto, id, volunteerId, boardId);
5959

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

7373
return ApiResponse.ok("커뮤니티 댓글 삭제 성공");
7474
}

src/main/java/com/somemore/domains/community/domain/CommunityBoard.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,19 @@ public class CommunityBoard extends BaseEntity {
3838
@Column(name = "content", length = 1000, nullable = false)
3939
private String content;
4040

41-
@Column(name = "img_url", nullable = false)
42-
private String imgUrl;
43-
4441
@Builder
45-
public CommunityBoard(UUID writerId, String title, String content, String imgUrl) {
42+
public CommunityBoard(UUID writerId, String title, String content) {
4643
this.writerId = writerId;
4744
this.title = title;
4845
this.content = content;
49-
this.imgUrl = imgUrl;
5046
}
5147

5248
public boolean isWriter(UUID writerId) {
5349
return this.writerId.equals(writerId);
5450
}
5551

56-
public void updateWith(CommunityBoardUpdateRequestDto dto, String imgUrl) {
52+
public void updateWith(CommunityBoardUpdateRequestDto dto) {
5753
this.title = dto.title();
5854
this.content = dto.content();
59-
this.imgUrl = imgUrl;
6055
}
6156
}

src/main/java/com/somemore/domains/community/dto/request/CommunityBoardCreateRequestDto.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ public record CommunityBoardCreateRequestDto(
1919
@NotBlank(message = "게시글 내용은 필수 값입니다.")
2020
String content
2121
) {
22-
public CommunityBoard toEntity(UUID writerId, String imgUrl) {
22+
public CommunityBoard toEntity(UUID writerId) {
2323
return CommunityBoard.builder()
2424
.writerId(writerId)
2525
.title(title)
2626
.content(content)
27-
.imgUrl(imgUrl)
2827
.build();
2928
}
30-
31-
3229
}

src/main/java/com/somemore/domains/community/dto/response/CommunityBoardDetailResponseDto.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ public record CommunityBoardDetailResponseDto(
2121
String title,
2222
@Schema(description = "커뮤니티 게시글 내용", example = "저 포함 5명이 같이 가면 좋을 거 같아요")
2323
String content,
24-
@Schema(description = "이미지 URL", example = "https://image.domain.com/links")
25-
String imageUrl,
2624
@Schema(description = "커뮤니티 게시글 생성 일시", example = "2023-12-02T11:00:00")
2725
LocalDateTime createdAt,
2826
@Schema(description = "커뮤니티 게시글 수정 일시", example = "2023-12-02T11:00:00")
@@ -34,7 +32,6 @@ public static CommunityBoardDetailResponseDto from(CommunityBoard board) {
3432
board.getWriterId(),
3533
board.getTitle(),
3634
board.getContent(),
37-
board.getImgUrl(),
3835
board.getCreatedAt(),
3936
board.getUpdatedAt()
4037
);

src/main/java/com/somemore/domains/community/dto/response/CommunityCommentResponseDto.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
import java.time.LocalDateTime;
99
import java.util.ArrayList;
1010
import java.util.List;
11+
import java.util.UUID;
1112

1213
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
1314
public record CommunityCommentResponseDto(
1415
@Schema(description = "커뮤니티 댓글 ID", example = "1234")
1516
Long id,
17+
@Schema(description = "작성자 ID", example = "123e4567-e89b-12d3-a456-426614174000")
18+
UUID writerId,
1619
@Schema(description = "작성자(봉사자) 닉네임", example = "dkdudab")
1720
String writerNickname,
1821
@Schema(description = "커뮤니티 댓글 내용", example = "저도 함께 하고 싶습니다.")
@@ -39,6 +42,7 @@ public record CommunityCommentResponseDto(
3942
public static CommunityCommentResponseDto from(CommunityCommentView comment) {
4043
return new CommunityCommentResponseDto(
4144
comment.communityComment().getId(),
45+
comment.communityComment().getWriterId(),
4246
comment.writerNickname(),
4347
comment.communityComment().getContent(),
4448
comment.communityComment().getUpdatedAt(),

src/main/java/com/somemore/domains/community/repository/board/CommunityBoardRepositoryImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import com.somemore.domains.community.domain.CommunityBoard;
88
import com.somemore.domains.community.domain.QCommunityBoard;
99
import com.somemore.domains.community.repository.mapper.CommunityBoardView;
10-
import com.somemore.domains.volunteer.domain.QVolunteer;
10+
import com.somemore.volunteer.domain.QNEWVolunteer;
1111
import lombok.RequiredArgsConstructor;
1212
import org.apache.commons.lang3.StringUtils;
1313
import org.springframework.data.domain.Page;
@@ -27,7 +27,7 @@ public class CommunityBoardRepositoryImpl implements CommunityBoardRepository {
2727
private final CommunityBoardJpaRepository communityBoardJpaRepository;
2828

2929
private static final QCommunityBoard communityBoard = QCommunityBoard.communityBoard;
30-
private static final QVolunteer volunteer = QVolunteer.volunteer;
30+
private static final QNEWVolunteer volunteer = QNEWVolunteer.nEWVolunteer;
3131

3232
@Override
3333
public CommunityBoard save(CommunityBoard communityBoard) {
@@ -91,6 +91,11 @@ public void deleteAllInBatch() {
9191
communityBoardJpaRepository.deleteAllInBatch();
9292
}
9393

94+
@Override
95+
public List<CommunityBoard> findAllByDeletedFalse() {
96+
return communityBoardJpaRepository.findAllByDeletedFalse();
97+
}
98+
9499
private JPAQuery<CommunityBoardView> getCommunityBoardsQuery() {
95100
return queryFactory
96101
.select(Projections.constructor(CommunityBoardView.class,
@@ -101,11 +106,6 @@ private JPAQuery<CommunityBoardView> getCommunityBoardsQuery() {
101106
.orderBy(communityBoard.createdAt.desc());
102107
}
103108

104-
@Override
105-
public List<CommunityBoard> findAllByDeletedFalse() {
106-
return communityBoardJpaRepository.findAllByDeletedFalse();
107-
}
108-
109109
private BooleanExpression isNotDeleted() {
110110
return communityBoard.deleted.eq(false);
111111
}

src/main/java/com/somemore/domains/community/repository/comment/CommunityCommentRepositoryImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.somemore.domains.community.domain.CommunityComment;
77
import com.somemore.domains.community.domain.QCommunityComment;
88
import com.somemore.domains.community.repository.mapper.CommunityCommentView;
9-
import com.somemore.domains.volunteer.domain.QVolunteer;
9+
import com.somemore.volunteer.domain.QNEWVolunteer;
1010
import lombok.RequiredArgsConstructor;
1111
import org.springframework.data.domain.Page;
1212
import org.springframework.data.domain.Pageable;
@@ -24,7 +24,7 @@ public class CommunityCommentRepositoryImpl implements CommunityCommentRepositor
2424
private final CommunityCommentJpaRepository communityCommentJpaRepository;
2525

2626
private static final QCommunityComment communityComment = QCommunityComment.communityComment;
27-
private static final QVolunteer volunteer = QVolunteer.volunteer;
27+
private static final QNEWVolunteer volunteer = QNEWVolunteer.nEWVolunteer;
2828

2929
@Override
3030
public CommunityComment save(CommunityComment communityComment) {

src/main/java/com/somemore/domains/community/service/board/CreateCommunityBoardService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public class CreateCommunityBoardService implements CreateCommunityBoardUseCase
1818
private final CommunityBoardRepository communityBoardRepository;
1919

2020
@Override
21-
public Long createCommunityBoard(CommunityBoardCreateRequestDto requestDto, UUID writerId, String imgUrl) {
21+
public Long createCommunityBoard(CommunityBoardCreateRequestDto requestDto, UUID writerId) {
2222

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

2525
communityBoardRepository.save(communityBoard);
2626

src/main/java/com/somemore/domains/community/service/board/UpdateCommunityBoardService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public class UpdateCommunityBoardService implements UpdateCommunityBoardUseCase
2323
private final CommunityBoardRepository communityBoardRepository;
2424

2525
@Override
26-
public void updateCommunityBoard(CommunityBoardUpdateRequestDto requestDto, Long communityBoardId, UUID writerId, String imgUrl) {
26+
public void updateCommunityBoard(CommunityBoardUpdateRequestDto requestDto, Long communityBoardId, UUID writerId) {
2727
CommunityBoard communityBoard = getCommunityBoardById(communityBoardId);
2828
validateWriter(communityBoard, writerId);
29-
communityBoard.updateWith(requestDto, imgUrl);
29+
communityBoard.updateWith(requestDto);
3030

3131
communityBoardRepository.save(communityBoard);
3232
}

0 commit comments

Comments
 (0)