Skip to content

Commit

Permalink
πŸ”₯[FEAT]-#10- νŒŒν‹° 정보 쑰회 κ΅¬ν˜„
Browse files Browse the repository at this point in the history
## κ°œμš”
νŒŒν‹° 정보 쑰회 κ΅¬ν˜„
  • Loading branch information
daehwan2yo committed Dec 28, 2021
1 parent 13647f5 commit d04776d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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<MemberInParty, Long> {
Integer countByParty(Party party);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

public interface PartyAPI {
ResponseEntity<?> createParty(MemberAdaptor memberAdaptor, RequestCreatePartyDto requestDto);

ResponseEntity<?> getPartyInfo(MemberAdaptor memberAdaptor, Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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] λ„μ‹œμ˜ 정보가 μ‘΄μž¬ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.")));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit d04776d

Please sign in to comment.