package com.its.op.controller.database; import com.its.op.model.dto.LinkDto; import com.its.op.model.entity.Link; import com.its.op.service.database.TbLinkService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; @Slf4j @RequiredArgsConstructor @RestController @RequestMapping("/api/database/tb-link") @Api(tags = "09.기초데이터관리-02.링크", description="링크") public class TbLinkController { private final TbLinkService service; @ApiOperation(value = "전체조회(TB_LINK)", response = LinkDto.LinkInfo.class) @GetMapping(value = "", produces = {"application/json; charset=utf8"}) public ResponseEntity> findAll() { List data = this.service.findAll(); List result = new ArrayList<>(); for (Link obj: data) { result.add(new LinkDto.LinkInfo(obj)); } return new ResponseEntity<>(result, HttpStatus.OK); } @ApiOperation(value = "개별조회(TB_LINK)", response = LinkDto.LinkInfo.class) @GetMapping(value = "/{id}", produces = {"application/json; charset=utf8"}) public ResponseEntity findById(@PathVariable final Long id) { Link obj = this.service.findById(id); if (obj != null) { return new ResponseEntity<>(new LinkDto.LinkInfo(obj), HttpStatus.OK); } return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);//NO_CONTENT); } @ApiOperation(value = "도로명변경(TB_LINK)", response = LinkDto.LinkInfo.class) @PutMapping(value = "/{id}", produces = {"application/json; charset=utf8"}) public ResponseEntity updateNameById(@PathVariable final Long id, @RequestBody final LinkDto.LinkNameUpdateReq req) { Link obj = this.service.updateNameById(id, req); if (obj != null) { return new ResponseEntity<>(new LinkDto.LinkInfo(obj), HttpStatus.OK); } return new ResponseEntity<>(null, HttpStatus.NOT_FOUND);//NO_CONTENT); } }