Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: http 문서 작성 #172

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions api/api-event/http/event-hall.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
### 공연장 생성
POST http://localhost:8080/api/v1/event-halls
Content-Type: application/json

{
"name" : "잠실 종합운동장",
"address" : "서울특별시 송파구",
"eventHallSeatCreateRequests" : [
{
"name": "1A"
},
{
"name": "2A"
},
{
"name": "1B"
},
{
"name": "1Z"
}
]
}

### 공연장 일괄 조회
GET http://localhost:8080/api/v1/event-halls

### 공연장 단일 조회
GET http://localhost:8080/api/v1/event-halls/2
55 changes: 55 additions & 0 deletions api/api-event/http/event-seat.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
### 공연 좌석 구역 생성
POST http://localhost:8080/api/v1/events/1/seat-area
Content-Type: application/json

{
"requests" :
[
{
"seatAreaType" : "R",
"price" : 1000
},
{
"seatAreaType" : "S",
"price" : 2000
}
]
}

### 공연 좌석 생성
POST http://localhost:8080/api/v1/event-seats/events/1
Content-Type: application/json

[
{
"name" : "1A",
"status": "AVAILABLE",
"eventSeatAreaId" : 3
},
{
"name" : "1B",
"status": "AVAILABLE",
"eventSeatAreaId" : 3
},
{
"name": "2A",
"status": "AVAILABLE",
"eventSeatAreaId": 3
},
{
"name" : "1A",
"status": "AVAILABLE",
"eventSeatAreaId" : 4
},
{
"name" : "1B",
"status": "AVAILABLE",
"eventSeatAreaId" : 4
}
]

### 공연 회차 좌석 목록 조회
GET http://localhost:8080/api/v1/event-seats/event-times/1

### 공연 회차 등급별 남은 좌석 수 조회
GET http://localhost:8080/api/v1/event-seats/event-times/1/available-numbers
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package com.pgms.apievent.eventHall.dto.response;

import java.util.List;

import com.pgms.coredomain.domain.event.EventHall;

import lombok.Builder;

import java.util.List;

