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

feat: 공연 DTO & Service 관련 Validation 추가 및 테스트 코드 추가 #29

Merged
merged 3 commits into from
Dec 26, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,45 @@

import java.time.LocalDateTime;

import org.springframework.format.annotation.DateTimeFormat;

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

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.Size;

public record EventCreateRequest(

@NotBlank(message = "공연 제목은 필수 입력값 입니다.")
@Size(min = 1, max = 100, message = "공연 제목은 최소 1자 이상 최대 100자 이하 입니다.")
String title,

@NotBlank(message = "공연 설명은 필수 입력값 입니다.")
String description,

@Positive(message = "공연 러닝 타임은 0보다 큰 값 이어야 합니다.")
int runningTime,

@DateTimeFormat(pattern = "yyyy-MM-dd")
LocalDateTime startDate,

@DateTimeFormat(pattern = "yyyy-MM-dd")
LocalDateTime endDate,

@NotBlank(message = "관람 등급은 필수 입력값 입니다.")
String rating,

@NotNull(message = "공연 장르 타입은 필수 입력값 입니다.")
GenreType genreType,

// TODO : MultipartFile로 입력 받도록 수정 , S3 연동 및 이미지 파일 Url로 변환 로직 추가 해야함
String thumbnail,

@NotNull(message = "이벤트 홀 ID는 필수 입력값 입니다.")
Long eventHallId
) {
public Event toEntity(EventHall eventHall) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,44 @@

import java.time.LocalDateTime;

import org.springframework.format.annotation.DateTimeFormat;

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

import jakarta.annotation.Nullable;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.Size;

public record EventUpdateRequest(

@Nullable
@Size(min = 1, max = 100, message = "공연 제목은 최소 1자 이상 최대 100자 이하 입니다.")
String title,

@Nullable
String description,

@Positive(message = "공연 러닝 타임은 0보다 큰 값 이어야 합니다.")
int runningTime,

@Nullable
@DateTimeFormat(pattern = "yyyy-MM-dd")
LocalDateTime startDate,

@Nullable
@DateTimeFormat(pattern = "yyyy-MM-dd")
LocalDateTime endDate,

@Nullable
String rating,

@Nullable
GenreType genreType,

@Nullable
String thumbnail,

@Nullable
Long eventHallId
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static EventResponse of(Event event) {
event.getStartDate().toString(),
event.getEndDate().toString(),
event.getRating(),
event.getGenreType().toString(),
event.getGenreType().getDescription(),
event.getThumbnail(),
event.getEventHall().getName()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.pgms.apievent.event.service;

import static org.assertj.core.api.Assertions.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.AfterEach;
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 com.pgms.apievent.event.dto.request.EventCreateRequest;
import com.pgms.apievent.event.dto.request.EventUpdateRequest;
import com.pgms.apievent.event.dto.response.EventResponse;
import com.pgms.coredomain.domain.event.Event;
import com.pgms.coredomain.domain.event.EventHall;
import com.pgms.coredomain.domain.event.GenreType;
import com.pgms.coredomain.domain.event.repository.EventHallRepository;
import com.pgms.coredomain.domain.event.repository.EventRepository;

@SpringBootTest
class EventServiceTest {

@Autowired
private EventService eventService;

@Autowired
private EventRepository eventRepository;

@Autowired
private EventHallRepository eventHallRepository;

private EventHall eventHall;

private Event event;

@BeforeEach
void setUp() {
eventHall = new EventHall("테스트 공연장", "테스트 주소", new ArrayList<>());
eventHallRepository.save(eventHall);

EventCreateRequest request = new EventCreateRequest(
"공연 1",
"공연1 입니다.",
60,
LocalDateTime.of(2023, 1, 1, 0, 0), // 예시로 날짜와 시간을 지정
LocalDateTime.of(2023, 1, 7, 0, 0),
"12세 이상",
GenreType.MUSICAL,
"thumbnail.jpg",
1L
);
event = eventRepository.save(request.toEntity(eventHall));
}

@AfterEach
void tearDown() {
eventRepository.deleteAll();
}

@Test
void 공연_아이디로_조회_테스트() {
// Given
Long eventId = event.getId();

// When
EventResponse response = eventService.getEventById(eventId);

// Then
assertThat(response.id()).isEqualTo(event.getId());
assertThat(response.title()).isEqualTo(event.getTitle());
}

@Test
void 공연_수정_테스트() {
// Given
Long eventId = event.getId();
EventUpdateRequest request = new EventUpdateRequest(
"공연 1 수정",
"공연 1 내용 수정입니다.",
100,
LocalDateTime.of(2023, 2, 1, 0, 0),
LocalDateTime.of(2023, 2, 1, 0, 0),
"15세 이상",
GenreType.MUSICAL,
"thumbnail.jpg",
eventHall.getId());

// When
EventResponse response = eventService.updateEvent(eventId, request);

// Then
assertThat(response.title()).isEqualTo(request.title());
assertThat(response.rating()).isEqualTo(request.rating());
}

@Test
void 공연_삭제_테스트() {
// Given
Long eventId = event.getId();

// When
eventService.deleteEventById(eventId);

// Then
List<Event> events = eventRepository.findAll();
assertThat(events).hasSize(0);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package com.pgms.coredomain.domain.event;

import lombok.Getter;

@Getter
public enum GenreType {
MUSICAL("뮤지컬"),
CONCERT("콘서트"),
PLAY("연극"),
CLASSIC("클래식"),
SPORTS("스포츠"),
CAMPING("캠핑");

private final String description;

GenreType(String description) {
this.description = description;
}
}