-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 공연장 dto, service validation 추가 (#28)
* feat : add validation in EventHallCreate, Update Dtos * feat: #25 공연장 생성 테스트 추가 * feat: #25 add 공연장 삭제, 수정, 목록 조회 성공 테스트 * fix : 테스트 코드 수정 --------- Co-authored-by: zerozae <[email protected]>
- Loading branch information
Showing
6 changed files
with
151 additions
and
6 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
6 changes: 5 additions & 1 deletion
6
...i-event/src/main/java/com/pgms/apievent/eventHall/dto/request/EventHallCreateRequest.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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
package com.pgms.apievent.eventHall.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
|
||
import java.util.List; | ||
|
||
public record EventHallCreateRequest(String name, | ||
public record EventHallCreateRequest(@NotBlank(message = "공연장 이름은 빈칸을 지정할 수 없습니다.") | ||
@Size(max = 25, message = "공연장 이름은 10자 이내로 입력해주세요.") String name, | ||
String address, | ||
List<EventHallSeatCreateRequest> eventHallSeatCreateRequests) { | ||
} |
6 changes: 5 additions & 1 deletion
6
...ent/src/main/java/com/pgms/apievent/eventHall/dto/request/EventHallSeatCreateRequest.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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
package com.pgms.apievent.eventHall.dto.request; | ||
|
||
public record EventHallSeatCreateRequest(String name) { | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
|
||
public record EventHallSeatCreateRequest(@NotBlank(message = "공연장 좌석은 빈칸을 지정할 수 없습니다.") | ||
@Size(max = 10, message = "공연장 좌석은 10자 이내로 입력해주세요.") String name) { | ||
} |
8 changes: 7 additions & 1 deletion
8
...i-event/src/main/java/com/pgms/apievent/eventHall/dto/request/EventHallUpdateRequest.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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
package com.pgms.apievent.eventHall.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
|
||
import java.util.List; | ||
|
||
public record EventHallUpdateRequest(String name, String address, List<EventHallSeatCreateRequest> eventHallSeatCreateRequests) { | ||
public record EventHallUpdateRequest(@NotBlank(message = "공연장 이름은 빈칸을 지정할 수 없습니다.") | ||
@Size(max = 25, message = "공연장 이름은 10자 이내로 입력해주세요.") String name, | ||
String address, | ||
List<EventHallSeatCreateRequest> eventHallSeatCreateRequests) { | ||
} |
128 changes: 128 additions & 0 deletions
128
api/api-event/src/test/java/com/pgms/apievent/eventHall/service/EventHallServiceTest.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,128 @@ | ||
package com.pgms.apievent.eventHall.service; | ||
|
||
import com.pgms.apievent.eventHall.dto.request.EventHallCreateRequest; | ||
import com.pgms.apievent.eventHall.dto.request.EventHallSeatCreateRequest; | ||
import com.pgms.apievent.eventHall.dto.request.EventHallUpdateRequest; | ||
import com.pgms.apievent.eventHall.dto.response.EventHallResponse; | ||
import com.pgms.coredomain.domain.event.EventHall; | ||
import com.pgms.coredomain.domain.event.EventHallSeat; | ||
import com.pgms.coredomain.domain.event.repository.EventHallRepository; | ||
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.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.stream.IntStream; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@SpringBootTest | ||
@Transactional | ||
class EventHallServiceTest { | ||
|
||
@Autowired | ||
private EventHallRepository eventHallRepository; | ||
@Autowired | ||
private EventHallService eventHallService; | ||
|
||
@BeforeEach | ||
void clean(){ | ||
eventHallRepository.deleteAll(); | ||
} | ||
|
||
@Test | ||
public void 공연장_생성_성공(){ | ||
// given | ||
List<EventHallSeatCreateRequest> eventHallSeatCreateRequests = IntStream.range(0, 10) | ||
.mapToObj(i -> new EventHallSeatCreateRequest("T" + String.valueOf(i))) | ||
.toList(); | ||
|
||
EventHallCreateRequest eventHallCreateRequest = new EventHallCreateRequest("test", "test", eventHallSeatCreateRequests); | ||
|
||
// when | ||
EventHallResponse eventHallResponse = eventHallService.createEventHall(eventHallCreateRequest); | ||
|
||
// then | ||
assertThat(eventHallResponse.name(), is("test")); | ||
assertThat(eventHallResponse.eventHallSeatResponses().size(), is(10)); | ||
} | ||
|
||
@Test | ||
public void 공연장_삭제_성공(){ | ||
// given | ||
List<EventHallSeat> eventHallSeats = IntStream.range(0, 10) | ||
.mapToObj(i -> new EventHallSeat("T" + String.valueOf(i))) | ||
.toList(); | ||
|
||
EventHall eventHall = EventHall.builder() | ||
.name("test") | ||
.address("test") | ||
.eventHallSeats(eventHallSeats) | ||
.build(); | ||
|
||
EventHall savedEventHall = eventHallRepository.save(eventHall); | ||
|
||
// when | ||
eventHallRepository.delete(savedEventHall); | ||
|
||
// then | ||
assertThat(eventHallRepository.count(), is(0L)); | ||
} | ||
|
||
@Test | ||
public void 공연장_수정_성공(){ | ||
// given | ||
List<EventHallSeat> eventHallSeats = IntStream.range(0, 10) | ||
.mapToObj(i -> new EventHallSeat("T" + String.valueOf(i))) | ||
.toList(); | ||
|
||
EventHall eventHall = EventHall.builder() | ||
.name("test") | ||
.address("test") | ||
.eventHallSeats(eventHallSeats) | ||
.build(); | ||
|
||
EventHall savedEventHall = eventHallRepository.save(eventHall); | ||
|
||
List<EventHallSeatCreateRequest> eventHallSeatCreateRequests = IntStream.range(0, 10) | ||
.mapToObj(i -> new EventHallSeatCreateRequest("T" + String.valueOf(i))) | ||
.toList(); | ||
|
||
EventHallUpdateRequest eventHallUpdateRequest = new EventHallUpdateRequest("update", "test", eventHallSeatCreateRequests); | ||
|
||
// when | ||
EventHallResponse eventHallResponse = eventHallService.updateEventHall(savedEventHall.getId(), eventHallUpdateRequest); | ||
|
||
// then | ||
assertThat(eventHallResponse.name(), is("update")); | ||
assertThat(savedEventHall.getEventHallSeats().size(), is(10)); | ||
} | ||
|
||
@Test | ||
public void 공연장_목록_조회_성공(){ | ||
// given | ||
|
||
List<EventHallSeat> eventHallSeats = IntStream.range(0, 10) | ||
.mapToObj(i -> new EventHallSeat("T" + String.valueOf(i))) | ||
.toList(); | ||
|
||
List<EventHall> eventHalls = IntStream.range(0, 10) | ||
.mapToObj(i -> { | ||
return EventHall.builder() | ||
.name("test") | ||
.address("test") | ||
.eventHallSeats(eventHallSeats) | ||
.build(); | ||
}) | ||
.toList(); | ||
|
||
// when | ||
List<EventHall> savedEventHalls = eventHallRepository.saveAll(eventHalls); | ||
|
||
// then | ||
assertThat(savedEventHalls.size(), is(10)); | ||
} | ||
} |
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