Skip to content

Commit

Permalink
Merge pull request #28 from CodingWasabi/feature-10/groupMember
Browse files Browse the repository at this point in the history
🔥[FEAT]-#10- party 에 참여한 회원 조회
  • Loading branch information
daehwan2yo authored Dec 28, 2021
2 parents 5c5decd + 65e2d1d commit cc9ee2e
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import com.codingwasabi.trti.domain.party.model.Party;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface MemberInPartyRepository extends JpaRepository<MemberInParty, Long> {
Integer countByParty(Party party);

List<MemberInParty> findAllByParty(Party party);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ public interface PartyAPI {
ResponseEntity<?> createParty(MemberAdaptor memberAdaptor, RequestCreatePartyDto requestDto);

ResponseEntity<?> getPartyInfo(MemberAdaptor memberAdaptor, Long id);

ResponseEntity<?> getPartyMemberList(MemberAdaptor memberAdaptor, Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import com.codingwasabi.trti.domain.party.model.request.RequestCreatePartyDto;
import com.codingwasabi.trti.domain.party.model.response.ResponseCreatePartyDto;
import com.codingwasabi.trti.domain.party.model.response.ResponsePartyInfoDto;
import com.codingwasabi.trti.domain.party.model.response.ResponsePartyMemberListDto;

public interface PartyService {
ResponseCreatePartyDto create(Member member, RequestCreatePartyDto requestDto);

ResponsePartyInfoDto getInfo(Member member, Long id);

ResponsePartyMemberListDto getMemberList(Member member, Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ public ResponseEntity<?> getPartyInfo(@AuthenticationPrincipal MemberAdaptor mem
@RequestParam(name = "id") Long id) {
return ResponseEntity.ok(partyService.getInfo(memberAdaptor.getMember(), id));
}

@Override
@GetMapping("/members")
public ResponseEntity<?> getPartyMemberList(@AuthenticationPrincipal MemberAdaptor memberAdaptor,
@RequestParam(name = "id") Long id) {
return ResponseEntity.ok(partyService.getMemberList(memberAdaptor.getMember(), id));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
import com.codingwasabi.trti.domain.party.model.Party;
import com.codingwasabi.trti.domain.party.model.request.RequestCreatePartyDto;
import com.codingwasabi.trti.domain.party.model.response.ResponseCreatePartyDto;
import com.codingwasabi.trti.domain.party.model.response.ResponseMemberDto;
import com.codingwasabi.trti.domain.party.model.response.ResponsePartyInfoDto;
import com.codingwasabi.trti.domain.party.model.response.ResponsePartyMemberListDto;
import com.codingwasabi.trti.domain.party.repository.PartyRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -49,11 +52,30 @@ public ResponsePartyInfoDto getInfo(Member member, Long id) {
Party party = partyRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("[ERROR] 해당 id의 Party는 존재하지 않습니다."));
ResponsePartyInfoDto responseDto = ResponsePartyInfoDto.from(party);
responseDto.setParticipantsCount( memberInPartyRepository.countByParty(party) );
responseDto.setParticipantsCount(memberInPartyRepository.countByParty(party));

return responseDto;
}

@Override
@Transactional(readOnly = true)
public ResponsePartyMemberListDto getMemberList(Member member, Long id) {
// 현재 로그인한 회원이 조회 권한이 있는지 확인 하는 검증 로직 구현해야함

// Error code 추가 해야함
Party party = partyRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("[ERROR] 해당 id의 Party는 존재하지 않습니다."));

List<MemberInParty> memberList = memberInPartyRepository.findAllByParty(party);

return ResponsePartyMemberListDto.of(
memberList.size(),
memberList.stream()
.map((memberInParty) -> ResponseMemberDto.from(memberInParty))
.collect(Collectors.toList())
);
}

private void setPartyCaptain(Member member, Party party) {
party.setCaptain(member);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.codingwasabi.trti.domain.party.model.response;

import com.codingwasabi.trti.domain.memberInParty.model.MemberInParty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor
public class ResponseMemberDto {
private String nickname;
private String imageUrl;

public static ResponseMemberDto from(MemberInParty memberInParty) {
return ResponseMemberDto.builder()
.nickname(memberInParty.getMember().getNickname())
.imageUrl(memberInParty.getMember().getImagePath())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.codingwasabi.trti.domain.party.model.response;

import com.codingwasabi.trti.domain.memberInParty.model.MemberInParty;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

@Getter
@AllArgsConstructor
public class ResponsePartyMemberListDto {
private Integer membersCount;
private List<ResponseMemberDto> members;

public static ResponsePartyMemberListDto of(int membersCount, List<ResponseMemberDto> members) {
return new ResponsePartyMemberListDto(membersCount, members);
}
}

0 comments on commit cc9ee2e

Please sign in to comment.