diff --git a/build.gradle b/build.gradle index 78dac900..c9b56701 100644 --- a/build.gradle +++ b/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' diff --git a/src/main/java/com/kamco/cd/kamcoback/zoo/ZooApiController.java b/src/main/java/com/kamco/cd/kamcoback/zoo/ZooApiController.java index 652532a2..a66ad94c 100644 --- a/src/main/java/com/kamco/cd/kamcoback/zoo/ZooApiController.java +++ b/src/main/java/com/kamco/cd/kamcoback/zoo/ZooApiController.java @@ -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 createZoo(@RequestBody ZooDto.AddReq req) { - ZooDto.Detail created = zooService.createZoo(req); - return ResponseEntity.status(HttpStatus.CREATED).body(created); - } + /** + * 동물원 생성 + * + * @param req 동물원 생성 요청 + * @return 생성된 동물원 정보 (동물 개수 포함) + */ + @PostMapping + public ResponseEntity 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 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 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 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 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> 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 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> 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 zoos = zooService.search(searchReq); + return ResponseEntity.ok(zoos); + } } diff --git a/src/main/java/com/kamco/cd/kamcoback/zoo/dto/AnimalDto.java b/src/main/java/com/kamco/cd/kamcoback/zoo/dto/AnimalDto.java index 335079b1..856d256d 100644 --- a/src/main/java/com/kamco/cd/kamcoback/zoo/dto/AnimalDto.java +++ b/src/main/java/com/kamco/cd/kamcoback/zoo/dto/AnimalDto.java @@ -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); } + } } diff --git a/src/main/java/com/kamco/cd/kamcoback/zoo/dto/ZooDto.java b/src/main/java/com/kamco/cd/kamcoback/zoo/dto/ZooDto.java index 4182278d..805419db 100644 --- a/src/main/java/com/kamco/cd/kamcoback/zoo/dto/ZooDto.java +++ b/src/main/java/com/kamco/cd/kamcoback/zoo/dto/ZooDto.java @@ -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); } + } }