-
Notifications
You must be signed in to change notification settings - Fork 0
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
콘서트 좌석정보 수정, 콘서트 상태 close로 변경 API 개발 및 콘서트 상태 open 변경 스케줄러 작업 추가 #4
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
86 changes: 86 additions & 0 deletions
86
...c/main/java/co/kr/ticketing/adminconcert/common/repository/QuerydslRepositorySupport.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,86 @@ | ||
package co.kr.ticketing.adminconcert.common.repository; | ||
|
||
import java.util.List; | ||
import java.util.function.Function; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.support.JpaEntityInformation; | ||
import org.springframework.data.jpa.repository.support.JpaEntityInformationSupport; | ||
import org.springframework.data.jpa.repository.support.Querydsl; | ||
import org.springframework.data.querydsl.SimpleEntityPathResolver; | ||
import org.springframework.data.support.PageableExecutionUtils; | ||
import org.springframework.util.Assert; | ||
|
||
import com.querydsl.core.types.EntityPath; | ||
import com.querydsl.core.types.Expression; | ||
import com.querydsl.core.types.dsl.PathBuilder; | ||
import com.querydsl.jpa.impl.JPAQuery; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import jakarta.persistence.EntityManager; | ||
|
||
public abstract class QuerydslRepositorySupport { | ||
|
||
private final Class<?> domainClass; | ||
private Querydsl querydsl; | ||
private EntityManager entityManager; | ||
private JPAQueryFactory queryFactory; | ||
|
||
protected QuerydslRepositorySupport(Class<?> domainClass) { | ||
Assert.notNull(domainClass, "Domain class must not be null!"); | ||
this.domainClass = domainClass; | ||
} | ||
|
||
@Autowired | ||
public void setEntityManager(EntityManager entityManager) { | ||
Assert.notNull(entityManager, "EntityManager must not be null!"); | ||
JpaEntityInformation<?, ?> entityInformation = JpaEntityInformationSupport.getEntityInformation( | ||
domainClass, entityManager); | ||
SimpleEntityPathResolver resolver = SimpleEntityPathResolver.INSTANCE; | ||
EntityPath<?> path = resolver.createPath(entityInformation.getJavaType()); | ||
this.entityManager = entityManager; | ||
this.querydsl = new Querydsl(entityManager, | ||
new PathBuilder<>(path.getType(), path.getMetadata())); | ||
this.queryFactory = new JPAQueryFactory(entityManager); | ||
} | ||
|
||
@PostConstruct | ||
public void validate() { | ||
Assert.notNull(entityManager, "EntityManager must not be null!"); | ||
Assert.notNull(querydsl, "Querydsl must not be null!"); | ||
Assert.notNull(queryFactory, "QueryFactory must not be null!"); | ||
} | ||
|
||
protected JPAQueryFactory getQueryFactory() { | ||
return queryFactory; | ||
} | ||
|
||
protected Querydsl getQuerydsl() { | ||
return querydsl; | ||
} | ||
|
||
protected EntityManager getEntityManager() { | ||
return entityManager; | ||
} | ||
|
||
protected <T> JPAQuery<T> select(Expression<T> expr) { | ||
return getQueryFactory().select(expr); | ||
} | ||
|
||
protected <T> JPAQuery<T> selectFrom(EntityPath<T> from) { | ||
return getQueryFactory().selectFrom(from); | ||
} | ||
|
||
protected <T> Page<T> applyPagination( | ||
Pageable pageable, | ||
Function<JPAQueryFactory, JPAQuery<T>> contentQuery | ||
) { | ||
JPAQuery<T> jpaQuery = contentQuery.apply(getQueryFactory()); | ||
List<T> content = getQuerydsl().applyPagination(pageable, jpaQuery).fetch(); | ||
|
||
return PageableExecutionUtils.getPage(content, pageable, content::size); | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
...n/java/co/kr/ticketing/adminconcert/concert/controller/request/GetConcertListRequest.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,18 @@ | ||
package co.kr.ticketing.adminconcert.concert.controller.request; | ||
|
||
import co.kr.ticketing.adminconcert.concert.domain.model.ConcertState; | ||
import co.kr.ticketing.adminconcert.concert.service.dto.GetConcertListVo; | ||
|
||
public record GetConcertListRequest( | ||
String name, | ||
String placeName, | ||
ConcertState state | ||
) { | ||
public GetConcertListVo toVo() { | ||
return GetConcertListVo.builder() | ||
.name(name) | ||
.placeName(placeName) | ||
.state(state) | ||
.build(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...va/co/kr/ticketing/adminconcert/concert/controller/request/ModifyConcertSeatsRequest.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,36 @@ | ||
package co.kr.ticketing.adminconcert.concert.controller.request; | ||
|
||
import java.util.List; | ||
|
||
import co.kr.ticketing.adminconcert.concert.service.dto.ModifyConcertSeatVo; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record ModifyConcertSeatsRequest( | ||
@Valid | ||
@NotEmpty | ||
List<ConcertSeatRequest> seats | ||
) { | ||
public record ConcertSeatRequest( | ||
@NotNull | ||
Long id, | ||
@NotBlank | ||
String grade, | ||
@NotNull | ||
Integer price | ||
) { | ||
public ModifyConcertSeatVo toVo() { | ||
return ModifyConcertSeatVo.builder() | ||
.id(id) | ||
.grade(grade) | ||
.price(price) | ||
.build(); | ||
} | ||
} | ||
|
||
public List<ModifyConcertSeatVo> toVo() { | ||
return seats.stream().map(ConcertSeatRequest::toVo).toList(); | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
...java/co/kr/ticketing/adminconcert/concert/controller/response/GetConcertListResponse.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,42 @@ | ||
package co.kr.ticketing.adminconcert.concert.controller.response; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
import co.kr.ticketing.adminconcert.concert.domain.model.Concert; | ||
import co.kr.ticketing.adminconcert.concert.domain.model.ConcertState; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record GetConcertListResponse( | ||
List<ConcertResponse> concerts | ||
) { | ||
@Builder | ||
public record ConcertResponse( | ||
Long id, | ||
String name, | ||
ConcertState state, | ||
LocalDateTime openTime, | ||
LocalDateTime ticketingStartTime, | ||
LocalDateTime lastRunningEndTime, | ||
String placeName | ||
) { | ||
public static ConcertResponse from(Concert concert) { | ||
return ConcertResponse.builder() | ||
.id(concert.id()) | ||
.name(concert.name()) | ||
.state(concert.state()) | ||
.openTime(concert.openTime()) | ||
.ticketingStartTime(concert.ticketingStartTime()) | ||
.lastRunningEndTime(concert.lastRunningEndTime()) | ||
.placeName(concert.place().name()) | ||
.build(); | ||
} | ||
} | ||
|
||
public static GetConcertListResponse from(List<Concert> concerts) { | ||
return GetConcertListResponse.builder() | ||
.concerts(concerts.stream().map(ConcertResponse::from).toList()) | ||
.build(); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -49,6 +49,10 @@ public boolean isPossibleUpdate() { | |
return !state.equals(ConcertState.CLOSE); | ||
} | ||
|
||
public boolean isPossibleUpdateSeats() { | ||
return !isPossibleUpdate() || ticketingStartTime.isBefore(LocalDateTime.now()); | ||
} | ||
|
||
public Concert setOpenTime(LocalDateTime openTime) { | ||
if (!this.state.isSetOpenTimeState() || | ||
openTime.isBefore(LocalDateTime.now()) || | ||
|
@@ -141,4 +145,43 @@ public Concert updatePlace(Place place, List<ConcertSeat> seats) { | |
.seats(List.copyOf(seats)) | ||
.build(); | ||
} | ||
|
||
public Concert changeState(ConcertState state) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메서드명이 changeState 인데 실제로는 get 을 수행하는것 같습니다. |
||
if (state == ConcertState.READY) { | ||
throw new BadRequestException("READY 상태로 변경할 수 없습니다"); | ||
} else if (state == ConcertState.OPEN) { | ||
isPossibleChangeStateToOpen(); | ||
} else { | ||
isPossibleChangeStateToClose(); | ||
} | ||
|
||
return Concert.builder() | ||
.id(this.id) | ||
.name(this.name) | ||
.detailInfo(this.detailInfo) | ||
.runningTime(this.runningTime) | ||
.state(state) | ||
.ticketingStartTime(this.ticketingStartTime) | ||
.lastRunningEndTime(this.lastRunningEndTime) | ||
.openTime(this.openTime) | ||
.rounds(List.copyOf(this.rounds)) | ||
.place(this.place) | ||
.seats(List.copyOf(this.seats)) | ||
.build(); | ||
} | ||
|
||
private void isPossibleChangeStateToOpen() { | ||
if (this.state == ConcertState.CLOSE || (this.openTime != null && this.openTime.isAfter(LocalDateTime.now()))) { | ||
throw new BadRequestException("OPEN 상태로 변경할 수 없습니다"); | ||
} | ||
} | ||
|
||
private void isPossibleChangeStateToClose() { | ||
if (this.state == ConcertState.OPEN) { | ||
if (this.lastRunningEndTime.isAfter(LocalDateTime.now())) { | ||
//todo) 예매된 공연이 있으면 변경 불가능한 로직 추가 | ||
throw new BadRequestException("CLOSE 상태로 변경할 수 없습니다"); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/{id}/close 로 해도 될것 같습니다.