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 @@ -30,24 +30,32 @@ public class PotBadgeMemberController {
@GetMapping("/pots/{pot_id}")
public ResponseEntity<ApiResponse<List<PotBadgeMemberDto>>> getBadgeMembersByPotId(
@PathVariable("pot_id") Long potId) {

List<PotBadgeMemberDto> badgeMembers = potBadgeMemberService.getBadgeMembersByPotId(potId);
return ResponseEntity.ok(ApiResponse.onSuccess(badgeMembers));
}

@Operation(summary = "팟에서 가장 많은 `투두를 완료한' 멤버에게 뱃지 부여")
@Operation(summary = "팟에서 가장 많은 `투두를 완료한' 멤버에게 '할 일 정복자' 뱃지 부여")
@PostMapping("/{potId}")
@ApiErrorCodeExamples({
ErrorStatus.BADGE_NOT_FOUND,
ErrorStatus.BADGE_INSUFFICIENT_TODO_COUNTS,
ErrorStatus.POT_MEMBER_NOT_FOUND
})
public ResponseEntity<ApiResponse<Void>> assignBadgeToTopMembers(
@PathVariable Long potId) {
public ResponseEntity<ApiResponse<Void>> assignBadgeToTopMembers(@PathVariable Long potId) {
badgeService.assignBadgeToTopMembers(potId);
return ResponseEntity.ok(ApiResponse.onSuccess(null));
}


@Operation(summary = "전체 프로젝트 업무 수 대비 개인이 담당한 업무 수 비율이 큰 사람에게 '없어서는 안 될 능력자' 뱃지 부여")
@PostMapping("/{potId}/task-badge")
@ApiErrorCodeExamples({
ErrorStatus.BADGE_NOT_FOUND,
ErrorStatus.BADGE_INSUFFICIENT_TOP_MEMBERS,
ErrorStatus.POT_MEMBER_NOT_FOUND
})
public ResponseEntity<ApiResponse<Void>> assignTaskBadgeToTopMembers(@PathVariable Long potId) {
badgeService.assignTaskBadgeToTopMembers(potId);
return ResponseEntity.ok(ApiResponse.onSuccess(null));
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import stackpot.stackpot.badge.entity.Badge;

public interface BadgeService {
Badge getDefaultBadge();
Badge getBadge(Long badgeId);
void assignBadgeToTopMembers(Long potId);
void assignTaskBadgeToTopMembers(Long potId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import stackpot.stackpot.badge.repository.PotMemberBadgeRepository;
import stackpot.stackpot.pot.entity.mapping.PotMember;
import stackpot.stackpot.pot.repository.PotMemberRepository;
import stackpot.stackpot.task.service.TaskQueryService;
import stackpot.stackpot.todo.entity.enums.TodoStatus;
import stackpot.stackpot.todo.repository.UserTodoRepository;

Expand All @@ -29,12 +30,11 @@ public class BadgeServiceImpl implements BadgeService {
private final PotMemberRepository potMemberRepository;
private final PotMemberBadgeRepository potMemberBadgeRepository;
private final PotBadgeMemberConverter potBadgeMemberConverter;

private static final Long DEFAULT_BADGE_ID = 1L;
private final TaskQueryService taskQueryService;

@Override
public Badge getDefaultBadge() {
return badgeRepository.findBadgeByBadgeId(DEFAULT_BADGE_ID)
public Badge getBadge(Long badgeId) {
return badgeRepository.findBadgeByBadgeId(badgeId)
.orElseThrow(() -> new PotHandler(BADGE_NOT_FOUND));
}

Expand All @@ -57,10 +57,10 @@ public void assignBadgeToTopMembers(Long potId) {
List<PotMember> topPotMembers = topUserIds.stream()
.map(userId -> potMemberRepository.findByPot_PotIdAndUser_Id(potId, userId)
.orElseThrow(() -> new PotHandler(ErrorStatus.POT_MEMBER_NOT_FOUND)))
.collect(Collectors.toList());
.toList();

// 4. 기본 배지 부여
Badge badge = getDefaultBadge();
// 4. Todo 배지 부여
Badge badge = getBadge(1L);
for (PotMember potMember : topPotMembers) {
PotMemberBadge potMemberBadge = PotMemberBadge.builder()
.badge(badge)
Expand All @@ -69,5 +69,27 @@ public void assignBadgeToTopMembers(Long potId) {
potMemberBadgeRepository.save(potMemberBadge);
}
}

@Override
public void assignTaskBadgeToTopMembers(Long potId) {
List<Long> potMemberIds = potMemberRepository.selectPotMemberIdsByPotId(potId);
if (potMemberIds.isEmpty()) {
throw new PotHandler(ErrorStatus.POT_MEMBER_NOT_FOUND);
}

List<PotMember> top2PotMembers = taskQueryService.getTop2TaskCountByPotMemberId(potMemberIds);
if (top2PotMembers.size() < 2) {
throw new PotHandler(ErrorStatus.BADGE_INSUFFICIENT_TOP_MEMBERS);
}

Badge badge = getBadge(2L);
for (PotMember potMember : top2PotMembers) {
PotMemberBadge potMemberBadge = PotMemberBadge.builder()
.badge(badge)
.potMember(potMember)
.build();
potMemberBadgeRepository.save(potMemberBadge);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public class FeedCommentConverter {
public FeedCommentResponseDto.AllFeedCommentDto toAllFeedCommentDto(FeedCommentDto.FeedCommentInfoDto dto, Long currentUserId) {
return FeedCommentResponseDto.AllFeedCommentDto.builder()
.userId(dto.getUserId())
.userName(dto.getUserName() + " " + dto.getRole().getVegetable())
.role(dto.getRole())
.userName(dto.getUserName() + " 새싹")
.isCommentWriter(Objects.equals(dto.getUserId(), currentUserId))
.isFeedWriter(Objects.equals(dto.getFeedWriterId(), dto.getUserId()))
.commentId(dto.getCommentId())
Expand All @@ -30,26 +29,24 @@ public FeedCommentResponseDto.AllFeedCommentDto toAllFeedCommentDto(FeedCommentD
.build();
}

public FeedCommentResponseDto.FeedCommentCreateDto toFeedCommentCreateDto(Long userId, String userName, Role role, Boolean isWriter,
public FeedCommentResponseDto.FeedCommentCreateDto toFeedCommentCreateDto(Long userId, String userName, Boolean isWriter,
Long commentId, String comment, LocalDateTime createdAt) {
return FeedCommentResponseDto.FeedCommentCreateDto.builder()
.userId(userId)
.userName(userName)
.role(role)
.userName(userName + " 새싹")
.isWriter(isWriter)
.commentId(commentId)
.comment(comment)
.createdAt(createdAt)
.build();
}

public FeedCommentResponseDto.FeedReplyCommentCreateDto toFeedReplyCommentCreateDto(Long userId, String userName, Role role, Boolean isWriter,
public FeedCommentResponseDto.FeedReplyCommentCreateDto toFeedReplyCommentCreateDto(Long userId, String userName, Boolean isWriter,
Long commentId, String comment, Long parentCommentId,
LocalDateTime createdAt) {
return FeedCommentResponseDto.FeedReplyCommentCreateDto.builder()
.userId(userId)
.userName(userName)
.role(role)
.userName(userName + " 새싹")
.isWriter(isWriter)
.commentId(commentId)
.comment(comment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class FeedCommentDto {
public static class FeedCommentInfoDto {
private Long userId;
private String userName;
private Role role;
private Long feedWriterId; // Feed 작성자
private Long commentId;
private String comment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
public class FeedCommentInfoDto {
private Long userId;
private String userName;
private Role role;
private Long feedWriterId;
private Long commentId;
private String comment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class FeedCommentResponseDto {
public static class AllFeedCommentDto {
private Long userId;
private String userName;
private Role role;
private Boolean isCommentWriter;
private Boolean isFeedWriter;
private Long commentId;
Expand All @@ -35,7 +34,6 @@ public static class AllFeedCommentDto {
public static class FeedCommentCreateDto {
private Long userId;
private String userName;
private Role role;
private Boolean isWriter;
private Long commentId;
private String comment;
Expand All @@ -49,7 +47,6 @@ public static class FeedCommentCreateDto {
public static class FeedReplyCommentCreateDto {
private Long userId;
private String userName;
private Role role;
private Boolean isWriter;
private Long commentId;
private String comment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ public interface FeedCommentRepository extends JpaRepository<FeedComment, Long>
@Query("select fc from FeedComment fc where fc.id = :commentId")
Optional<FeedComment> findByCommentId(@Param("commentId") Long commentId);

@Query("select new stackpot.stackpot.feed.dto.FeedCommentInfoDto(fc.user.id, fc.user.nickname, fc.user.role, " +
@Query("select new stackpot.stackpot.feed.dto.FeedCommentDto$FeedCommentInfoDto(fc.user.id, fc.user.nickname, " +
"fc.feed.user.id, fc.id, fc.comment, fc.parent.id, fc.createdAt) " +
"from FeedComment fc where fc.feed.feedId = :feedId")
List<FeedCommentDto.FeedCommentInfoDto> findAllCommentInfoDtoByFeedId(@Param("feedId") Long feedId);

@Query("SELECT COUNT(fc) FROM FeedComment fc WHERE fc.feed.feedId = :feedId")
Long countByFeedId(@Param("feedId") Long feedId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public boolean toggleLike(Long feedId) {
FeedLike savedFeedLike = feedLikeRepository.save(feedLike);

NotificationResponseDto.UnReadNotificationDto dto = notificationCommandService.createFeedLikeNotification(
feed.getFeedId(), savedFeedLike.getLikeId(), user.getId(), user.getRole());
feed.getFeedId(), savedFeedLike.getLikeId(), user.getId());

applicationEventPublisher.publishEvent(new FeedLikeEvent(feed.getUser().getUserId(), dto));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public FeedCommentResponseDto.FeedCommentCreateDto createFeedComment(FeedComment
Boolean isWriter = Objects.equals(user.getId(), feed.getUser().getUserId());

NotificationResponseDto.UnReadNotificationDto dto = notificationCommandService.createdFeedCommentNotification(
feedId, feedComment.getId(), user.getId(), user.getRole());
feedId, feedComment.getId(), user.getId());

applicationEventPublisher.publishEvent(new FeedCommentEvent(feed.getUser().getUserId(), null, dto));

return feedCommentConverter.toFeedCommentCreateDto(user.getUserId(), user.getNickname(), user.getRole(), isWriter,
return feedCommentConverter.toFeedCommentCreateDto(user.getUserId(), user.getNickname(), isWriter,
feedComment.getId(), comment, feedComment.getCreatedAt());
}

Expand All @@ -73,11 +73,11 @@ public FeedCommentResponseDto.FeedReplyCommentCreateDto createFeedReplyComment(L
Boolean isWriter = Objects.equals(user.getId(), feed.getUser().getUserId());

NotificationResponseDto.UnReadNotificationDto dto = notificationCommandService.createdFeedCommentNotification(
feedId, feedComment.getId(), user.getId(), user.getRole());
feedId, feedComment.getId(), user.getId());

applicationEventPublisher.publishEvent(new FeedCommentEvent(feed.getUser().getUserId(), parent.getUser().getUserId(), dto));

return feedCommentConverter.toFeedReplyCommentCreateDto(user.getUserId(), user.getNickname(), user.getRole(), isWriter,
return feedCommentConverter.toFeedReplyCommentCreateDto(user.getUserId(), user.getNickname(), isWriter,
feedComment.getId(), comment, parent.getId(), feedComment.getCreatedAt());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,19 @@ public NotificationResponseDto.UnReadNotificationDto toUnReadNotificationDto(Not
return NotificationResponseDto.UnReadNotificationDto.builder()
.notificationId(unReadNotificationDto.getNotificationId())
.potOrFeedId(unReadNotificationDto.getPotOrFeedId())
.role(unReadNotificationDto.getRole())
.userName(unReadNotificationDto.getUserName() + " " + unReadNotificationDto.getRole().getVegetable())
.userName(unReadNotificationDto.getUserName() + " 새싹")
.type(unReadNotificationDto.getType())
.content(unReadNotificationDto.getContent())
.createdAt(unReadNotificationDto.getCreatedAt().format(DATE_FORMATTER))
.build();
}

public NotificationResponseDto.UnReadNotificationDto toUnReadNotificationDto(
Long notificationId, Long potOrFeedId, Role role, String userName, String type, String content, LocalDateTime createdAt) {
Long notificationId, Long potOrFeedId, String userName, String type, String content, LocalDateTime createdAt) {
return NotificationResponseDto.UnReadNotificationDto.builder()
.notificationId(notificationId)
.potOrFeedId(potOrFeedId)
.role(role)
.userName(userName + " " + role.getVegetable())
.userName(userName + " 새싹")
.type(type)
.content(content)
.createdAt(createdAt.format(DATE_FORMATTER))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class NotificationDto {
public static class UnReadNotificationDto {
private Long notificationId;
private Long potOrFeedId;
private Role role;
private String userName;
private String type;
private String content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class NotificationResponseDto {
public static class UnReadNotificationDto {
private Long notificationId;
private Long potOrFeedId;
private Role role;
private String userName;
private String type;
private String content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public interface FeedCommentNotificationRepository extends JpaRepository<FeedCommentNotification, Long> {

@Query("SELECT new stackpot.stackpot.notification.dto.NotificationDto$UnReadNotificationDto(" +
"fcn.id, fcn.feedComment.feed.feedId, fcn.feedComment.user.role," +
"fcn.id, fcn.feedComment.feed.feedId, " +
"fcn.feedComment.user.nickname, 'FeedComment', fcn.feedComment.comment, fcn.createdAt) " +
"FROM FeedCommentNotification fcn " +
"WHERE fcn.isRead = false AND (" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public interface FeedLikeNotificationRepository extends JpaRepository<FeedLikeNotification, Long> {

@Query("SELECT new stackpot.stackpot.notification.dto.NotificationDto$UnReadNotificationDto(" +
"fln.id, fln.feedLike.feed.feedId, fln.feedLike.user.role," +
"fln.id, fln.feedLike.feed.feedId, " +
"fln.feedLike.user.nickname, 'FeedLike', null, fln.createdAt) " +
"FROM FeedLikeNotification fln " +
"WHERE fln.isRead = false and fln.feedLike.feed.user.id = :userId ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public interface PotApplicationNotificationRepository extends JpaRepository<PotApplicationNotification, Long> {

@Query("SELECT new stackpot.stackpot.notification.dto.NotificationDto$UnReadNotificationDto(" +
"pan.id, pan.potApplication.pot.potId, pan.potApplication.user.role, pan.potApplication.user.nickname, " +
"pan.id, pan.potApplication.pot.potId, pan.potApplication.user.nickname, " +
"'PotApplication', null, pan.createdAt) " +
"FROM PotApplicationNotification pan " +
"WHERE pan.isRead = false AND pan.potApplication.pot.user.id = :userId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public interface PotCommentNotificationRepository extends JpaRepository<PotCommentNotification, Long> {

@Query("SELECT new stackpot.stackpot.notification.dto.NotificationDto$UnReadNotificationDto(" +
"pcn.id, pcn.potComment.pot.potId, pcn.potComment.user.role, " +
"pcn.id, pcn.potComment.pot.potId, " +
"pcn.potComment.user.nickname, 'PotComment', pcn.potComment.comment, pcn.createdAt) " +
"FROM PotCommentNotification pcn " +
"WHERE pcn.isRead = false AND (" +
Expand Down
Loading