diff --git a/src/main/java/com/codingwasabi/trti/domain/memberInParty/repository/MemberInPartyRepository.java b/src/main/java/com/codingwasabi/trti/domain/memberInParty/repository/MemberInPartyRepository.java index 39a8b17..c151f1f 100644 --- a/src/main/java/com/codingwasabi/trti/domain/memberInParty/repository/MemberInPartyRepository.java +++ b/src/main/java/com/codingwasabi/trti/domain/memberInParty/repository/MemberInPartyRepository.java @@ -1,7 +1,9 @@ package com.codingwasabi.trti.domain.memberInParty.repository; import com.codingwasabi.trti.domain.memberInParty.model.MemberInParty; +import com.codingwasabi.trti.domain.party.model.Party; import org.springframework.data.jpa.repository.JpaRepository; public interface MemberInPartyRepository extends JpaRepository { + Integer countByParty(Party party); } diff --git a/src/main/java/com/codingwasabi/trti/domain/party/PartyAPI.java b/src/main/java/com/codingwasabi/trti/domain/party/PartyAPI.java index ce550a3..95f5132 100644 --- a/src/main/java/com/codingwasabi/trti/domain/party/PartyAPI.java +++ b/src/main/java/com/codingwasabi/trti/domain/party/PartyAPI.java @@ -6,4 +6,6 @@ public interface PartyAPI { ResponseEntity createParty(MemberAdaptor memberAdaptor, RequestCreatePartyDto requestDto); + + ResponseEntity getPartyInfo(MemberAdaptor memberAdaptor, Long id); } diff --git a/src/main/java/com/codingwasabi/trti/domain/party/PartyService.java b/src/main/java/com/codingwasabi/trti/domain/party/PartyService.java index 27cf395..f02115c 100644 --- a/src/main/java/com/codingwasabi/trti/domain/party/PartyService.java +++ b/src/main/java/com/codingwasabi/trti/domain/party/PartyService.java @@ -3,7 +3,10 @@ import com.codingwasabi.trti.domain.member.model.entity.Member; 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; public interface PartyService { ResponseCreatePartyDto create(Member member, RequestCreatePartyDto requestDto); + + ResponsePartyInfoDto getInfo(Member member, Long id); } diff --git a/src/main/java/com/codingwasabi/trti/domain/party/implementation/PartyController.java b/src/main/java/com/codingwasabi/trti/domain/party/implementation/PartyController.java index 44edd25..065405c 100644 --- a/src/main/java/com/codingwasabi/trti/domain/party/implementation/PartyController.java +++ b/src/main/java/com/codingwasabi/trti/domain/party/implementation/PartyController.java @@ -7,10 +7,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @@ -24,4 +21,11 @@ public ResponseEntity createParty(@AuthenticationPrincipal MemberAdaptor memb @RequestBody RequestCreatePartyDto requestDto) { return ResponseEntity.ok(partyService.create(memberAdaptor.getMember(), requestDto)); } + + @Override + @GetMapping("/info") + public ResponseEntity getPartyInfo(@AuthenticationPrincipal MemberAdaptor memberAdaptor, + @RequestParam(name = "id") Long id) { + return ResponseEntity.ok(partyService.getInfo(memberAdaptor.getMember(), id)); + } } diff --git a/src/main/java/com/codingwasabi/trti/domain/party/implementation/PartyServiceImpl.java b/src/main/java/com/codingwasabi/trti/domain/party/implementation/PartyServiceImpl.java index 8182681..9aba510 100644 --- a/src/main/java/com/codingwasabi/trti/domain/party/implementation/PartyServiceImpl.java +++ b/src/main/java/com/codingwasabi/trti/domain/party/implementation/PartyServiceImpl.java @@ -10,6 +10,7 @@ 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.ResponsePartyInfoDto; import com.codingwasabi.trti.domain.party.repository.PartyRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -39,13 +40,27 @@ public ResponseCreatePartyDto create(Member member, RequestCreatePartyDto reques return ResponseCreatePartyDto.from(party); } + @Override + @Transactional(readOnly = true) + public ResponsePartyInfoDto getInfo(Member member, Long id) { + // 현재 로그인한 회원이 조회 권한이 있는지 확인 하는 검증 로직 구현해야함 + + // Error code 추가 해야함 + Party party = partyRepository.findById(id) + .orElseThrow(() -> new IllegalArgumentException("[ERROR] 해당 id의 Party는 존재하지 않습니다.")); + ResponsePartyInfoDto responseDto = ResponsePartyInfoDto.from(party); + responseDto.setParticipantsCount( memberInPartyRepository.countByParty(party) ); + + return responseDto; + } + private void setPartyCaptain(Member member, Party party) { party.setCaptain(member); } private void setPartyCity(RequestCreatePartyDto requestDto, Party party) { Location.parseName(requestDto.getLocation()); - party.setLocation(cityRepository + party.setCity(cityRepository .findByLocation(Location.parseName(requestDto.getLocation())) .orElseThrow(() -> new IllegalArgumentException("[ERROR] 도시의 정보가 존재하지 않습니다."))); } diff --git a/src/main/java/com/codingwasabi/trti/domain/party/model/response/ResponsePartyInfoDto.java b/src/main/java/com/codingwasabi/trti/domain/party/model/response/ResponsePartyInfoDto.java new file mode 100644 index 0000000..8d4f2ff --- /dev/null +++ b/src/main/java/com/codingwasabi/trti/domain/party/model/response/ResponsePartyInfoDto.java @@ -0,0 +1,32 @@ +package com.codingwasabi.trti.domain.party.model.response; + +import com.codingwasabi.trti.domain.party.model.Party; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Builder +@AllArgsConstructor +public class ResponsePartyInfoDto { + private Long id; + private String title; + private String location; + @Setter + private Integer participantsCount; + private String imageUrl; + private Boolean isAgreed; + private String[] period; + + public static ResponsePartyInfoDto from(Party party) { + return ResponsePartyInfoDto.builder() + .id(party.getId()) + .title(party.getTitle()) + .location(party.getCity().getLocation().getName()) + .imageUrl(party.getImageLink()) + .isAgreed(party.isAgreed()) + .period(party.getPeriod()) + .build(); + } +}