-
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
Feature/admin concert place #2
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
44aed94
오타수정
plere 8a102da
admin-concert 프로젝트 추가
plere d89a845
장소 등록 API 개발
plere 97d9d9c
요청 파라미터 validation exception advice 추가
plere d55d52b
장소명으로 장소 조회하는 API 개발
plere af6df1a
코드리뷰 반영
plere dc5ef32
placeVersion을 제거하고 verison 정보를 place 한곳에서 관리하도록 수정
plere e38287f
admin-concert example http 코드 추가
plere e667323
reader/writer 분리
plere 53842b8
model과 entity 분리
plere 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
dependencies { | ||
// database | ||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' | ||
implementation 'com.mysql:mysql-connector-j' | ||
|
||
// validator | ||
implementation 'org.springframework.boot:spring-boot-starter-validation' | ||
|
||
} | ||
|
||
bootJar { | ||
archivesBaseName = 'Admin-concert' | ||
archiveFileName = 'admin-concert.jar' | ||
destinationDirectory = file(project.rootProject.projectDir) | ||
enabled = true | ||
} | ||
|
||
jar { | ||
enabled = false | ||
} |
15 changes: 15 additions & 0 deletions
15
admin/admin-concert/src/main/java/co/kr/ticketing/adminconcert/AdminConcertApplication.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,15 @@ | ||
package co.kr.ticketing.adminconcert; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.data.jpa.repository.config.EnableJpaAuditing; | ||
|
||
@EnableJpaAuditing | ||
@SpringBootApplication | ||
public class AdminConcertApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(AdminConcertApplication.class, args); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
admin/admin-concert/src/main/java/co/kr/ticketing/adminconcert/common/dto/CreatedDto.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,14 @@ | ||
package co.kr.ticketing.adminconcert.common.dto; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record CreatedDto( | ||
Long id | ||
) { | ||
public static CreatedDto from(Long id) { | ||
return CreatedDto.builder() | ||
.id(id) | ||
.build(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
admin/admin-concert/src/main/java/co/kr/ticketing/adminconcert/common/dto/ResponseDto.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 co.kr.ticketing.adminconcert.common.dto; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ResponseDto<T> { | ||
private final String code; | ||
private final T body; | ||
|
||
public ResponseDto(String code) { | ||
this.code = code; | ||
this.body = null; | ||
} | ||
|
||
public ResponseDto(String code, T body) { | ||
this.code = code; | ||
this.body = body; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...-concert/src/main/java/co/kr/ticketing/adminconcert/common/exception/CustomException.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,15 @@ | ||
package co.kr.ticketing.adminconcert.common.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CustomException extends RuntimeException { | ||
private final HttpStatus status; | ||
|
||
public CustomException(final HttpStatus status, final String message) { | ||
super(message); | ||
this.status = status; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ncert/src/main/java/co/kr/ticketing/adminconcert/common/exception/DuplicateException.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,11 @@ | ||
package co.kr.ticketing.adminconcert.common.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ResponseStatus(value = HttpStatus.CONFLICT) | ||
public class DuplicateException extends CustomException { | ||
public DuplicateException(String message) { | ||
super(HttpStatus.CONFLICT, message); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...-concert/src/main/java/co/kr/ticketing/adminconcert/common/exception/ExceptionAdvice.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,30 @@ | ||
package co.kr.ticketing.adminconcert.common.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.MethodArgumentNotValidException; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
import co.kr.ticketing.adminconcert.common.dto.ResponseDto; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
public class ExceptionAdvice { | ||
@ExceptionHandler(CustomException.class) | ||
public ResponseEntity<ResponseDto<String>> customException(CustomException exception) { | ||
ResponseDto<String> responseDto = new ResponseDto<>(exception.getStatus().toString(), | ||
exception.getMessage()); | ||
log.error("CustomRuntimeException 발생 : code: {}, message: {}", responseDto.getCode(), responseDto.getBody()); | ||
return new ResponseEntity<>(responseDto, exception.getStatus()); | ||
} | ||
|
||
@ExceptionHandler(MethodArgumentNotValidException.class) | ||
public ResponseEntity<ResponseDto<String>> customException(MethodArgumentNotValidException exception) { | ||
HttpStatus badRequest = HttpStatus.BAD_REQUEST; | ||
ResponseDto<String> responseDto = new ResponseDto<>(badRequest.toString(), "요청 값이 잘 못 됐습니다"); | ||
log.error("MethodArgumentNotValidException 발생 : message: {}", exception.getMessage()); | ||
return new ResponseEntity<>(responseDto, badRequest); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...rc/main/java/co/kr/ticketing/adminconcert/common/exception/ResourceNotFoundException.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,15 @@ | ||
package co.kr.ticketing.adminconcert.common.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
|
||
@ResponseStatus(value = HttpStatus.NO_CONTENT) | ||
public class ResourceNotFoundException extends CustomException { | ||
public ResourceNotFoundException(String domain, Long id) { | ||
super(HttpStatus.NO_CONTENT, "domain: " + domain + ", id: " + id); | ||
} | ||
|
||
public ResourceNotFoundException(String domain, String id) { | ||
super(HttpStatus.NO_CONTENT, "domain: " + domain + ", id: " + id); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...-concert/src/main/java/co/kr/ticketing/adminconcert/place/controller/PlaceController.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,46 @@ | ||
package co.kr.ticketing.adminconcert.place.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import co.kr.ticketing.adminconcert.common.dto.CreatedDto; | ||
import co.kr.ticketing.adminconcert.common.dto.ResponseDto; | ||
import co.kr.ticketing.adminconcert.place.controller.request.AddPlaceRequest; | ||
import co.kr.ticketing.adminconcert.place.controller.request.GetPlaceRequest; | ||
import co.kr.ticketing.adminconcert.place.controller.response.GetPlaceResponse; | ||
import co.kr.ticketing.adminconcert.place.controller.response.PlaceResponseCode; | ||
import co.kr.ticketing.adminconcert.place.usecase.AddPlaceUseCase; | ||
import co.kr.ticketing.adminconcert.place.usecase.GetPlaceUseCase; | ||
import jakarta.validation.Valid; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.experimental.FieldDefaults; | ||
|
||
@Validated | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping(value = "/places") | ||
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) | ||
public class PlaceController { | ||
AddPlaceUseCase addPlaceUseCase; | ||
GetPlaceUseCase getPlaceUseCase; | ||
|
||
@GetMapping | ||
public ResponseEntity<ResponseDto<GetPlaceResponse>> get(@Valid @ModelAttribute GetPlaceRequest request) { | ||
var response = getPlaceUseCase.execute(request); | ||
return ResponseEntity.ok(new ResponseDto<>(PlaceResponseCode.GET_PLACE.name(), response)); | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<ResponseDto<CreatedDto>> addPlace(@RequestBody @Valid AddPlaceRequest request) { | ||
long createdId = addPlaceUseCase.execute(request); | ||
|
||
return ResponseEntity.ok(new ResponseDto<>(PlaceResponseCode.CREATED_PLACE.name(), CreatedDto.from(createdId))); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
.../src/main/java/co/kr/ticketing/adminconcert/place/controller/request/AddPlaceRequest.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,48 @@ | ||
package co.kr.ticketing.adminconcert.place.controller.request; | ||
|
||
import java.util.List; | ||
|
||
import co.kr.ticketing.adminconcert.place.domain.model.Place; | ||
import co.kr.ticketing.adminconcert.place.domain.model.Seat; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotEmpty; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record AddPlaceRequest( | ||
@NotBlank | ||
String name, | ||
@NotBlank | ||
String address, | ||
@Valid | ||
@NotEmpty | ||
List<SeatRequest> seats, | ||
String identifier | ||
) { | ||
public record SeatRequest( | ||
@NotNull | ||
Integer columnNum, | ||
@NotNull | ||
Integer rowNum, | ||
@NotNull | ||
Integer floor | ||
) { | ||
public Seat toModel() { | ||
return Seat.builder() | ||
.columnNum(columnNum) | ||
.rowNum(rowNum) | ||
.floor(floor) | ||
.build(); | ||
} | ||
} | ||
|
||
public Place toModel() { | ||
return Place.builder() | ||
.name(name) | ||
.address(address) | ||
.identifier(identifier) | ||
.last(true) | ||
.seats(seats.stream().map(SeatRequest::toModel).toList()) | ||
.build(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
.../src/main/java/co/kr/ticketing/adminconcert/place/controller/request/GetPlaceRequest.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,9 @@ | ||
package co.kr.ticketing.adminconcert.place.controller.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record GetPlaceRequest( | ||
@NotBlank | ||
String name | ||
) { | ||
} |
32 changes: 32 additions & 0 deletions
32
...rc/main/java/co/kr/ticketing/adminconcert/place/controller/response/GetPlaceResponse.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,32 @@ | ||
package co.kr.ticketing.adminconcert.place.controller.response; | ||
|
||
import java.util.List; | ||
|
||
import co.kr.ticketing.adminconcert.place.domain.model.Place; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record GetPlaceResponse( | ||
List<PlaceResponse> places | ||
) { | ||
@Builder | ||
public record PlaceResponse( | ||
Long id, | ||
String identifier, | ||
String name | ||
) { | ||
public static PlaceResponse from(Place place) { | ||
return PlaceResponse.builder() | ||
.id(place.id()) | ||
.identifier(place.identifier()) | ||
.name(place.name()) | ||
.build(); | ||
} | ||
} | ||
|
||
public static GetPlaceResponse from(List<Place> places) { | ||
return GetPlaceResponse.builder() | ||
.places(places.stream().map(PlaceResponse::from).toList()) | ||
.build(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...c/main/java/co/kr/ticketing/adminconcert/place/controller/response/PlaceResponseCode.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,6 @@ | ||
package co.kr.ticketing.adminconcert.place.controller.response; | ||
|
||
public enum PlaceResponseCode { | ||
GET_PLACE, | ||
CREATED_PLACE | ||
} |
5 changes: 5 additions & 0 deletions
5
...-concert/src/main/java/co/kr/ticketing/adminconcert/place/domain/IdentifierGenerator.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,5 @@ | ||
package co.kr.ticketing.adminconcert.place.domain; | ||
|
||
public interface IdentifierGenerator { | ||
String generate(); | ||
} |
19 changes: 19 additions & 0 deletions
19
...c/main/java/co/kr/ticketing/adminconcert/place/domain/infrastructure/PlaceRepository.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 co.kr.ticketing.adminconcert.place.domain.infrastructure; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import co.kr.ticketing.adminconcert.place.domain.infrastructure.dto.UpdatePlaceDto; | ||
import co.kr.ticketing.adminconcert.place.domain.model.Place; | ||
|
||
public interface PlaceRepository { | ||
Optional<Place> find(long id); | ||
|
||
Optional<Place> findLastVersion(String identifier); | ||
|
||
List<Place> getLastVersionsByPlaceName(String placeName); | ||
|
||
Place create(Place place); | ||
|
||
Place update(long id, UpdatePlaceDto updateDto); | ||
} |
13 changes: 13 additions & 0 deletions
13
...ain/java/co/kr/ticketing/adminconcert/place/domain/infrastructure/dto/UpdatePlaceDto.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,13 @@ | ||
package co.kr.ticketing.adminconcert.place.domain.infrastructure.dto; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record UpdatePlaceDto( | ||
String name, | ||
String address, | ||
String identifier, | ||
Long version, | ||
boolean last | ||
) { | ||
} |
43 changes: 43 additions & 0 deletions
43
admin/admin-concert/src/main/java/co/kr/ticketing/adminconcert/place/domain/model/Place.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,43 @@ | ||
package co.kr.ticketing.adminconcert.place.domain.model; | ||
|
||
import java.util.List; | ||
|
||
import co.kr.ticketing.adminconcert.place.domain.IdentifierGenerator; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record Place( | ||
Long id, | ||
String name, | ||
String address, | ||
String identifier, | ||
Long version, | ||
boolean last, | ||
List<Seat> seats | ||
) { | ||
public static Place getNewPlace(Place place, IdentifierGenerator generator) { | ||
return Place.builder() | ||
.name(place.name()) | ||
.address(place.address()) | ||
.identifier(generator.generate()) | ||
.version(0L) | ||
.last(true) | ||
.seats(List.copyOf(place.seats())) | ||
.build(); | ||
} | ||
|
||
public Place getNextPlace(Place beforePlace) { | ||
return Place.builder() | ||
.name(name) | ||
.address(address) | ||
.identifier(identifier) | ||
.version(beforePlace.getNextVersion()) | ||
.last(true) | ||
.seats(List.copyOf(seats())) | ||
.build(); | ||
} | ||
|
||
public Long getNextVersion() { | ||
return this.version + 1; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
admin/admin-concert/src/main/java/co/kr/ticketing/adminconcert/place/domain/model/Seat.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,12 @@ | ||
package co.kr.ticketing.adminconcert.place.domain.model; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record Seat( | ||
Long id, | ||
int columnNum, | ||
int rowNum, | ||
int floor | ||
) { | ||
} |
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.
get 에서 last 를 셋팅하는 write operation 이 같이 있는데요. 분리하면 좋을 것 같습니다.
함수는 getNextPlace 로 DB 변경이 없을 것이 기대되지만 실재로는 beforePlace 의 last 가 Update 되는 함수라 안정적이지 않아보입니다.
차라리 last 를 별도 루틴에서 셋팅하게해서 read / write 를 분리하는게 좋을것 같습니다.