-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df0f299
commit da9f3cb
Showing
7 changed files
with
110 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/meltingpot/server/domain/repository/PartyRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/meltingpot/server/party/controller/PartyController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
35
src/main/java/meltingpot/server/party/dto/PartyResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
src/main/java/meltingpot/server/party/service/PartyService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters