feat: add zoo sample_test1
This commit is contained in:
14
build.gradle
14
build.gradle
@@ -73,22 +73,20 @@ bootJar {
|
|||||||
// formatAnnotations()
|
// formatAnnotations()
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
spotless {
|
spotless {
|
||||||
java {
|
java {
|
||||||
target 'src/**/*.java'
|
target 'src/**/*.java'
|
||||||
googleJavaFormat('1.19.2')
|
indentWithSpaces(2)
|
||||||
.aosp()
|
trimTrailingWhitespace()
|
||||||
.reflowLongStrings()
|
endWithNewline()
|
||||||
// removeUnusedImports()
|
|
||||||
importOrder()
|
importOrder()
|
||||||
|
removeUnusedImports()
|
||||||
formatAnnotations()
|
formatAnnotations()
|
||||||
|
|
||||||
// indentWithSpaces는 google-java-format에는 영향 없음
|
|
||||||
// indent control 불가 → 필요하면 google-java-format 제거해야 함
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Run spotlessCheck before build
|
// Run spotlessCheck before build
|
||||||
tasks.named('build') {
|
tasks.named('build') {
|
||||||
dependsOn 'spotlessCheck'
|
dependsOn 'spotlessCheck'
|
||||||
|
|||||||
@@ -13,65 +13,65 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
@RequestMapping({"/api/zoos", "/v1/api/zoos"})
|
@RequestMapping({"/api/zoos", "/v1/api/zoos"})
|
||||||
public class ZooApiController {
|
public class ZooApiController {
|
||||||
|
|
||||||
private final ZooService zooService;
|
private final ZooService zooService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 동물원 생성
|
* 동물원 생성
|
||||||
*
|
*
|
||||||
* @param req 동물원 생성 요청
|
* @param req 동물원 생성 요청
|
||||||
* @return 생성된 동물원 정보 (동물 개수 포함)
|
* @return 생성된 동물원 정보 (동물 개수 포함)
|
||||||
*/
|
*/
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public ResponseEntity<ZooDto.Detail> createZoo(@RequestBody ZooDto.AddReq req) {
|
public ResponseEntity<ZooDto.Detail> createZoo(@RequestBody ZooDto.AddReq req) {
|
||||||
ZooDto.Detail created = zooService.createZoo(req);
|
ZooDto.Detail created = zooService.createZoo(req);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(created);
|
return ResponseEntity.status(HttpStatus.CREATED).body(created);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UUID로 동물원 조회
|
* UUID로 동물원 조회
|
||||||
*
|
*
|
||||||
* @param uuid 동물원 UUID
|
* @param uuid 동물원 UUID
|
||||||
* @return 동물원 정보 (현재 동물 개수 포함)
|
* @return 동물원 정보 (현재 동물 개수 포함)
|
||||||
*/
|
*/
|
||||||
@GetMapping("/{uuid}")
|
@GetMapping("/{uuid}")
|
||||||
public ResponseEntity<ZooDto.Detail> getZoo(@PathVariable String uuid) {
|
public ResponseEntity<ZooDto.Detail> getZoo(@PathVariable String uuid) {
|
||||||
Long id = zooService.getZooByUuid(uuid);
|
Long id = zooService.getZooByUuid(uuid);
|
||||||
ZooDto.Detail zoo = zooService.getZoo(id);
|
ZooDto.Detail zoo = zooService.getZoo(id);
|
||||||
return ResponseEntity.ok(zoo);
|
return ResponseEntity.ok(zoo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UUID로 동물원 삭제 (논리 삭제)
|
* UUID로 동물원 삭제 (논리 삭제)
|
||||||
*
|
*
|
||||||
* @param uuid 동물원 UUID
|
* @param uuid 동물원 UUID
|
||||||
* @return 삭제 성공 메시지
|
* @return 삭제 성공 메시지
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("/{uuid}")
|
@DeleteMapping("/{uuid}")
|
||||||
public ResponseEntity<Void> deleteZoo(@PathVariable String uuid) {
|
public ResponseEntity<Void> deleteZoo(@PathVariable String uuid) {
|
||||||
Long id = zooService.getZooByUuid(uuid);
|
Long id = zooService.getZooByUuid(uuid);
|
||||||
zooService.deleteZoo(id);
|
zooService.deleteZoo(id);
|
||||||
return ResponseEntity.noContent().build();
|
return ResponseEntity.noContent().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 동물원 검색 (페이징)
|
* 동물원 검색 (페이징)
|
||||||
*
|
*
|
||||||
* @param name 동물원 이름 (선택)
|
* @param name 동물원 이름 (선택)
|
||||||
* @param location 위치 (선택)
|
* @param location 위치 (선택)
|
||||||
* @param page 페이지 번호 (기본값: 0)
|
* @param page 페이지 번호 (기본값: 0)
|
||||||
* @param size 페이지 크기 (기본값: 20)
|
* @param size 페이지 크기 (기본값: 20)
|
||||||
* @param sort 정렬 조건 (예: "name,asc")
|
* @param sort 정렬 조건 (예: "name,asc")
|
||||||
* @return 페이징 처리된 동물원 목록 (각 동물원의 현재 동물 개수 포함)
|
* @return 페이징 처리된 동물원 목록 (각 동물원의 현재 동물 개수 포함)
|
||||||
*/
|
*/
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public ResponseEntity<Page<ZooDto.Detail>> searchZoos(
|
public ResponseEntity<Page<ZooDto.Detail>> searchZoos(
|
||||||
@RequestParam(required = false) String name,
|
@RequestParam(required = false) String name,
|
||||||
@RequestParam(required = false) String location,
|
@RequestParam(required = false) String location,
|
||||||
@RequestParam(defaultValue = "0") int page,
|
@RequestParam(defaultValue = "0") int page,
|
||||||
@RequestParam(defaultValue = "20") int size,
|
@RequestParam(defaultValue = "20") int size,
|
||||||
@RequestParam(required = false) String sort) {
|
@RequestParam(required = false) String sort) {
|
||||||
ZooDto.SearchReq searchReq = new ZooDto.SearchReq(name, location, page, size, sort);
|
ZooDto.SearchReq searchReq = new ZooDto.SearchReq(name, location, page, size, sort);
|
||||||
Page<ZooDto.Detail> zoos = zooService.search(searchReq);
|
Page<ZooDto.Detail> zoos = zooService.search(searchReq);
|
||||||
return ResponseEntity.ok(zoos);
|
return ResponseEntity.ok(zoos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,61 +14,62 @@ import org.springframework.data.domain.Sort;
|
|||||||
|
|
||||||
public class AnimalDto {
|
public class AnimalDto {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class AddReq {
|
public static class AddReq {
|
||||||
|
|
||||||
private Category category;
|
private Category category;
|
||||||
private Species species;
|
private Species species;
|
||||||
private String name;
|
private String name;
|
||||||
private Long zooId; // 동물원 ID (선택)
|
private Long zooId; // 동물원 ID (선택)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public static class Basic {
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
private Long id;
|
||||||
|
private String uuid;
|
||||||
|
private Category category;
|
||||||
|
private Species species;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@JsonFormat(
|
||||||
|
shape = JsonFormat.Shape.STRING,
|
||||||
|
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
|
||||||
|
timezone = "Asia/Seoul")
|
||||||
|
private ZonedDateTime createdDate;
|
||||||
|
|
||||||
|
@JsonFormat(
|
||||||
|
shape = JsonFormat.Shape.STRING,
|
||||||
|
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
|
||||||
|
timezone = "Asia/Seoul")
|
||||||
|
private ZonedDateTime modifiedDate;
|
||||||
|
|
||||||
|
public Basic(
|
||||||
|
Long id,
|
||||||
|
String uuid,
|
||||||
|
String name,
|
||||||
|
Category category,
|
||||||
|
Species species,
|
||||||
|
ZonedDateTime createdDate,
|
||||||
|
ZonedDateTime modifiedDate) {
|
||||||
|
this.id = id;
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.name = name;
|
||||||
|
this.category = category;
|
||||||
|
this.species = species;
|
||||||
|
this.createdDate = createdDate;
|
||||||
|
this.modifiedDate = modifiedDate;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public static class Basic {
|
@AllArgsConstructor
|
||||||
|
public enum Category implements EnumType {
|
||||||
@JsonIgnore private Long id;
|
// @formatter:off
|
||||||
private String uuid;
|
|
||||||
private Category category;
|
|
||||||
private Species species;
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
@JsonFormat(
|
|
||||||
shape = JsonFormat.Shape.STRING,
|
|
||||||
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
|
|
||||||
timezone = "Asia/Seoul")
|
|
||||||
private ZonedDateTime createdDate;
|
|
||||||
|
|
||||||
@JsonFormat(
|
|
||||||
shape = JsonFormat.Shape.STRING,
|
|
||||||
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
|
|
||||||
timezone = "Asia/Seoul")
|
|
||||||
private ZonedDateTime modifiedDate;
|
|
||||||
|
|
||||||
public Basic(
|
|
||||||
Long id,
|
|
||||||
String uuid,
|
|
||||||
String name,
|
|
||||||
Category category,
|
|
||||||
Species species,
|
|
||||||
ZonedDateTime createdDate,
|
|
||||||
ZonedDateTime modifiedDate) {
|
|
||||||
this.id = id;
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.name = name;
|
|
||||||
this.category = category;
|
|
||||||
this.species = species;
|
|
||||||
this.createdDate = createdDate;
|
|
||||||
this.modifiedDate = modifiedDate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@AllArgsConstructor
|
|
||||||
public enum Category implements EnumType {
|
|
||||||
// @formatter:off
|
|
||||||
MAMMALS("100", "포유류"), // 땅에 사는 동물
|
MAMMALS("100", "포유류"), // 땅에 사는 동물
|
||||||
BIRDS("200", "조류"), // 하늘을 나는 동물
|
BIRDS("200", "조류"), // 하늘을 나는 동물
|
||||||
FISH("300", "어류"),
|
FISH("300", "어류"),
|
||||||
@@ -79,13 +80,13 @@ public class AnimalDto {
|
|||||||
;
|
;
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String text;
|
private final String text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum Species implements EnumType {
|
public enum Species implements EnumType {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
DOG("101", "개"),
|
DOG("101", "개"),
|
||||||
CAT("102", "강아지"),
|
CAT("102", "강아지"),
|
||||||
DOVE("201", "비둘기"),
|
DOVE("201", "비둘기"),
|
||||||
@@ -95,36 +96,36 @@ public class AnimalDto {
|
|||||||
;
|
;
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String text;
|
private final String text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class SearchReq {
|
public static class SearchReq {
|
||||||
|
|
||||||
// 검색 조건
|
// 검색 조건
|
||||||
private String name;
|
private String name;
|
||||||
private Category category;
|
private Category category;
|
||||||
private Species species;
|
private Species species;
|
||||||
|
|
||||||
// 페이징 파라미터
|
// 페이징 파라미터
|
||||||
private int page = 0;
|
private int page = 0;
|
||||||
private int size = 20;
|
private int size = 20;
|
||||||
private String sort;
|
private String sort;
|
||||||
|
|
||||||
public Pageable toPageable() {
|
public Pageable toPageable() {
|
||||||
if (sort != null && !sort.isEmpty()) {
|
if (sort != null && !sort.isEmpty()) {
|
||||||
String[] sortParams = sort.split(",");
|
String[] sortParams = sort.split(",");
|
||||||
String property = sortParams[0];
|
String property = sortParams[0];
|
||||||
Sort.Direction direction =
|
Sort.Direction direction =
|
||||||
sortParams.length > 1
|
sortParams.length > 1
|
||||||
? Sort.Direction.fromString(sortParams[1])
|
? Sort.Direction.fromString(sortParams[1])
|
||||||
: Sort.Direction.ASC;
|
: Sort.Direction.ASC;
|
||||||
return PageRequest.of(page, size, Sort.by(direction, property));
|
return PageRequest.of(page, size, Sort.by(direction, property));
|
||||||
}
|
}
|
||||||
return PageRequest.of(page, size);
|
return PageRequest.of(page, size);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,101 +13,102 @@ import org.springframework.data.domain.Sort;
|
|||||||
|
|
||||||
public class ZooDto {
|
public class ZooDto {
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class AddReq {
|
public static class AddReq {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String location;
|
private String location;
|
||||||
private String description;
|
private String description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public static class Basic {
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
private Long id;
|
||||||
|
private String uuid;
|
||||||
|
private String name;
|
||||||
|
private String location;
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@JsonFormat(
|
||||||
|
shape = JsonFormat.Shape.STRING,
|
||||||
|
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
|
||||||
|
timezone = "Asia/Seoul")
|
||||||
|
private ZonedDateTime createdDate;
|
||||||
|
|
||||||
|
@JsonFormat(
|
||||||
|
shape = JsonFormat.Shape.STRING,
|
||||||
|
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
|
||||||
|
timezone = "Asia/Seoul")
|
||||||
|
private ZonedDateTime modifiedDate;
|
||||||
|
|
||||||
|
public Basic(
|
||||||
|
Long id,
|
||||||
|
String uuid,
|
||||||
|
String name,
|
||||||
|
String location,
|
||||||
|
String description,
|
||||||
|
ZonedDateTime createdDate,
|
||||||
|
ZonedDateTime modifiedDate) {
|
||||||
|
this.id = id;
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.name = name;
|
||||||
|
this.location = location;
|
||||||
|
this.description = description;
|
||||||
|
this.createdDate = createdDate;
|
||||||
|
this.modifiedDate = modifiedDate;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public static class Basic {
|
public static class Detail extends Basic {
|
||||||
|
|
||||||
@JsonIgnore private Long id;
|
private Long activeAnimalCount;
|
||||||
private String uuid;
|
|
||||||
private String name;
|
|
||||||
private String location;
|
|
||||||
private String description;
|
|
||||||
|
|
||||||
@JsonFormat(
|
public Detail(
|
||||||
shape = JsonFormat.Shape.STRING,
|
Long id,
|
||||||
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
|
String uuid,
|
||||||
timezone = "Asia/Seoul")
|
String name,
|
||||||
private ZonedDateTime createdDate;
|
String location,
|
||||||
|
String description,
|
||||||
@JsonFormat(
|
ZonedDateTime createdDate,
|
||||||
shape = JsonFormat.Shape.STRING,
|
ZonedDateTime modifiedDate,
|
||||||
pattern = "yyyy-MM-dd'T'HH:mm:ssXXX",
|
Long activeAnimalCount) {
|
||||||
timezone = "Asia/Seoul")
|
super(id, uuid, name, location, description, createdDate, modifiedDate);
|
||||||
private ZonedDateTime modifiedDate;
|
this.activeAnimalCount = activeAnimalCount;
|
||||||
|
|
||||||
public Basic(
|
|
||||||
Long id,
|
|
||||||
String uuid,
|
|
||||||
String name,
|
|
||||||
String location,
|
|
||||||
String description,
|
|
||||||
ZonedDateTime createdDate,
|
|
||||||
ZonedDateTime modifiedDate) {
|
|
||||||
this.id = id;
|
|
||||||
this.uuid = uuid;
|
|
||||||
this.name = name;
|
|
||||||
this.location = location;
|
|
||||||
this.description = description;
|
|
||||||
this.createdDate = createdDate;
|
|
||||||
this.modifiedDate = modifiedDate;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public static class Detail extends Basic {
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class SearchReq {
|
||||||
|
|
||||||
private Long activeAnimalCount;
|
// 검색 조건
|
||||||
|
private String name;
|
||||||
|
private String location;
|
||||||
|
|
||||||
public Detail(
|
// 페이징 파라미터
|
||||||
Long id,
|
private int page = 0;
|
||||||
String uuid,
|
private int size = 20;
|
||||||
String name,
|
private String sort;
|
||||||
String location,
|
|
||||||
String description,
|
public Pageable toPageable() {
|
||||||
ZonedDateTime createdDate,
|
if (sort != null && !sort.isEmpty()) {
|
||||||
ZonedDateTime modifiedDate,
|
String[] sortParams = sort.split(",");
|
||||||
Long activeAnimalCount) {
|
String property = sortParams[0];
|
||||||
super(id, uuid, name, location, description, createdDate, modifiedDate);
|
Sort.Direction direction =
|
||||||
this.activeAnimalCount = activeAnimalCount;
|
sortParams.length > 1
|
||||||
}
|
? Sort.Direction.fromString(sortParams[1])
|
||||||
}
|
: Sort.Direction.ASC;
|
||||||
|
return PageRequest.of(page, size, Sort.by(direction, property));
|
||||||
@Getter
|
}
|
||||||
@Setter
|
return PageRequest.of(page, size);
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
public static class SearchReq {
|
|
||||||
|
|
||||||
// 검색 조건
|
|
||||||
private String name;
|
|
||||||
private String location;
|
|
||||||
|
|
||||||
// 페이징 파라미터
|
|
||||||
private int page = 0;
|
|
||||||
private int size = 20;
|
|
||||||
private String sort;
|
|
||||||
|
|
||||||
public Pageable toPageable() {
|
|
||||||
if (sort != null && !sort.isEmpty()) {
|
|
||||||
String[] sortParams = sort.split(",");
|
|
||||||
String property = sortParams[0];
|
|
||||||
Sort.Direction direction =
|
|
||||||
sortParams.length > 1
|
|
||||||
? Sort.Direction.fromString(sortParams[1])
|
|
||||||
: Sort.Direction.ASC;
|
|
||||||
return PageRequest.of(page, size, Sort.by(direction, property));
|
|
||||||
}
|
|
||||||
return PageRequest.of(page, size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user