feat: add zoo sample_test1

This commit is contained in:
2025-11-17 12:24:42 +09:00
parent 2fed53abe2
commit 1c38d4eecd
4 changed files with 241 additions and 241 deletions

View File

@@ -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);
}
}