Skip to content

Commit 288864b

Browse files
Merge pull request #390 from JNU-econovation/feature/BE-148
[BE-148] 코멘트 숨김 기능
2 parents c46b54a + 3d636a2 commit 288864b

File tree

6 files changed

+34
-8
lines changed

6 files changed

+34
-8
lines changed

server/Recruit-Api/src/main/java/com/econovation/recruit/api/comment/controller/CommentController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public ResponseEntity<List<CommentPairVo>> findByCardId(
5050
return new ResponseEntity(comments, HttpStatus.OK);
5151
}
5252

53-
@Operation(summary = "applicationId로 댓글 조회")
53+
@Operation(summary = "applicationId로 댓글 조회", description = "권한별로 회장단만 모든 코멘트 조회 가능, TF들은 자신의 코멘트만 조회 가능")
5454
@GetMapping("/applicants/{applicant-id}/comments")
5555
public ResponseEntity<List<CommentPairVo>> findByApplicantId(
5656
@PathVariable(name = "applicant-id") String applicantId) {

server/Recruit-Api/src/main/java/com/econovation/recruit/api/comment/service/CommentService.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.econovation.recruitdomain.domains.dto.CommentPairVo;
1313
import com.econovation.recruitdomain.domains.dto.CommentRegisterDto;
1414
import com.econovation.recruitdomain.domains.interviewer.domain.Interviewer;
15+
import com.econovation.recruitdomain.domains.interviewer.domain.Role;
1516
import com.econovation.recruitdomain.out.CardLoadPort;
1617
import com.econovation.recruitdomain.out.CommentLikeLoadPort;
1718
import com.econovation.recruitdomain.out.CommentLikeRecordPort;
@@ -165,14 +166,16 @@ public void deleteCommentLike(Long commentId) {
165166
@Override
166167
public List<CommentPairVo> findByCardId(Long cardId) {
167168
Long idpId = SecurityUtils.getCurrentUserId();
169+
Interviewer interviewer = interviewerLoadPort.loadInterviewById(idpId);
170+
168171
Card card = cardLoadPort.findById(cardId);
169172
List<Comment> comments = commentLoadPort.findByCardId(card.getId());
170173

171-
return getCommentPairVo(idpId, comments);
174+
return getCommentPairVo(idpId, comments, isAdminRole(interviewer));
172175
}
173176

174177
@NotNull
175-
private List<CommentPairVo> getCommentPairVo(Long idpId, List<Comment> comments) {
178+
private List<CommentPairVo> getCommentPairVo(Long idpId, List<Comment> comments, boolean isAdmin) {
176179
List<Long> idpIds = comments.stream().map(Comment::getIdpId).collect(Collectors.toList());
177180

178181
List<Interviewer> interviewers = interviewerLoadPort.loadInterviewerByIdpIds(idpIds);
@@ -194,6 +197,7 @@ private List<CommentPairVo> getCommentPairVo(Long idpId, List<Comment> comments)
194197
.equals(idpId));
195198

196199
Boolean canEdit = Objects.equals(comment.getIdpId(), idpId);
200+
Boolean isBlurred = !isAdmin && !canEdit;
197201
String interviewersName =
198202
interviewers.stream()
199203
.filter(
@@ -204,7 +208,7 @@ private List<CommentPairVo> getCommentPairVo(Long idpId, List<Comment> comments)
204208
.findFirst()
205209
.map(Interviewer::getName)
206210
.orElse("");
207-
return CommentPairVo.of(comment, isLiked, interviewersName, canEdit);
211+
return CommentPairVo.of(comment, isLiked, interviewersName, canEdit, isBlurred);
208212
})
209213
.collect(Collectors.toList());
210214
}
@@ -227,13 +231,14 @@ public void updateCommentContent(Long commentId, Map<String, String> contents) {
227231
comment.updateContent(content);
228232
}
229233

230-
//
231234
@Override
232235
@Transactional(readOnly = true)
233236
public List<CommentPairVo> findByApplicantId(String applicantId) {
234237
Long idpId = SecurityUtils.getCurrentUserId();
238+
Interviewer interviewer = interviewerLoadPort.loadInterviewById(idpId);
235239
List<Comment> comments = commentLoadPort.findByApplicantId(applicantId);
236-
return getCommentPairVo(idpId, comments);
240+
241+
return getCommentPairVo(idpId, comments, isAdminRole(interviewer));
237242
}
238243

239244
@Override
@@ -248,4 +253,9 @@ public void deleteCommentByCardId(Long cardId) {
248253
commentLikeLoadPort.findByCommentIds(
249254
comments.stream().map(Comment::getId).collect(Collectors.toList())));
250255
}
256+
257+
private boolean isAdminRole(Interviewer interviewer) {
258+
return interviewer.getRole() == Role.ROLE_OPERATION
259+
|| interviewer.getRole() == Role.ROLE_PRESIDENT;
260+
}
251261
}

server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/comment/adaptor/CommentAdapter.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ public List<Comment> findByApplicantId(String applicantId) {
7070
return comments;
7171
}
7272

73+
@Override
74+
public List<Comment> findByApplicantIdAndIdpId(String applicantId, Long idpId) {
75+
List<Comment> comments = commentRepository.findByApplicantIdAndIdpId(applicantId, idpId);
76+
if (comments.isEmpty()) {
77+
return Collections.emptyList();
78+
}
79+
return comments;
80+
}
81+
7382
@Override
7483
public CommentLike saveCommentLike(CommentLike commentLike) {
7584
return commentLikeRepository.save(commentLike);

server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/comment/domain/CommentRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public interface CommentRepository extends JpaRepository<Comment, Long> {
1313

1414
List<Comment> findByApplicantId(String applicantId);
1515

16+
List<Comment> findByApplicantIdAndIdpId(String applicantId, Long idpId);
17+
1618
@Modifying
1719
@Query("delete from Comment c where c.idpId = :idpId")
1820
void deleteByIdpId(@Param("idpId") Long idpId);

server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/domains/dto/CommentPairVo.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@ public class CommentPairVo {
1515
private Boolean isLike;
1616
private Integer likeCount;
1717
private Boolean canEdit;
18+
private Boolean isBlurred;
1819

1920
public static CommentPairVo of(
20-
Comment comment, Boolean isLike, String interviewerName, Boolean canEdit) {
21+
Comment comment, Boolean isLike, String interviewerName, Boolean canEdit, Boolean isBlurred) {
2122
return CommentPairVo.builder()
2223
.id(comment.getId())
2324
.createdAt(String.valueOf(Timestamp.valueOf(comment.getCreatedAt()).getTime()))
24-
.content(comment.getContent())
25+
.content(isBlurred ? "자신의 댓글만 조회할 수 있습니다." : comment.getContent())
2526
.isLike(isLike)
2627
.likeCount(comment.getLikeCount())
2728
.interviewerName(interviewerName)
2829
.canEdit(canEdit)
30+
.isBlurred(isBlurred)
2931
.build();
3032
}
3133
}
34+

server/Recruit-Domain/src/main/java/com/econovation/recruitdomain/out/CommentLoadPort.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public interface CommentLoadPort {
1111
List<Comment> findByCardId(Long cardId);
1212

1313
List<Comment> findByApplicantId(String applicantId);
14+
15+
List<Comment> findByApplicantIdAndIdpId(String applicantId, Long idpId);
1416
}

0 commit comments

Comments
 (0)