From a585d4dc8f284e6283d35b553dcba923a4398b03 Mon Sep 17 00:00:00 2001 From: Yoon-Jemin Date: Tue, 20 Feb 2024 00:41:56 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=B9=9C=ED=95=9C=20=EC=B9=9C=EA=B5=AC?= =?UTF-8?q?=20=ED=95=B4=EC=A0=9C=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umcproject/entity/MemberMission.java | 4 +++- .../umcproject/entity/Mission.java | 5 ++++- .../FriendService/FriendCommandService.java | 2 ++ .../FriendCommandServiceImpl.java | 12 +++++++++++ .../MissionService/MissionCommandService.java | 2 ++ .../MissionCommandServiceImpl.java | 21 +++++++++++++++++++ .../web/controller/FriendController.java | 20 ++++++++++++++++++ 7 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/main/java/aromanticcat/umcproject/entity/MemberMission.java b/src/main/java/aromanticcat/umcproject/entity/MemberMission.java index c79d261..42bd024 100644 --- a/src/main/java/aromanticcat/umcproject/entity/MemberMission.java +++ b/src/main/java/aromanticcat/umcproject/entity/MemberMission.java @@ -19,7 +19,7 @@ public class MemberMission extends BaseEntity { @Setter @Enumerated(EnumType.STRING) - private MissionStatus missionStatus; // 미션 완료 여부 + private MissionStatus missionStatus = MissionStatus.NOT_STARTED; // 미션 완료 여부 @JoinColumn(name = "member_id") @ManyToOne(fetch = FetchType.LAZY) @@ -33,4 +33,6 @@ public void completeStep(){ stepsCompleted += 1; } + public void resetStep(){ stepsCompleted = 0; } + } diff --git a/src/main/java/aromanticcat/umcproject/entity/Mission.java b/src/main/java/aromanticcat/umcproject/entity/Mission.java index 2edd950..76e12aa 100644 --- a/src/main/java/aromanticcat/umcproject/entity/Mission.java +++ b/src/main/java/aromanticcat/umcproject/entity/Mission.java @@ -5,10 +5,13 @@ import javax.persistence.*; import io.swagger.models.auth.In; -import lombok.Getter; +import lombok.*; @Entity @Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class Mission extends BaseEntity { @Id diff --git a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandService.java b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandService.java index f87a511..e71580f 100644 --- a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandService.java +++ b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandService.java @@ -12,4 +12,6 @@ public interface FriendCommandService { void rejectFriendship(String userEmail, Long friendId); void setCloseFriend(String userEmail, Long friendId); + + void deleteCloseFriend(String userEmail, Long friendId); } diff --git a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandServiceImpl.java b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandServiceImpl.java index df23ebd..84cd1e7 100644 --- a/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandServiceImpl.java +++ b/src/main/java/aromanticcat/umcproject/service/FriendService/FriendCommandServiceImpl.java @@ -91,4 +91,16 @@ public void setCloseFriend(String userEmail, Long friendId) { friend.changeFriendStatus(FriendStatus.CLOSE_FRIEND); } + + @Override + @Transactional + public void deleteCloseFriend(String userEmail, Long friendId) { + + Member member = getMember(userEmail); + + Friend friend = friendRepository.findByMemberAndFriendId(member, friendId); + + friend.changeFriendStatus(FriendStatus.APPROVED); + + } } diff --git a/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandService.java b/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandService.java index 6f32657..56f1e45 100644 --- a/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandService.java +++ b/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandService.java @@ -4,4 +4,6 @@ public interface MissionCommandService { void stepCompleted(String userEmail, Long missionId); + + void resetDailyMissions(); } diff --git a/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandServiceImpl.java b/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandServiceImpl.java index 24703cb..4db8874 100644 --- a/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandServiceImpl.java +++ b/src/main/java/aromanticcat/umcproject/service/MissionService/MissionCommandServiceImpl.java @@ -9,9 +9,12 @@ import aromanticcat.umcproject.repository.MemberRepository; import aromanticcat.umcproject.repository.MissionRepository; import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Service @RequiredArgsConstructor @Transactional(readOnly = true) @@ -53,4 +56,22 @@ public void stepCompleted(String userEmail, Long missionId) { // 미션 안 } } + @Override + @Transactional + @Scheduled(cron = "0 0 0 * * *") // 매일 자정에 실행되도록 설정 + public void resetDailyMissions() { + + List memberMissions = memberMissionRepository.findAll(); + + for (MemberMission memberMission : memberMissions) { + Mission mission = memberMission.getMission(); + if (mission.isEveryday()) { + memberMission.resetStep(); + memberMission.setMissionStatus(MissionStatus.NOT_STARTED); + // MemberMission 엔티티를 저장하여 변경 사항을 데이터베이스에 반영 + memberMissionRepository.save(memberMission); + } + } + } + } diff --git a/src/main/java/aromanticcat/umcproject/web/controller/FriendController.java b/src/main/java/aromanticcat/umcproject/web/controller/FriendController.java index 6561efe..adb9194 100644 --- a/src/main/java/aromanticcat/umcproject/web/controller/FriendController.java +++ b/src/main/java/aromanticcat/umcproject/web/controller/FriendController.java @@ -253,4 +253,24 @@ public ApiResponse registerCloseFriend(@RequestParam(value = "friend_id" } } + @PostMapping("/close-friend/delete") + @ApiOperation(value = "친한 친구 해제 API", notes = "query String으로 친한 친구를 해제하려는 친구 아이디를 알려주세요.") + @Parameters({ + @Parameter(name = "friend_id", description = "친한 친구를 해제하려는 친구의 아이디, query string입니다!") + }) + public ApiResponse deleteCloseFriend(@RequestParam(value = "friend_id") Long friendId) { + try { + String userEmail = memberService.getUserInfo().getEmail(); + + // 친한 친구 해제하기 + friendCommandService.deleteCloseFriend(userEmail, friendId); + + // 성공 응답 생성 + return ApiResponse.onSuccess("친한 친구를 해제하는데 성공했습니다."); + + } catch (Exception e) { + return ApiResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage(), null); + } + } + }