Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix notification bugs #869

Merged
merged 3 commits into from
Feb 18, 2024
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
2 changes: 1 addition & 1 deletion private-resources
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import peer.backend.entity.user.User;
import peer.backend.exception.BadRequestException;
import peer.backend.service.board.recruit.RecruitService;
import peer.backend.service.noti.NotificationCreationService;

import javax.validation.Valid;
import java.util.List;
Expand All @@ -28,6 +29,7 @@
public class RecruitController {

private final RecruitService recruitService;
private final NotificationCreationService notificationCreationService;

@ApiOperation(value = "", notes = "모집게시글을 불러온다.")
@GetMapping("/{recruit_id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import peer.backend.dto.board.team.*;
import peer.backend.dto.noti.enums.NotificationPriority;
import peer.backend.dto.noti.enums.NotificationType;
import peer.backend.entity.board.team.Post;
import peer.backend.entity.board.team.enums.BoardType;
import peer.backend.entity.user.User;
import peer.backend.service.board.team.BoardService;
Expand Down Expand Up @@ -94,22 +95,23 @@ public List<PostCommentListResponse> getShowcaseComments(@PathVariable Long show
}
}

//TODO : DTO 수정 필요...!!
@PostMapping("/comment")
public void createShowcaseComment(@RequestBody @Valid PostCommentRequest request, Authentication auth){
User user = User.authenticationToUser(auth);
boardService.createComment(
Post data = boardService.createComment(
request.getPostId(),
request.getContent(),
user,
BoardType.SHOWCASE);
this.notificationCreationService.makeNotificationForTeam(
null,
user.getNickname() + "님께서 코멘트를 다셨습니다. : " + request.getContent(),
user.getNickname() + "님께서 "+ data.getTitle() +" 에 댓글을 다셨습니다 : " + request.getContent(),
"/showcase/detail/" + request.getPostId(),
NotificationPriority.IMMEDIATE,
NotificationType.SYSTEM,
null,
request.getTeamId(),
data.getOwnTeamId(),
null
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public interface TeamUserRepository extends JpaRepository<TeamUser, Long> {
@Query("SELECT m.userId FROM TeamUser m WHERE m.teamId IN :teamId AND m.user.activated = true")
List<Long> findAllUserIdsIn(@Param("teamId") List<Long> teamId);

@Query("SELECT m.userId FROM TeamUser m WHERE m.teamId = :teamId AND m.user.activated = true")
@Query("SELECT m.userId FROM TeamUser m WHERE m.teamId = :teamId AND m.status = 'APPROVED'")
List<Long> findUserIdsIn(@Param("teamId") Long teamId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,27 @@ public interface UserRepository extends JpaRepository<User, Long> {
@Query("SELECT CASE WHEN COUNT(n) > 0 THEN true ELSE false END FROM User n WHERE n.nickname = :nickname")
Boolean existsByNickname(String nickname);

@Modifying
@Query("UPDATE User m SET m.alarmCounter = m.alarmCounter + 1")
void increaseAlarmCountForALL();

@Modifying
@Query("UPDATE User m SET m.alarmCounter = CASE WHEN (m.alarmCounter - 1) < 0 then 0 ELSE (m.alarmCounter - 1) END")
void decreaseAlarmCountForALL();

@Query("UPDATE User m SET m.alarmCounter = m.alarmCounter + 1 WHERE m.id IN : userIds AND m.activated = true")
@Modifying
@Query("UPDATE User m SET m.alarmCounter = m.alarmCounter + 1, m.newAlarmCounter = m.newAlarmCounter + 1 WHERE m.id IN :userIds AND m.activated = true")
void increaseAlarmCountForUsers(@Param("userIds") List<Long> userIds);

@Modifying
@Query("UPDATE User m SET m.alarmCounter = m.alarmCounter + 1, m.newAlarmCounter = m.newAlarmCounter + 1 WHERE m.id = :userId AND m.activated = true")
void increaseAlarmCountForOne(@Param("userId") Long userId);

@Modifying
@Query("UPDATE User m SET m.alarmCounter = CASE WHEN (m.alarmCounter - 1) < 0 then 0 ELSE (m.alarmCounter - 1) END WHERE m.id IN :userIds")
void decreaseAlarmCountForUsers(@Param("userIds") List<Long> userIds);

@Modifying
@Query("UPDATE User m SET m.alarmCounter = CASE WHEN (m.alarmCounter - 1) < 0 then 0 ELSE (m.alarmCounter - 1) END WHERE m.id = :userId")
void decreaseAlarmCountForOne(@Param("userId") Long userId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
Expand Down Expand Up @@ -88,6 +89,9 @@ public class RecruitService {
private final EntityManager entityManager;
private final NotificationCreationService notificationCreationService;

private static final String teamPage = "/teams/";
private static final String teamList = "/team-list";

//query 생성 및 주입
@PersistenceContext
private EntityManager em;
Expand All @@ -106,14 +110,18 @@ public void changeRecruitFavorite(Authentication auth, Long recruitId,
throw new NotFoundException("존재하지 않는 모집글입니다.");
}

AtomicBoolean likeOrHate = new AtomicBoolean(false);

recruitFavoriteRepository.findById(new RecruitFavoritePK(user.getId(), recruitId))
.ifPresentOrElse(
favorite -> {
if (favorite.getType().equals(type)) {
recruitFavoriteRepository.delete(favorite);
likeOrHate.set(false);
} else {
favorite.setType(type);
recruitFavoriteRepository.save(favorite);
likeOrHate.set(true);
}
},
() -> {
Expand All @@ -122,14 +130,15 @@ public void changeRecruitFavorite(Authentication auth, Long recruitId,
newFavorite.setRecruitId(recruitId);
newFavorite.setType(type);
recruitFavoriteRepository.save(newFavorite);
likeOrHate.set(true);
});
if (rawTarget.get().getWriter().isActivated())
if (rawTarget.get().getWriter().isActivated() && likeOrHate.get())
this.notificationCreationService.makeNotificationForUser(
null,
user.getNickname() + "님께서 당신의 글에 좋아요를 눌렀습니다",
user.getNickname() + "님께서 당신의 " + rawTarget.get().getTitle() + " 글에 좋아요를 눌렀습니다",
"/recruit/" + recruitId,
NotificationPriority.IMMEDIATE,
NotificationType.TEAM,
NotificationType.SYSTEM,
null,
rawTarget.get().getWriterId(),
rawTarget.get().getThumbnailUrl()
Expand Down Expand Up @@ -451,6 +460,30 @@ public void applyRecruit(Long recruit_id, ApplyRecruitRequest request, Authentic
.status(TeamUserStatus.PENDING)
.answers(request.getAnswerList())
.build());

// 신청자를 위한 알림
this.notificationCreationService.makeNotificationForUser(
null,
"축하드립니다! " + team.getName()
+ " 팀에 신청을 완료하였습니다. 답변이 올 때까지 기다려볼까요? 궁금한 것은 팀장에게 메시지를 날려보아도 좋습니다!",
teamList,
NotificationPriority.IMMEDIATE,
NotificationType.SYSTEM,
null,
user.getId(),
null
);

this.notificationCreationService.makeNotificationForTeam(
null,
team.getName() + " 팀에 새로운 동료가 접수되었습니다! 확인 하러 가시죠!",
teamPage + team.getId(),
NotificationPriority.IMMEDIATE,
NotificationType.SYSTEM,
null,
team.getId(),
null
);
}

@Transactional
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/peer/backend/service/board/team/ShowcaseService.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public boolean doFavorite(Long showcaseId, Authentication auth) {
// 관심리스트에 추가 됨을 알림
this.notificationCreationService.makeNotificationForTeam(
null,
showcase.getTitle() + " 쇼케이스가 누군가의 관심리스트에 등록되었습니다!",
showcase.getTitle() + " 누군가의 관심리스트에 등록되었습니다!",
detailPage + showcase.getId(),
NotificationPriority.IMMEDIATE,
NotificationType.SYSTEM,
Expand All @@ -145,9 +145,13 @@ public int doLike(Long showcaseId, Authentication auth) {
.orElseThrow(() -> new NotFoundException("존재하지 않는 모집글입니다."));
Optional<PostLike> postLike = postLikeRepository.findById(
new PostLikePK(user.getId(), showcaseId, PostLikeType.LIKE));

boolean likeOrHate;

if (postLike.isPresent()) {
postLikeRepository.delete(postLike.get());
showcase.decreaseLike();
likeOrHate = false;
} else {
PostLike newFavorite = new PostLike();
newFavorite.setUser(user);
Expand All @@ -157,18 +161,21 @@ public int doLike(Long showcaseId, Authentication auth) {
newFavorite.setType(PostLikeType.LIKE);
postLikeRepository.save(newFavorite);
showcase.increaseLike();
likeOrHate = true;
}

this.notificationCreationService.makeNotificationForTeam(
null,
showcase.getTitle() + " 쇼케이스가 좋아요를 받았습니다! 확인해보시겠어요?",
detailPage + showcase.getId(),
NotificationPriority.IMMEDIATE,
NotificationType.SYSTEM,
null,
showcase.getOwnTeamId(),
null
);
if (likeOrHate) {
this.notificationCreationService.makeNotificationForTeam(
null,
showcase.getTitle() + " 가 좋아요를 받았습니다! 확인해보시겠어요?",
detailPage + showcase.getId(),
NotificationPriority.IMMEDIATE,
NotificationType.SYSTEM,
null,
showcase.getOwnTeamId(),
null
);
}

return showcase.getLiked();
}
Expand Down Expand Up @@ -259,7 +266,7 @@ public Long createShowcase(ShowcaseCreateDto request, Authentication auth) {

this.notificationCreationService.makeNotificationForTeam(
null,
post.getTitle() + " 쇼케이스가 등록 되었습니다! 한 번 확인하러 가볼까요?",
post.getTitle() + " 등록 되었습니다! 한 번 확인하러 가볼까요?",
detailPage + post.getId(),
NotificationPriority.IMMEDIATE,
NotificationType.SYSTEM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ public void makeNotificationForTeam(@Nullable String title,
@NotNull Long teamId,
@Nullable String imageLink) {
List<Long> targetUsers = this.makeUserListFromTeamId(teamId);

targetUsers.forEach(m-> System.out.println("나오나? : " + m.toString()));

this.makeNotificationForUserList(
title,
body,
Expand Down
61 changes: 22 additions & 39 deletions src/main/java/peer/backend/service/team/TeamService.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ public void updateTeamSetting(Long teamId, TeamSettingInfoDto teamSettingInfoDto

this.notificationCreationService.makeNotificationForTeam(
null,
"팀 설정이 변경되었습니다. 확인 부탁드립니다.",
teamPage + teamId,
team.getName() + " 팀 상태가 변경되었습니다. 확인 해볼까요? 자세한 내용은 리더들에게 확인해보세요.",
teamList,
NotificationPriority.IMMEDIATE,
NotificationType.TEAM,
null,
Expand Down Expand Up @@ -339,36 +339,6 @@ public List<TeamApplicantListDto> getTeamApplicantList(Long teamId, User user) {
.image(applicantUser.getImageUrl())
.build());
}

// 신청자를 위한 알림
this.notificationCreationService.makeNotificationForUser(
null,
"축하드립니다! " + team.getName()
+ " 팀에 신청을 완료하였습니다. 답변이 올 때까지 기다려볼까요? 궁금한 것은 팀장에게 메시지를 날려보아도 좋습니다!",
teamList,
NotificationPriority.IMMEDIATE,
NotificationType.SYSTEM,
null,
user.getId(),
null
);

//팀리더에게 알림
List<TeamUser> owner = team.getTeamUsers().stream()
.filter(m -> m.getRole().equals(TeamUserRoleType.LEADER)).collect(Collectors.toList());
List<Long> userIds = new ArrayList<>();
owner.forEach(m -> userIds.add(m.getUserId()));
this.notificationCreationService.makeNotificationForUserList(
null,
team.getName() + " 팀에 새로운 동료 신청이 들어왔습니다! 어떤 분인지 맞이하러 가볼까요?",
teamPage + team.getId() + "/setting",
NotificationPriority.IMMEDIATE,
NotificationType.TEAM,
null,
userIds,
team.getTeamLogoPath()
);

return result;
}

Expand All @@ -384,6 +354,8 @@ public void acceptTeamApplicant(Long teamId, TeamUserJobPK teamUserJobId, User u
Team team = this.teamRepository.findById(teamId).orElseThrow(
() -> new NotFoundException("존재하지 않는 팀입니다.")
);

Long targetId = teamUserJob.getTeamUser().getUser().getId();
// 신청자에게 알리기
this.notificationCreationService.makeNotificationForUser(
null,
Expand All @@ -392,17 +364,28 @@ public void acceptTeamApplicant(Long teamId, TeamUserJobPK teamUserJobId, User u
NotificationPriority.IMMEDIATE,
NotificationType.SYSTEM,
null,
user.getId(),
targetId,
null
);
this.notificationCreationService.makeNotificationForTeam(
null,

List<Long> userIds = new ArrayList<>();
team.getTeamUsers().forEach(m -> {
if (m.getStatus().equals(TeamUserStatus.APPROVED)) {
if (!m.getUserId().equals(targetId)){
userIds.add(m.getUserId());
}
}
}
);

this.notificationCreationService.makeNotificationForUserList(
null,
"여러분 새로운 동료가 찾아왔습니다. 모두 축하해주세요!",
teamPage + teamId,
NotificationPriority.IMMEDIATE,
NotificationType.TEAM,
null,
teamId,
userIds,
team.getTeamLogoPath()
);
}
Expand All @@ -424,12 +407,12 @@ public void rejectTeamApplicant(Long teamId, TeamUserJobPK applicantId, User use
// 신청자에게 알림 보냄
this.notificationCreationService.makeNotificationForUser(
null,
"안타깝게도 지원이 거절 당했습니다. 팀 페이지에서 자세한 내용을 확인해주세요.",
"안타깝게도 " + teamUser.getTeam().getName() +" 팀에 대한 지원이 거절 당했습니다. 팀 페이지에서 자세한 내용을 확인해주세요.",
teamList,
NotificationPriority.IMMEDIATE,
NotificationType.SYSTEM,
null,
user.getId(),
teamUser.getUserId(),
null
);
}
Expand Down Expand Up @@ -685,7 +668,7 @@ public Team disperseTeam(User user, Long teamId) {

this.notificationCreationService.makeNotificationForTeam(
null,
team.getName() + " 팀이 해산되었슴을 알립니다.",
team.getName() + " 팀이 해산되었습니다.",
teamList,
NotificationPriority.IMMEDIATE,
NotificationType.SYSTEM,
Expand Down
Loading