Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 약속 참여 가능자 목록 API 구현 #103

Merged
merged 3 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.kkumulkkum.server.annotation.IsParticipant;
import org.kkumulkkum.server.annotation.UserId;
import org.kkumulkkum.server.dto.participant.request.PreparationInfoDto;
import org.kkumulkkum.server.dto.participant.response.AvailableParticipantsDto;
import org.kkumulkkum.server.dto.participant.response.LateComersDto;
import org.kkumulkkum.server.dto.participant.response.ParticipantsDto;
import org.kkumulkkum.server.dto.participant.response.PreparationStatusDto;
Expand Down Expand Up @@ -61,6 +62,15 @@ public ResponseEntity<ParticipantsDto> getParticipants(
return ResponseEntity.ok().body(participantService.getParticipants(promiseId));
}

@IsParticipant(promiseIdParamIndex = 1)
@GetMapping("/v1/promises/{promiseId}/members")
public ResponseEntity<AvailableParticipantsDto> getAvailableParticipants(
@UserId final Long userId,
@PathVariable("promiseId") final Long promiseId
) {
return ResponseEntity.ok().body(participantService.getAvailableParticipants(userId, promiseId));
}

@PatchMapping("/v1/promises/{promiseId}/times")
public ResponseEntity<Void> inputPreparationInfo(
@UserId final Long userId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.kkumulkkum.server.dto.participant.response;

import org.kkumulkkum.server.dto.member.response.MemberDto;

import java.util.List;
public record AvailableParticipantsDto(
List<AvailableParticipantDto> members
) {
public static AvailableParticipantsDto of(List<MemberDto> members, List<Long> participantIds) {
List<AvailableParticipantDto> participantDtos = members.stream()
.map(member -> new AvailableParticipantDto(
member.memberId(),
member.name(),
member.profileImg(),
//모임 내 멤버가 약속 참여중인 멤버 리스트 안에 있으면 true, 아니면 false
participantIds.contains(member.memberId())
)).toList();
return new AvailableParticipantsDto(participantDtos);
}

public record AvailableParticipantDto(
Long memberId,
String name,
String profileImg,
boolean isParticipant
) {
public static AvailableParticipantDto of(Long memberId, String name, String profileImg, boolean isParticipant) {
return new AvailableParticipantDto(
memberId,
name,
profileImg,
isParticipant
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ SELECT CASE WHEN EXISTS (
JOIN Promise p ON p.meeting.id = mt.id
WHERE p.id = :promiseId AND u.id = :userId""")
Member findByUserIdAndPromiseId(Long userId, Long promiseId);

@Query("""
SELECT new org.kkumulkkum.server.dto.member.response.MemberDto
(m.id, ui.name, ui.profileImg)
FROM Member m
JOIN m.meeting mt
JOIN FETCH UserInfo ui ON m.user.id = ui.user.id
JOIN Promise p ON p.meeting.id = mt.id
WHERE p.id = :promiseId""")
List<MemberDto> findAllByPromiseId(Long promiseId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,8 @@ public Member findByUserIdAndPromiseId(
) {
return memberRepository.findByUserIdAndPromiseId(userId, promiseId);
}

public List<MemberDto> findAllByPromiseId(final Long promiseId) {
return memberRepository.findAllByPromiseId(promiseId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.kkumulkkum.server.domain.Member;
import org.kkumulkkum.server.domain.Participant;
import org.kkumulkkum.server.domain.Promise;
import org.kkumulkkum.server.dto.member.response.MemberDto;
import org.kkumulkkum.server.dto.participant.ParticipantStatusUserInfoDto;
import org.kkumulkkum.server.dto.participant.request.PreparationInfoDto;
import org.kkumulkkum.server.dto.participant.response.*;
Expand All @@ -12,6 +14,7 @@
import org.kkumulkkum.server.external.FcmService;
import org.kkumulkkum.server.external.dto.FcmMessageDto;
import org.kkumulkkum.server.external.enums.FcmContent;
import org.kkumulkkum.server.service.member.MemberRetreiver;
import org.kkumulkkum.server.service.promise.PromiseRetriever;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -30,6 +33,7 @@ public class ParticipantService {
private final ParticipantRetriever participantRetriever;
private final ParticipantEditor participantEditor;
private final PromiseRetriever promiseRetriever;
private final MemberRetreiver memberRetreiver;
private final ParticipantRemover participantRemover;
private final FcmService fcmService;

Expand Down Expand Up @@ -107,6 +111,25 @@ public ParticipantsDto getParticipants(final Long promiseId) {
return ParticipantsDto.from(sortedParticipants);
}

@Transactional(readOnly = true)
public AvailableParticipantsDto getAvailableParticipants(
final Long userId,
final Long promiseId
) {
//모임 내 멤버 목록
List<MemberDto> members = memberRetreiver.findAllByPromiseId(promiseId);
//나 제외
Member authenticatedMember = memberRetreiver.findByUserIdAndPromiseId(userId, promiseId);
members.removeIf(member -> member.memberId().equals(authenticatedMember.getId()));

//약속에 참여 중인 멤버 id들 가져오기
List<Long> participantIds = participantRetriever.findAllByPromiseId(promiseId).stream()
.map(participant -> participant.getMember().getId())
.toList();

return AvailableParticipantsDto.of(members, participantIds);
}

@Transactional
public void insertPreparationInfo(
final Long userId,
Expand Down
Loading