Skip to content

Commit

Permalink
Merge pull request #309 from Modagbul/main
Browse files Browse the repository at this point in the history
v.1.0.10
  • Loading branch information
minsu20 authored Sep 8, 2024
2 parents c95ab51 + 88ccc3b commit fd62732
Show file tree
Hide file tree
Showing 29 changed files with 310 additions and 60 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ data.sql

firebase-key.json
apple-key.p8
logs/
2 changes: 2 additions & 0 deletions src/docs/asciidoc/AlarmHistory-API.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ operation::alarm-history-controller-test/get_all_alarm_history[snippets='http-re
| `REJECT_TEAM`
| 소모임 반려

| `COMMENT`
| 댓글 생성 알림
|===

[[AlarmHistory-알림-단건-조회하기]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.moing.backend.domain.history.application.dto.response.MemberIdAndToken;
import com.moing.backend.domain.history.application.dto.response.NewUploadInfo;
import com.moing.backend.domain.history.application.mapper.AlarmHistoryMapper;
import com.moing.backend.domain.history.domain.entity.AlarmType;
import com.moing.backend.domain.history.domain.entity.PagePath;
import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.domain.team.domain.entity.Team;
Expand All @@ -20,6 +19,7 @@
import java.util.List;
import java.util.Optional;

import static com.moing.backend.domain.history.domain.entity.AlarmType.NEW_UPLOAD;
import static com.moing.backend.global.config.fcm.constant.NewNoticeUploadMessage.NEW_NOTICE_UPLOAD_MESSAGE;

@Service
Expand All @@ -41,14 +41,15 @@ public void sendNewUploadAlarm(BaseServiceResponse baseServiceResponse, Board bo
Optional<List<MemberIdAndToken>> memberIdAndTokensByPush = AlarmHistoryMapper.getNewUploadPushInfo(newUploadInfos);
Optional<List<MemberIdAndToken>> memberIdAndTokensBySave = AlarmHistoryMapper.getNewUploadSaveInfo(newUploadInfos);
// 알림 보내기
eventPublisher.publishEvent(new MultiFcmEvent(title, body, memberIdAndTokensByPush, memberIdAndTokensBySave, createIdInfo(team.getTeamId(), board.getBoardId()), team.getName(), AlarmType.NEW_UPLOAD, PagePath.NOTICE_PATH.getValue()));
eventPublisher.publishEvent(new MultiFcmEvent(title, body, memberIdAndTokensByPush, memberIdAndTokensBySave, createIdInfo(team.getTeamId(), board.getBoardId()), team.getName(), NEW_UPLOAD, PagePath.NOTICE_PATH.getValue()));
}
}

private String createIdInfo(Long teamId, Long boardId) {
JSONObject jo = new JSONObject();
jo.put("teamId", teamId);
jo.put("boardId", boardId);
jo.put("type", "NEW_UPLOAD_BOARD");
return jo.toJSONString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class CreateBoardCommentUseCase {
private final BoardCommentSaveService boardCommentSaveService;
private final BaseBoardService baseBoardService;
private final CheckLeaderUseCase checkLeaderUseCase;
private final SendCommentAlarmUseCase sendCommentAlarmUseCase;
private final SendBoardCommentAlarmUseCase sendCommentAlarm;
/**
* 게시글 댓글 생성
*/
Expand All @@ -33,7 +33,7 @@ public CreateCommentResponse createBoardComment(String socialId, Long teamId, Lo
// 2. 게시글 댓글 개수 증가
data.getBoard().incrComNum();
// 3. 게시글 댓글 알림
sendCommentAlarmUseCase.sendNewUploadAlarm(data, boardComment);
sendCommentAlarm.sendCommentAlarm(data, boardComment);
return new CreateCommentResponse(boardComment.getBoardCommentId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
@Service
@RequiredArgsConstructor
@Transactional
public class SendCommentAlarmUseCase {
public class SendBoardCommentAlarmUseCase {

private final ApplicationEventPublisher eventPublisher;
private final BoardCommentGetService boardCommentGetService;

public void sendNewUploadAlarm(BaseBoardServiceResponse response, BoardComment comment) {
public void sendCommentAlarm(BaseBoardServiceResponse response, BoardComment comment) {
Member member = response.getMember();
Team team = response.getTeam();
Board board = response.getBoard();
Expand All @@ -50,21 +50,22 @@ private void sendBoardWriter(Board board, Member member, String title, String bo
Member receiver = board.getTeamMember().getMember();

if (checkBoardWriter(receiver, member, newUploadInfos)) {
eventPublisher.publishEvent(new SingleFcmEvent(receiver, title, body, createIdInfo(team.getTeamId(), board.getBoardId()), team.getName(), AlarmType.NEW_UPLOAD, PagePath.NOTICE_PATH.getValue(), receiver.isNewUploadPush()));
eventPublisher.publishEvent(new SingleFcmEvent(receiver, title, body, createIdInfo(team.getTeamId(), board.getBoardId()), team.getName(), AlarmType.COMMENT, PagePath.NOTICE_PATH.getValue(), receiver.isCommentPush()));
}
}

private void sendBoardCommentWriter(Board board, Member member, String title, String body, Team team, Optional<List<NewUploadInfo>> newUploadInfos) {
Optional<List<MemberIdAndToken>> memberIdAndTokensByPush = AlarmHistoryMapper.getNewUploadPushInfo(newUploadInfos);
Optional<List<MemberIdAndToken>> memberIdAndTokensBySave = AlarmHistoryMapper.getNewUploadSaveInfo(newUploadInfos);

eventPublisher.publishEvent(new MultiFcmEvent(title, body, memberIdAndTokensByPush, memberIdAndTokensBySave, createIdInfo(team.getTeamId(), board.getBoardId()), team.getName(), AlarmType.NEW_UPLOAD, PagePath.NOTICE_PATH.getValue()));
eventPublisher.publishEvent(new MultiFcmEvent(title, body, memberIdAndTokensByPush, memberIdAndTokensBySave, createIdInfo(team.getTeamId(), board.getBoardId()), team.getName(), AlarmType.COMMENT, PagePath.NOTICE_PATH.getValue()));
}

private String createIdInfo(Long teamId, Long boardId) {
JSONObject jo = new JSONObject();
jo.put("teamId", teamId);
jo.put("boardId", boardId);
jo.put("type", "COMMENT_BOARD");
return jo.toJSONString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Optional<List<NewUploadInfo>> findNewUploadInfo(Long memberId, Long board
List<NewUploadInfo> result = queryFactory.select(Projections.constructor(NewUploadInfo.class,
boardComment.teamMember.member.fcmToken,
boardComment.teamMember.member.memberId,
boardComment.teamMember.member.isNewUploadPush,
boardComment.teamMember.member.isCommentPush,
boardComment.teamMember.member.isSignOut))
.distinct()
.from(boardComment)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.moing.backend.domain.fire.application.dto.req;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Getter
public class FireThrowReq {

private String message;

@Builder
public FireThrowReq(String message) {
this.message = message;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.moing.backend.domain.fire.application.service;

import com.moing.backend.domain.history.domain.entity.AlarmType;
import com.moing.backend.domain.fire.application.dto.req.FireThrowReq;
import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.domain.mission.domain.entity.Mission;
import com.moing.backend.domain.mission.domain.entity.constant.MissionType;
Expand All @@ -14,6 +14,7 @@
import javax.transaction.Transactional;
import java.util.Random;

import static com.moing.backend.domain.history.domain.entity.AlarmType.FIRE;
import static com.moing.backend.domain.history.domain.entity.PagePath.MISSION_PATH;
import static com.moing.backend.global.config.fcm.constant.FireThrowMessage.*;

Expand All @@ -24,28 +25,31 @@ public class FireThrowAlarmUseCase {

private final ApplicationEventPublisher eventPublisher;

public void sendFireThrowAlarm(Member throwMember, Member receiveMember, Team team, Mission mission) {
public void sendFireThrowAlarm(Member throwMember, Member receiveMember, Team team, Mission mission, FireThrowReq fireThrowReq) {

Random random = new Random(System.currentTimeMillis());
int randomNum = random.nextInt(2);
int randomNum = new Random(System.currentTimeMillis()).nextInt(2);

String title = getTitle(throwMember.getNickName(), receiveMember.getNickName(), randomNum);
String message = getMessage(throwMember.getNickName(), receiveMember.getNickName(), randomNum);
String idInfo = createIdInfo(mission.getType() == MissionType.REPEAT, mission.getTeam().getTeamId(), mission.getId());
String title = fireThrowReq != null ? NEW_FIRE_THROW_TITLE_WITH_COMMENT.to(throwMember.getNickName())
: getRandomTitle(throwMember.getNickName(), receiveMember.getNickName(), randomNum);
String message = fireThrowReq != null ? fireThrowReq.getMessage()
: getRandomMessage(throwMember.getNickName(), receiveMember.getNickName(), randomNum);
String idInfo = createIdInfo(mission.getType() == MissionType.REPEAT, mission.getTeam().getTeamId(), mission.getId(), fireThrowReq == null);

eventPublisher.publishEvent(new SingleFcmEvent(receiveMember, title, message, idInfo, team.getName(), AlarmType.FIRE, MISSION_PATH.getValue(), receiveMember.isFirePush()));
eventPublisher.publishEvent(new SingleFcmEvent(receiveMember, title, message, idInfo, team.getName(), FIRE, MISSION_PATH.getValue(), receiveMember.isFirePush()));
}

public String getMessage(String pusher, String receiver, int num) {
public String getRandomMessage(String pusher, String receiver, int num) {

switch (num) {
case 0: return pusher + "님이 " + receiver + NEW_FIRE_THROW_MESSAGE1.getMessage();
case 1: return receiver + "님! " + pusher + NEW_FIRE_THROW_MESSAGE2.getMessage();
case 0:
return NEW_FIRE_THROW_MESSAGE1.fromTo(pusher, receiver);
case 1: return NEW_FIRE_THROW_MESSAGE2.toFrom(receiver, pusher);

}
return pusher + "님이" + receiver + NEW_FIRE_THROW_MESSAGE1.getMessage();
return NEW_FIRE_THROW_MESSAGE1.fromTo(pusher, receiver);
}

public String getTitle(String pusher, String receiver, int num) {
public String getRandomTitle(String pusher, String receiver, int num) {

switch (num) {
case 0:
Expand All @@ -56,13 +60,20 @@ public String getTitle(String pusher, String receiver, int num) {
return NEW_FIRE_THROW_TITLE1.getMessage();
}

private String createIdInfo(boolean isRepeated, Long teamId, Long missionId) {
private String createIdInfo(boolean isRepeated, Long teamId, Long missionId, boolean isMessageNull) {
JSONObject jo = new JSONObject();
jo.put("isRepeated", isRepeated);
jo.put("teamId", teamId);
jo.put("missionId", missionId);
jo.put("type", getType(isMessageNull));
return jo.toJSONString();
}

private String getType(boolean isMessageNull){
if(isMessageNull)
return "FIRE_MESSAGE_NULL";
return "FIRE_MESSAGE_EXIST";
}


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.moing.backend.domain.fire.application.service;

import com.moing.backend.domain.fire.application.dto.req.FireThrowReq;
import com.moing.backend.domain.fire.application.dto.res.FireReceiveRes;
import com.moing.backend.domain.fire.application.dto.res.FireThrowRes;
import com.moing.backend.domain.fire.application.mapper.FireMapper;
Expand All @@ -19,6 +20,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
@Transactional
Expand All @@ -33,7 +35,7 @@ public class FireThrowUseCase {
private final MissionQueryService missionQueryService;
private final TeamGetService teamGetService;

public FireThrowRes createFireThrow(String userId, Long receiveMemberId, Long missionId, Long teamId) {
public FireThrowRes createFireThrow(String userId, Long receiveMemberId, Long missionId, Long teamId, FireThrowReq fireThrowReq) {

Member throwMember = memberGetService.getMemberBySocialId(userId);
Member receiveMember = memberGetService.getMemberByMemberId(receiveMemberId);
Expand All @@ -50,12 +52,14 @@ public FireThrowRes createFireThrow(String userId, Long receiveMemberId, Long mi
throw new NoAuthThrowFireException();
}

fireThrowAlarmUseCase.sendFireThrowAlarm(throwMember, receiveMember, team, mission);
fireThrowAlarmUseCase.sendFireThrowAlarm(throwMember, receiveMember, team, mission, fireThrowReq);

return FireMapper.mapToFireThrowRes(fireSaveService.save(Fire.builder()
Fire save = fireSaveService.save(Fire.builder()
.throwMemberId(throwMember.getMemberId())
.receiveMemberId(receiveMemberId)
.build()));
.build());

return FireMapper.mapToFireThrowRes(fireSaveService.save(save));
}

public List<FireReceiveRes> getFireReceiveList(String userId,Long teamId, Long missionId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
@AllArgsConstructor
public class Fire extends BaseTimeEntity {


@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "fire_id")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.moing.backend.domain.fire.presentation;

import com.moing.backend.domain.fire.application.dto.req.FireThrowReq;
import com.moing.backend.domain.fire.application.dto.res.FireReceiveRes;
import com.moing.backend.domain.fire.application.dto.res.FireThrowRes;
import com.moing.backend.domain.fire.application.service.FireThrowUseCase;
Expand Down Expand Up @@ -30,8 +31,8 @@ public class FireController {

@PostMapping("/{receiveMemberId}")
public ResponseEntity<SuccessResponse<FireThrowRes>> throwFire (@AuthenticationPrincipal User user, @PathVariable("teamId") Long teamId,
@PathVariable("receiveMemberId") Long receiveMemberId, @PathVariable("missionId") Long missionId) {
return ResponseEntity.ok(SuccessResponse.create(THROW_FIRE_SUCCESS.getMessage(), this.fireThrowUseCase.createFireThrow(user.getSocialId(), receiveMemberId, missionId, teamId)));
@PathVariable("receiveMemberId") Long receiveMemberId, @PathVariable("missionId") Long missionId, @RequestBody(required = false) FireThrowReq fireThrowReq) {
return ResponseEntity.ok(SuccessResponse.create(THROW_FIRE_SUCCESS.getMessage(), this.fireThrowUseCase.createFireThrow(user.getSocialId(), receiveMemberId, missionId, teamId, fireThrowReq)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public enum AlarmType {
FIRE,
REMIND,
APPROVE_TEAM,
REJECT_TEAM
REJECT_TEAM,
COMMENT
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public class Member extends BaseTimeEntity {
@Column(nullable = false)
private boolean isFirePush;

@ColumnDefault("true")
@Column(nullable = false)
private boolean isCommentPush;

private boolean isDeleted;

private LocalDateTime lastSignInTime;
Expand Down Expand Up @@ -140,10 +144,15 @@ public void updateFirePush(boolean firePush) {
this.isFirePush = firePush;
}

public void updateCommentPush(boolean commentPush){
this.isCommentPush=commentPush;
}

public void updateAllPush(boolean allPush) {
this.isNewUploadPush = allPush;
this.isRemindPush = allPush;
this.isFirePush = allPush;
this.isCommentPush=allPush;
}

public void updateFcmToken(String fcmToken) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.moing.backend.domain.history.application.dto.response.MemberIdAndToken;
import com.moing.backend.domain.history.application.dto.response.NewUploadInfo;
import com.moing.backend.domain.history.application.mapper.AlarmHistoryMapper;
import com.moing.backend.domain.history.domain.entity.AlarmType;
import com.moing.backend.domain.history.domain.entity.PagePath;
import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.domain.mission.domain.entity.Mission;
Expand All @@ -21,6 +20,7 @@
import java.util.List;
import java.util.Optional;

import static com.moing.backend.domain.history.domain.entity.AlarmType.NEW_UPLOAD;
import static com.moing.backend.global.config.fcm.constant.NewMissionTitle.NEW_SINGLE_MISSION_COMING;

@Service
Expand All @@ -43,7 +43,7 @@ public void sendNewMissionUploadAlarm(Member member, Mission mission) {
Optional<List<MemberIdAndToken>> memberIdAndTokensByPush = AlarmHistoryMapper.getNewUploadPushInfo(newUploadInfos);
Optional<List<MemberIdAndToken>> memberIdAndTokensBySave = AlarmHistoryMapper.getNewUploadSaveInfo(newUploadInfos);
// 알림 보내기
eventPublisher.publishEvent(new MultiFcmEvent(title, message, memberIdAndTokensByPush, memberIdAndTokensBySave, createIdInfo(team.getTeamId(), mission.getId(),mission.getType(),mission.getStatus()), team.getName(), AlarmType.NEW_UPLOAD, PagePath.MISSION_PATH.getValue()));
eventPublisher.publishEvent(new MultiFcmEvent(title, message, memberIdAndTokensByPush, memberIdAndTokensBySave, createIdInfo(team.getTeamId(), mission.getId(),mission.getType(),mission.getStatus()), team.getName(), NEW_UPLOAD, PagePath.MISSION_PATH.getValue()));
}

private String createIdInfo(Long teamId, Long missionId,MissionType type, MissionStatus status) {
Expand All @@ -52,6 +52,7 @@ private String createIdInfo(Long teamId, Long missionId,MissionType type, Missio
jo.put("teamId", teamId);
jo.put("missionId", missionId);
jo.put("status", status.name());
jo.put("type", "NEW_UPLOAD_MISSION");
return jo.toJSONString();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.moing.backend.domain.missionArchive.application.service;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum MissionArchiveCreateMessage {

CREATOR_CREATE_MISSION_ARCHIVE("%s님이 미션을 인증했어요!"),
TEAM_AND_TITLE("[%s] %s");

private final String message;

public String to(String creator) {
return String.format(message, creator);
}

public String teamAndTitle(String team, String title) {
return String.format(message, team, title);
}
}
Loading

0 comments on commit fd62732

Please sign in to comment.