content: package com.ahastudio.api.rest.demo.controllers;
  
  import java.util.List;
  
  import org.springframework.http.HttpStatus;
  import org.springframework.web.bind.annotation.DeleteMapping;
  import org.springframework.web.bind.annotation.ExceptionHandler;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.PatchMapping;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.ResponseStatus;
  import org.springframework.web.bind.annotation.RestController;
  
  import com.ahastudio.api.rest.demo.application.GetPostDtoListService;
  import com.ahastudio.api.rest.demo.application.PostService;
  import com.ahastudio.api.rest.demo.dtos.PostDto;
  import com.ahastudio.api.rest.demo.exceptions.PostNotFound;
  
  @RestController
  @RequestMapping("/posts")
  public class PostController {
      private final GetPostDtoListService getPostDtoListService;
      private final PostService postService;
  
      public PostController(GetPostDtoListService getPostDtoListService,
                            PostService postService) {
          this.getPostDtoListService = getPostDtoListService;
          this.postService = postService;
      }
  
      @GetMapping
      public List<PostDto> list() {
          List<PostDto> postDtos = getPostDtoListService.getPostDtos();
  
          return postDtos;
      }
  
      @GetMapping("/{id}")
      public PostDto detail(@PathVariable String id) {
          PostDto postDto = postService.getPostDto(id);
  
          return postDto;
      }
  
      @PostMapping
      @ResponseStatus(HttpStatus.CREATED)
      public PostDto create(@RequestBody PostDto postDto) {
          PostDto created = postService.createPost(postDto);
  
          return created;
      }
  
      @PatchMapping("/{id}")
      public PostDto update(@PathVariable String id,
                            @RequestBody PostDto postDto) {
          PostDto updated = postService.updatePost(id, postDto);
  
          return updated;
      }
  
      @DeleteMapping("/{id}")
      public PostDto delete(@PathVariable String id) {
          PostDto postDto = postService.deletePost(id);
  
          return postDto;
      }
  
      @ExceptionHandler(PostNotFound.class)
      @ResponseStatus(HttpStatus.NOT_FOUND)
      public String postNotFound() {
          return "게시물을 찾을 수 없습니다\n";
      }
  }
  