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