Skip to content

Commit

Permalink
Merge pull request #73 from Modagbul/feat/mission-closing
Browse files Browse the repository at this point in the history
feat/mission : 미션 관련 전반적인 버그 수정 및 기능 구현
  • Loading branch information
minsu20 authored Nov 14, 2023
2 parents 6b715b8 + c7edc26 commit 21b03ea
Show file tree
Hide file tree
Showing 30 changed files with 597 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ data.sql
#### docs ####
!**/src/main/resources/static/docs/
*.html
firebase-key.json

firebase-key.json
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-batch'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
Expand Down Expand Up @@ -90,6 +91,7 @@ dependencies {
implementation platform('software.amazon.awssdk:bom:2.17.230')
implementation 'software.amazon.awssdk:s3'


}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.moing.backend.domain.fire.application.service;

import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.global.config.fcm.dto.request.SingleRequest;
import com.moing.backend.global.config.fcm.service.FcmService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

import java.util.Random;

import static com.moing.backend.global.config.fcm.constant.FireThrowMessage.*;
import static java.lang.Math.random;

@Service
@Transactional
@RequiredArgsConstructor
public class FireThrowAlarmUseCase {

private final FcmService fcmService;

public void sendFireThrowAlarm(Member throwMember, Member receiveMember) {

Random random = new Random(System.currentTimeMillis());
String title = getTitle(throwMember.getNickName(), receiveMember.getNickName(), random.nextInt(2));

String message = getMessage(throwMember.getNickName(), receiveMember.getNickName(), random.nextInt(2));
SingleRequest singleRequest = new SingleRequest(receiveMember.getFcmToken(), title, message);

fcmService.sendSingleDevice(singleRequest);
}

public String getMessage(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();
}
return pusher + "님이" + receiver + NEW_FIRE_THROW_MESSAGE1.getMessage();
}

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

switch (num) {
case 0:
return NEW_FIRE_THROW_TITLE1.getMessage();
case 1:
return NEW_FIRE_THROW_TITLE2.getMessage();
}
return NEW_FIRE_THROW_TITLE1.getMessage();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
import com.moing.backend.domain.fire.application.dto.res.FireThrowRes;
import com.moing.backend.domain.fire.application.mapper.FireMapper;
import com.moing.backend.domain.fire.domain.entity.Fire;
import com.moing.backend.domain.fire.domain.repository.FireCustomRepository;
import com.moing.backend.domain.fire.domain.service.FireQueryService;
import com.moing.backend.domain.fire.domain.service.FireSaveService;
import com.moing.backend.domain.fire.exception.NoAuthThrowFireException;
import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.domain.member.domain.service.MemberGetService;
import com.moing.backend.domain.mission.application.service.MissionCreateUseCase;
import com.moing.backend.global.config.fcm.dto.request.SingleRequest;
import com.moing.backend.global.config.fcm.service.FcmService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static java.lang.Math.random;

