feat: add zoo sample
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
package com.kamco.cd.kamcoback.zoo;
|
||||
|
||||
import com.kamco.cd.kamcoback.zoo.dto.ZooDto;
|
||||
import com.kamco.cd.kamcoback.zoo.service.ZooService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping({"/api/zoos", "/v1/api/zoos"})
|
||||
public class ZooApiController {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 동물원 검색 (페이징)
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user