@Builder
public record EventHallResponse(Long id, String name, String address, List<EventHallSeatResponse> eventHallSeatResponses) {
static public EventHallResponse of(EventHall eventHall){
List<EventHallSeatResponse> eventHallSeatResponses = eventHall.getEventHallSeats().stream()
.map(EventHallSeatResponse::of)
.toList();

static public EventHallResponse of(EventHall eventHall, List<EventHallSeatResponse> eventHallSeatResponses){
return EventHallResponse.builder()
.id(eventHall.getId())
.name(eventHall.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.pgms.apievent.eventHall.dto.request.EventHallUpdateRequest;
import com.pgms.apievent.eventHall.dto.request.EventHallSeatCreateRequest;
import com.pgms.apievent.eventHall.dto.response.EventHallResponse;
import com.pgms.apievent.eventHall.dto.response.EventHallSeatResponse;
import com.pgms.apievent.exception.EventHallNotFoundException;
import com.pgms.coredomain.domain.event.EventHall;
import com.pgms.coredomain.domain.event.EventHallEdit;
Expand Down Expand Up @@ -35,7 +36,14 @@ public EventHallResponse createEventHall(EventHallCreateRequest eventHallCreateR
.eventHallSeats(eventHallSeats)
.build();

return EventHallResponse.of(eventHallRepository.save(eventHall));
EventHall savedEventHall = eventHallRepository.save(eventHall);

List<EventHallSeatResponse> eventHallSeatResponses = savedEventHall.getEventHallSeats()
.stream()
.map(EventHallSeatResponse::of)
.toList();

return EventHallResponse.of(savedEventHall, eventHallSeatResponses);
}

public void deleteEventHall(Long id) {
Expand All @@ -62,21 +70,32 @@ public EventHallResponse updateEventHall(Long id, EventHallUpdateRequest eventHa

eventHall.updateEventHall(eventHallEdit);

return EventHallResponse.of(eventHall);
List<EventHallSeatResponse> eventHallSeatResponses = eventHall.getEventHallSeats()
.stream()
.map(EventHallSeatResponse::of)
.toList();

return EventHallResponse.of(eventHall, eventHallSeatResponses);
}

@Transactional(readOnly = true)
public EventHallResponse getEventHall(Long id) {
EventHall eventHall = eventHallRepository.findById(id).orElseThrow(EventHallNotFoundException::new);

return EventHallResponse.of(eventHall);
// TODO 못 읽어옴
List<EventHallSeatResponse> eventHallSeatResponses = eventHall.getEventHallSeats()
.stream()
.map(EventHallSeatResponse::of)
.toList();

return EventHallResponse.of(eventHall, eventHallSeatResponses);
}

@Transactional(readOnly = true)
public List<EventHallResponse> getEventHalls() {
List<EventHall> eventHalls = eventHallRepository.findAll();
return eventHalls.stream()
.map(EventHallResponse::of)
.map(eventHall -> EventHallResponse.of(eventHall, null))
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public ResponseEntity<Void> deleteEventSeats(@RequestParam List<Long> ids) {
return ResponseEntity.noContent().build();
}

@GetMapping("/event-time/{id}/seats")
@GetMapping("/event-times/{id}")
public ResponseEntity<ApiResponse> getEventSeatsByEventTime(@PathVariable Long id){
List<EventSeatResponse> responses = eventSeatService.getEventSeatsByEventTime(id);
return ResponseEntity.ok(ApiResponse.ok(responses));
}

@GetMapping("/event-time/{id}/available-numbers")
@GetMapping("/event-times/{id}/available-numbers")
public ResponseEntity<ApiResponse> getLeftEventSeatNumberByEventTime(@PathVariable Long id){
List<LeftEventSeatResponse> responses = eventSeatService.getLeftEventSeatNumberByEventTime(id);
return ResponseEntity.ok(ApiResponse.ok(responses));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.pgms.apievent.eventSeat.dto.request;

import com.pgms.coredomain.domain.event.EventSeatArea;
import com.pgms.coredomain.domain.event.EventSeatStatus;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

public record EventSeatsCreateRequest(@NotBlank(message = "공연장 좌석은 빈칸을 지정할 수 없습니다.")
@Size(max = 10, message = "공연장 좌석은 10자 이내로 입력해주세요.") String name,
EventSeatStatus status,
EventSeatArea eventSeatArea) {
Long eventSeatAreaId) {
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.pgms.apievent.eventSeat.dto.response;

import com.pgms.apievent.eventSeatArea.dto.response.EventSeatAreaResponse;
import com.pgms.coredomain.domain.event.EventSeat;
import com.pgms.coredomain.domain.event.EventSeatArea;
import com.pgms.coredomain.domain.event.EventSeatStatus;

public record EventSeatResponse(Long id,
String name,
EventSeatStatus status,
EventSeatArea eventSeatArea) {
EventSeatAreaResponse eventSeatAreaResponse) {
public static EventSeatResponse of(EventSeat eventSeat){
return new EventSeatResponse(eventSeat.getId(),
eventSeat.getName(),
eventSeat.getStatus(),
eventSeat.getEventSeatArea());
EventSeatAreaResponse.of(eventSeat.getEventSeatArea()));
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
package com.pgms.apievent.eventSeat.service;

import static com.pgms.apievent.exception.EventErrorCode.*;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.pgms.apievent.eventSeat.dto.request.EventSeatsCreateRequest;
import com.pgms.apievent.eventSeat.dto.response.EventSeatResponse;
import com.pgms.apievent.eventSeat.dto.response.LeftEventSeatResponse;
import com.pgms.apievent.eventSeat.repository.EventSeatCustomRepository;
import com.pgms.apievent.exception.CustomException;
import com.pgms.apievent.exception.EventSeatAreaNotFoundException;
import com.pgms.coredomain.domain.event.Event;
import com.pgms.coredomain.domain.event.EventSeat;
import com.pgms.coredomain.domain.event.EventSeatArea;
import com.pgms.coredomain.domain.event.EventSeatStatus;
import com.pgms.coredomain.domain.event.EventTime;
import com.pgms.coredomain.domain.event.*;
import com.pgms.coredomain.domain.event.repository.EventRepository;
import com.pgms.coredomain.domain.event.repository.EventSeatAreaRepository;
import com.pgms.coredomain.domain.event.repository.EventSeatRepository;
import com.pgms.coredomain.domain.event.repository.EventTimeRepository;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.pgms.apievent.exception.EventErrorCode.EVENT_NOT_FOUND;
import static com.pgms.apievent.exception.EventErrorCode.EVENT_TIME_NOT_FOUND;

@Service
@RequiredArgsConstructor
Expand All @@ -44,12 +39,18 @@ public void createEventSeats(Long id, List<EventSeatsCreateRequest> eventSeatsCr
.map(eventTime ->
eventSeatsCreateRequests
.stream()
.map(request -> EventSeat.builder()
.eventTime(eventTime)
.status(request.status())
.eventSeatArea(request.eventSeatArea())
.name(request.name())
.build())
.map(request -> {
EventSeatArea eventSeatArea = eventSeatAreaRepository
.findById(request.eventSeatAreaId())
.orElseThrow(EventSeatAreaNotFoundException::new);

return EventSeat.builder()
.eventTime(eventTime)
.status(request.status())
.eventSeatArea(eventSeatArea)
.name(request.name())
.build();
})
.toList())
.toList();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
package com.pgms.apievent.eventSeat.service;

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.IntStream;

import com.pgms.apievent.EventTestConfig;
import com.pgms.apievent.eventSeat.dto.request.EventSeatsCreateRequest;
import com.pgms.apievent.eventSeat.dto.response.EventSeatResponse;
import com.pgms.apievent.eventSeat.dto.response.LeftEventSeatResponse;
import com.pgms.apievent.factory.event.EventFactory;
import com.pgms.apievent.factory.eventhall.EventHallFactory;
import com.pgms.coredomain.domain.event.*;
import com.pgms.coredomain.domain.event.repository.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.Transactional;

import com.pgms.apievent.EventTestConfig;
import com.pgms.apievent.eventSeat.dto.request.EventSeatsCreateRequest;
import com.pgms.apievent.eventSeat.dto.response.EventSeatResponse;
import com.pgms.apievent.eventSeat.dto.response.LeftEventSeatResponse;
import com.pgms.apievent.factory.event.EventFactory;
import com.pgms.apievent.factory.eventhall.EventHallFactory;
import com.pgms.coredomain.domain.event.Event;
import com.pgms.coredomain.domain.event.EventHall;
import com.pgms.coredomain.domain.event.EventSeatArea;
import com.pgms.coredomain.domain.event.EventSeatStatus;
import com.pgms.coredomain.domain.event.EventTime;
import com.pgms.coredomain.domain.event.SeatAreaType;
import com.pgms.coredomain.domain.event.repository.EventHallRepository;
import com.pgms.coredomain.domain.event.repository.EventRepository;
import com.pgms.coredomain.domain.event.repository.EventSeatAreaRepository;
import com.pgms.coredomain.domain.event.repository.EventSeatRepository;
import com.pgms.coredomain.domain.event.repository.EventTimeRepository;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.IntStream;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

@Transactional
@SpringBootTest
Expand Down Expand Up @@ -78,7 +68,7 @@ void setUp() {

List<EventSeatsCreateRequest> eventSeatsCreateRequests = IntStream.range(0, 20)
.mapToObj(i ->
new EventSeatsCreateRequest("", EventSeatStatus.AVAILABLE, eventSeatArea))
new EventSeatsCreateRequest("", EventSeatStatus.AVAILABLE, eventSeatArea.getId()))
.toList();

// when
Expand All @@ -104,7 +94,7 @@ void setUp() {

List<EventSeatsCreateRequest> eventSeatsCreateRequests = IntStream.range(0, 20)
.mapToObj(i ->
new EventSeatsCreateRequest("", EventSeatStatus.AVAILABLE, eventSeatArea))
new EventSeatsCreateRequest("", EventSeatStatus.AVAILABLE, eventSeatArea.getId()))
.toList();
eventSeatService.createEventSeats(event.getId(), eventSeatsCreateRequests);

Expand Down