@Service
@Transactional
@RequiredArgsConstructor
Expand All @@ -25,16 +28,27 @@ public class FireThrowUseCase {
public final FireQueryService fireQueryService;
private final MemberGetService memberGetService;

private final FireThrowAlarmUseCase fireThrowAlarmUseCase;

public FireThrowRes createFireThrow(String userId, Long receiveMemberId) {

Long throwMemberId = memberGetService.getMemberBySocialId(userId).getMemberId();
Member throwMember = memberGetService.getMemberBySocialId(userId);
Member receiveMember = memberGetService.getMemberByMemberId(receiveMemberId);

// 나에게 던질 수 없음
if (throwMember.equals(receiveMember)) {
throw new NoAuthThrowFireException();
}

if (!fireQueryService.hasFireCreatedWithinOneHour(throwMemberId, receiveMemberId)) {
// 1시간전 불 던진 기록이 있다면, 던질 수 없음
if (!fireQueryService.hasFireCreatedWithinOneHour(throwMember.getMemberId(), receiveMemberId)) {
throw new NoAuthThrowFireException();
}

fireThrowAlarmUseCase.sendFireThrowAlarm(throwMember, receiveMember);

return FireMapper.mapToFireThrowRes(fireSaveService.save(Fire.builder()
.throwMemberId(throwMemberId)
.throwMemberId(throwMember.getMemberId())
.receiveMemberId(receiveMemberId)
.build()));
}
Expand All @@ -49,4 +63,6 @@ public List<FireReceiveRes> getFireReceiveList(String userId,Long teamId, Long m

return fireReceiveRes;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface MemberRepository extends JpaRepository<Member, Long>, MemberCus

Optional<Member> findByEmail(String email);

Optional<Member> findByMemberId(Long id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ public class MemberGetService {
public Member getMemberBySocialId(String socialId){
return memberRepository.findBySocialId(socialId).orElseThrow(()->new NotFoundBySocialIdException());
}

public Member getMemberByMemberId(Long memberId) {
return memberRepository.findByMemberId(memberId).orElseThrow(()->new NotFoundBySocialIdException());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import com.moing.backend.domain.team.domain.entity.Team;
import com.moing.backend.domain.team.domain.repository.TeamRepository;
import com.moing.backend.domain.team.domain.service.TeamGetService;
import com.moing.backend.global.config.fcm.dto.request.MultiRequest;
import com.moing.backend.global.config.fcm.dto.request.SingleRequest;
import com.moing.backend.global.config.fcm.service.FcmService;
import com.moing.backend.global.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -31,6 +34,7 @@ public class MissionCreateUseCase {
private final MissionQueryService missionQueryService;
private final TeamGetService teamGetService;
private final MemberGetService memberGetService;
private final SendMissionCreateAlarmUseCase sendMissionCreateAlarmUseCase;

public MissionCreateRes createMission(String userSocialId, Long teamId, MissionReq missionReq) {

Expand All @@ -39,23 +43,27 @@ public MissionCreateRes createMission(String userSocialId, Long teamId, MissionR

// 소모임 장 확인
if (member.getMemberId().equals(team.getLeaderId())) {
Mission mission = MissionMapper.mapToMission(missionReq, member, MissionStatus.ONGOING);
Mission mission = MissionMapper.mapToMission(missionReq, member, MissionStatus.WAIT);
// teamRepository 변경 예정

if (mission.getType() == MissionType.REPEAT && missionQueryService.isAbleCreateRepeatMission(team.getTeamId())) {
throw new NoMoreCreateMission();
}
mission.setTeam(team);
missionSaveService.save(mission);

// 단일 미션 최초 1회 알림
if (mission.getType().equals(MissionType.ONCE)) {
sendMissionCreateAlarmUseCase.sendNewMissionUploadAlarm(member, mission);
}

return MissionMapper.mapToMissionCreateRes(mission);
}
else{
throw new NoAccessCreateMission();
}




}

public MissionRecommendRes getCategoryByTeam(Long teamId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.moing.backend.domain.mission.application.service;

import com.moing.backend.domain.mission.domain.entity.Mission;
import com.moing.backend.global.config.fcm.dto.request.MultiRequest;
import com.moing.backend.global.config.fcm.service.FcmService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

import java.util.Random;

import static com.moing.backend.global.config.fcm.constant.RemindMissionTitle.*;
import static java.lang.Math.random;

@Service
@Transactional
@RequiredArgsConstructor
public class MissionRemindAlarmUseCase {

private final FcmService fcmService;

public void sendRemindMissionAlarm(Mission mission) {

Random random = new Random(System.currentTimeMillis());

String title = getTitle("receiver",random.nextInt(4));
String message = getMessage(mission.getTitle(),random.nextInt(4));

MultiRequest multiRequest = new MultiRequest();
}

public String getTitle(String receiver, int num) {
switch (num) {
case 0:
return receiver + REMIND_MISSION_TITLE1.getMessage();
case 1:
return receiver + REMIND_MISSION_TITLE2.getMessage();
case 2:
return receiver + REMIND_MISSION_TITLE3.getMessage();
case 3:
return receiver + REMIND_MISSION_TITLE4.getMessage();
}
return receiver + REMIND_MISSION_TITLE4.getMessage();

}
public String getMessage(String missionTitle, int num) {
switch (num) {
case 0:
return missionTitle + REMIND_MISSION_MESSAGE1.getMessage();
case 1:
return missionTitle + REMIND_MISSION_MESSAGE2.getMessage();
case 2:
return missionTitle + REMIND_MISSION_MESSAGE3.getMessage();
case 3:
return missionTitle + REMIND_MISSION_MESSAGE4.getMessage();
}
return missionTitle + REMIND_MISSION_MESSAGE4.getMessage();

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//package com.moing.backend.domain.mission.application.service;
//
//import com.moing.backend.domain.mission.domain.entity.Mission;
//import com.moing.backend.domain.missionState.domain.entity.MissionState;
//import com.moing.backend.domain.missionState.domain.service.MissionStateDeleteService;
//import com.moing.backend.domain.teamScore.application.service.TeamScoreLogicUseCase;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.batch.core.Job;
//import org.springframework.batch.core.Step;
//import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
//import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
//import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
//import org.springframework.batch.core.configuration.annotation.StepScope;
//import org.springframework.batch.item.ItemProcessor;
//import org.springframework.batch.item.database.JpaItemWriter;
//import org.springframework.batch.item.database.JpaPagingItemReader;
//import org.springframework.batch.item.database.builder.JpaItemWriterBuilder;
//import org.springframework.batch.item.database.builder.JpaPagingItemReaderBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import javax.persistence.EntityManagerFactory;
//import java.util.HashMap;
//import java.util.Map;
//
//@Slf4j
//@Configuration
//@EnableBatchProcessing
//@RequiredArgsConstructor
//public class MissionStateTerminateBatchConfig {
//
// private final JobBuilderFactory jobBuilderFactory;
// private final StepBuilderFactory stepBuilderFactory;
// private final EntityManagerFactory entityManagerFactory;
//
// private final TeamScoreLogicUseCase teamScoreLogicUseCase;
// private final MissionStateDeleteService missionStateDeleteService;
//
// @Bean
// public Job missionTerminateJob() {
// return jobBuilderFactory.get("missionTerminateJob")
// .start(missionTerminateStep())
// .build();
// }
//
// @Bean
// public Step missionTerminateStep() {
// return stepBuilderFactory.get("missionTerminateStep")
// .<Mission, Mission>chunk(10)
// .reader(missionReader())
// .processor(missionProcessor())
// .writer(missionWriter())
// .reader(missionStateReader())
// .processor(missionStateProcessor())
// .writer(missionStateWriter())
// .build();
// }
//
// @Bean
// @StepScope
// public JpaPagingItemReader<Mission,MissionState> missionStateReader() {
//
// Map<String,Object> parameterValues = new HashMap<>();
// parameterValues.put("missionId", 10000);
//
// .parameterValues(parameterValues) // 쿼리 파라미터 설정
//
// return new JpaPagingItemReaderBuilder<MissionState>()
// .name("missionStateReader")
// .entityManagerFactory(entityManagerFactory)
// .queryString("SELECT m FROM MissionState m WHERE m.mission_id = :missionId")
// .pageSize(10)
// .build();
// }
//
// @Bean
// public ItemProcessor<Mission, Mission> missionStateProcessor() {
// return mission -> {
// teamScoreLogicUseCase.updateTeamScore(mission.getId());
// return mission;
// };
// }
//
//
//
// @Bean
// public JpaItemWriter<Mission> missionStateWriter() {
// return new JpaItemWriterBuilder<Mission>()
// .entityManagerFactory(entityManagerFactory)
// .build();
// }
//
//
//
//}
Loading

0 comments on commit 21b03ea

Please sign in to comment.