Skip to content

Commit

Permalink
feat : 파티 내용 조회 API를 추가하라
Browse files Browse the repository at this point in the history
  • Loading branch information
runasy-koonta committed May 26, 2024
1 parent df0f299 commit da9f3cb
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/main/java/meltingpot/server/domain/entity/Account.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package meltingpot.server.domain.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import lombok.*;
import jakarta.validation.constraints.NotNull;
import meltingpot.server.domain.entity.common.BaseEntity;
import org.hibernate.annotations.DynamicInsert;
Expand All @@ -18,7 +14,7 @@

@Getter
@Setter
@SuperBuilder
@Builder
@NoArgsConstructor
@AllArgsConstructor
@DynamicInsert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Party extends BaseEntity {
private int id;

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "party_owner")
private Account account;

Expand Down Expand Up @@ -58,5 +58,9 @@ public class Party extends BaseEntity {
private int partyMinParticipant;

@NotNull
private int partMaxParticipant;
private int partyMaxParticipant;

@NotNull
@Column(name = "part_max_participant", nullable = false)
private Integer partMaxParticipant;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package meltingpot.server.domain.repository;

import meltingpot.server.domain.entity.party.Party;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PartyRepository extends JpaRepository<Party, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package meltingpot.server.party.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import meltingpot.server.party.dto.PartyResponse;
import meltingpot.server.party.service.PartyService;
import meltingpot.server.util.ResponseCode;
import meltingpot.server.util.ResponseData;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.NoSuchElementException;

@RestController
@RequestMapping("/api/v1/party")
@RequiredArgsConstructor
public class PartyController {
private final PartyService partyService;

// Todo: 사용자 인증 추가
@GetMapping("/{partyId}")
@Operation(summary = "파티 정보 조회", description = "파티 ID를 통해 파티 정보를 불러옵니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "OK", description = "파티 정보 조회 성공"),
@ApiResponse(responseCode = "NOT_FOUND", description = "파티 정보를 찾을 수 없습니다")
})
public ResponseEntity<ResponseData<PartyResponse>> getParty(@PathVariable Long partyId) {
try {
return ResponseData.toResponseEntity(ResponseCode.PARTY_FETCH_SUCCESS, partyService.getParty(partyId));
} catch (NoSuchElementException e) {
return ResponseData.toResponseEntity(ResponseCode.PARTY_NOT_FOUND, null);
}
}
}
35 changes: 35 additions & 0 deletions src/main/java/meltingpot/server/party/dto/PartyResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package meltingpot.server.party.dto;

import lombok.Builder;
import meltingpot.server.domain.entity.party.Party;
import meltingpot.server.domain.entity.party.enums.PartyStatus;

@Builder
public record PartyResponse(
int id,
String ownerName,
String subject,
PartyStatus partyStatus,
String startTime,
String locationAddress,
String locationDetail,
Boolean locationReserved,
Boolean locationCanBeChanged,
int minParticipant,
int maxParticipant
) {
public static PartyResponse of(Party party) {
return PartyResponse.builder().id(party.getId())
.ownerName(party.getAccount().getName())
.subject(party.getPartySubject())
.partyStatus(party.getPartyStatus())
.startTime(party.getPartyStartTime().toString())
.locationAddress(party.getPartyLocationAddress())
.locationDetail(party.getPartyLocationDetail())
.locationReserved(party.getPartyLocationReserved())
.locationCanBeChanged(party.getPartyLocationCanBeChanged())
.minParticipant(party.getPartyMinParticipant())
.maxParticipant(party.getPartyMinParticipant())
.build();
}
}
19 changes: 19 additions & 0 deletions src/main/java/meltingpot/server/party/service/PartyService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package meltingpot.server.party.service;

import lombok.RequiredArgsConstructor;
import meltingpot.server.domain.repository.PartyRepository;
import meltingpot.server.party.dto.PartyResponse;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class PartyService {
private final PartyRepository partyRepository;

@Transactional
public PartyResponse getParty(Long partyId) {
return partyRepository.findById(partyId).map(PartyResponse::of).orElseThrow();
}
}
2 changes: 2 additions & 0 deletions src/main/java/meltingpot/server/util/ResponseCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum ResponseCode {
SIGNIN_SUCCESS(OK, "로그인 성공"),
SIGNOUT_SUCCESS(OK, "로그아웃 성공"),
REISSUE_TOKEN_SUCCESS(OK, "토큰 재발급 성공"),
PARTY_FETCH_SUCCESS(OK, "파티 정보 불러오기 성공"),


/* 201 CREATED : 요청 성공, 자원 생성 */
Expand Down Expand Up @@ -42,6 +43,7 @@ public enum ResponseCode {
/* 404 NOT_FOUND : Resource 를 찾을 수 없음 */
ACCOUNT_NOT_FOUND(NOT_FOUND, "계정 정보를 찾을 수 없습니다"),
REFRESH_TOKEN_NOT_FOUND(NOT_FOUND, "REFRESH 토큰 정보를 찾을 수 없습니다"),
PARTY_NOT_FOUND(NOT_FOUND, "파티 정보를 찾을 수 없습니다"),


/* 409 CONFLICT : Resource 의 현재 상태와 충돌. 보통 중복된 데이터 존재 */
Expand Down

0 comments on commit da9f3cb

Please sign in to comment.