From a25d8c7e4d0a825342daf71d3615f5cabc7ad916 Mon Sep 17 00:00:00 2001 From: nohy6630 Date: Sat, 9 Sep 2023 15:56:15 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC,?= =?UTF-8?q?=20=EB=8F=84=EB=A9=94=EC=9D=B8,=20dto=20=EC=B4=88=EC=95=88=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pcs/controller/ArticleController.java | 42 +++++++++++++++++++ .../java/com/teamB/pcs/domain/Article.java | 36 ++++++++++++++++ .../teamB/pcs/dto/request/ArticleRequest.java | 4 ++ .../pcs/dto/response/ArticleResponse.java | 36 ++++++++++++++++ .../pcs/repository/ArticleRepository.java | 7 ++++ .../com/teamB/pcs/service/ArticleService.java | 19 +++++++++ 6 files changed, 144 insertions(+) create mode 100644 src/main/java/com/teamB/pcs/controller/ArticleController.java create mode 100644 src/main/java/com/teamB/pcs/domain/Article.java create mode 100644 src/main/java/com/teamB/pcs/dto/request/ArticleRequest.java create mode 100644 src/main/java/com/teamB/pcs/dto/response/ArticleResponse.java create mode 100644 src/main/java/com/teamB/pcs/repository/ArticleRepository.java create mode 100644 src/main/java/com/teamB/pcs/service/ArticleService.java diff --git a/src/main/java/com/teamB/pcs/controller/ArticleController.java b/src/main/java/com/teamB/pcs/controller/ArticleController.java new file mode 100644 index 0000000..9e8ab24 --- /dev/null +++ b/src/main/java/com/teamB/pcs/controller/ArticleController.java @@ -0,0 +1,42 @@ +package com.teamB.pcs.controller; + +import com.teamB.pcs.dto.request.ArticleRequest; +import com.teamB.pcs.dto.response.ArticleResponse; +import com.teamB.pcs.service.ArticleService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/articles") +public class ArticleController { + private final ArticleService articleService; + + @GetMapping("") + public List getAll(){ + return articleService.getAll(); + } + + @PostMapping("/{articleId}") + public void create(@PathVariable Long articleId, @RequestBody ArticleRequest articleRequest){ + return articleService.create(articleId, articleRequest); + } + + @GetMapping("/{articleId}") + public ArticleResponse get(@PathVariable Long articleId){ + return articleService.get(articleId); + } + + @PutMapping("/{articleId}") + public void update(@PathVariable Long articleId, @RequestBody ArticleRequest articleRequest){ + return articleService.update(articleId, articleRequest); + } + + @DeleteMapping("/{articleId}") + public void delete(@PathVariable Long articleId){ + return articleService.delete(articleId); + } +} diff --git a/src/main/java/com/teamB/pcs/domain/Article.java b/src/main/java/com/teamB/pcs/domain/Article.java new file mode 100644 index 0000000..005781a --- /dev/null +++ b/src/main/java/com/teamB/pcs/domain/Article.java @@ -0,0 +1,36 @@ +package com.teamB.pcs.domain; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +import java.time.LocalDateTime; +import java.util.List; + +@Entity +@NoArgsConstructor +@Getter +public class Article { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String title; + + private String description; + + private String body; + + private List tagList;//따로 태그 엔티티를 파야하나? + + @CreationTimestamp + private LocalDateTime createdAt; + + @UpdateTimestamp + private LocalDateTime updatedAt; +} diff --git a/src/main/java/com/teamB/pcs/dto/request/ArticleRequest.java b/src/main/java/com/teamB/pcs/dto/request/ArticleRequest.java new file mode 100644 index 0000000..5cc689b --- /dev/null +++ b/src/main/java/com/teamB/pcs/dto/request/ArticleRequest.java @@ -0,0 +1,4 @@ +package com.teamB.pcs.dto.request; + +public class ArticleRequest { +} diff --git a/src/main/java/com/teamB/pcs/dto/response/ArticleResponse.java b/src/main/java/com/teamB/pcs/dto/response/ArticleResponse.java new file mode 100644 index 0000000..b807d51 --- /dev/null +++ b/src/main/java/com/teamB/pcs/dto/response/ArticleResponse.java @@ -0,0 +1,36 @@ +package com.teamB.pcs.dto.response; + +import com.teamB.pcs.domain.Article; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; +import java.util.List; + +@NoArgsConstructor +@Getter +public class ArticleResponse { + private Long id; + + private String title; + + private String description; + + private String body; + + private List tagList; + + private LocalDateTime createdAt;//반환할때 LocalDateTime으로 해도되나? + + private LocalDateTime updatedAt; + + public ArticleResponse(Article article){ + id=article.getId(); + title=article.getTitle(); + description=article.getDescription(); + body=article.getBody(); + tagList=article.getTagList(); + createdAt=article.getCreatedAt(); + updatedAt=article.getUpdatedAt(); + } +} diff --git a/src/main/java/com/teamB/pcs/repository/ArticleRepository.java b/src/main/java/com/teamB/pcs/repository/ArticleRepository.java new file mode 100644 index 0000000..9993338 --- /dev/null +++ b/src/main/java/com/teamB/pcs/repository/ArticleRepository.java @@ -0,0 +1,7 @@ +package com.teamB.pcs.repository; + +import com.teamB.pcs.domain.Article; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface ArticleRepository extends JpaRepository { +} diff --git a/src/main/java/com/teamB/pcs/service/ArticleService.java b/src/main/java/com/teamB/pcs/service/ArticleService.java new file mode 100644 index 0000000..d89fdac --- /dev/null +++ b/src/main/java/com/teamB/pcs/service/ArticleService.java @@ -0,0 +1,19 @@ +package com.teamB.pcs.service; + +import com.teamB.pcs.dto.response.ArticleResponse; +import com.teamB.pcs.repository.ArticleRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class ArticleService { + private final ArticleRepository articleRepository; + + public List getAll() { + return articleRepository.findAll().stream() + .map() + } +}