Skip to content

Commit

Permalink
Merge pull request #31 from umc-5th-hackathon-team-I/feature/#21
Browse files Browse the repository at this point in the history
Feat: 친구 미션 조회 API 구현
  • Loading branch information
Jeongmin39 authored Jan 2, 2024
2 parents df22567 + 0bee44c commit 55dd1ab
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.teami.domain.friend.controller.dto.response.FriendCalendarInfo;
import com.teami.domain.friend.controller.dto.response.FriendListResponse;
import com.teami.domain.friend.controller.dto.response.FriendMissionInfo;
import com.teami.domain.friend.service.FriendService;
import com.teami.global.apiPayload.ApiResponse;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -40,4 +41,11 @@ public ApiResponse<FriendCalendarInfo> getFriendCalendarInfo(@RequestParam Long
FriendCalendarInfo response = friendService.getCalendarInfo(memberId, friendMemberId);
return ApiResponse.onSuccess(response);
}

// 친구 미션 조회
@GetMapping("/{friendMemberId}/mission")
public ApiResponse<FriendMissionInfo> getFriendMissionList(@RequestParam Long memberId, @PathVariable Long friendMemberId) {
FriendMissionInfo response = friendService.getMissionInfo(memberId, friendMemberId);
return ApiResponse.onSuccess(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.teami.domain.friend.controller.dto.response;

import com.teami.domain.calendar.entitty.CalendarMission;
import lombok.Builder;

import java.util.List;

@Builder
public record FriendMissionInfo(
Long memberId,
Long friendMemberId,
List<CalendarMission> missionContentList
) {
}
17 changes: 17 additions & 0 deletions src/main/java/com/teami/domain/friend/service/FriendService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.teami.domain.friend.service;

import com.teami.domain.calendar.entitty.Calendar;
import com.teami.domain.calendar.entitty.CalendarMission;
import com.teami.domain.calendar.repository.CalendarMissionRepository;
import com.teami.domain.calendar.repository.CalendarRepository;
import com.teami.domain.friend.controller.dto.response.FriendCalendarInfo;
import com.teami.domain.friend.controller.dto.response.FriendListResponse;
import com.teami.domain.friend.controller.dto.response.FriendMissionInfo;
import com.teami.domain.friend.entity.Friend;
import com.teami.domain.friend.repository.FriendRepository;
import com.teami.domain.member.entitty.Member;
Expand All @@ -14,6 +18,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -24,6 +29,7 @@ public class FriendService {
private final FriendRepository friendRepository;
private final MemberService memberService;
private final CalendarRepository calendarRepository;
private final CalendarMissionRepository calendarMissionRepository;

@Transactional
public Long createFriend(Long member1Id, Long member2Id) {
Expand Down Expand Up @@ -89,4 +95,15 @@ public FriendCalendarInfo getCalendarInfo(Long memberId, Long friendMemberId) {
Long calendarId = calendarRepository.findByMemberAndIsComplete(friendMember, false).get().getId();
return new FriendCalendarInfo(memberId, friendMemberId, calendarId);
}

public FriendMissionInfo getMissionInfo(Long memberId, Long friendMemberId) {
validateFriend(memberId, friendMemberId);
Member friendMember = memberService.findById(friendMemberId);

Optional<Calendar> calendar = calendarRepository.findByMemberAndIsComplete(friendMember, false);
List<CalendarMission> friendMissions = calendarMissionRepository.findAllByCalendarOrderByDate(calendar.get());

FriendMissionInfo friendMissionInfo = new FriendMissionInfo(memberId, friendMemberId, friendMissions);
return friendMissionInfo;
}
}

0 comments on commit 55dd1ab

Please sign in to comment.