Skip to content

Commit

Permalink
Merge pull request #184 from a-romantic-cat/feat/27
Browse files Browse the repository at this point in the history
feat: 친한 친구 해제 API 추가
  • Loading branch information
Yoon-Jemin authored Feb 19, 2024
2 parents c794f67 + a585d4d commit b8bebfd
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -33,4 +33,6 @@ public void completeStep(){
stepsCompleted += 1;
}

public void resetStep(){ stepsCompleted = 0; }

}
5 changes: 4 additions & 1 deletion src/main/java/aromanticcat/umcproject/entity/Mission.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

public interface MissionCommandService {
void stepCompleted(String userEmail, Long missionId);

void resetDailyMissions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -53,4 +56,22 @@ public void stepCompleted(String userEmail, Long missionId) { // 미션 안
}
}

@Override
@Transactional
@Scheduled(cron = "0 0 0 * * *") // 매일 자정에 실행되도록 설정
public void resetDailyMissions() {

List<MemberMission> 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);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,24 @@ public ApiResponse<String> 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<String> 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);
}
}

}

0 comments on commit b8bebfd

Please sign in to comment.