Skip to content

Commit

Permalink
feat: 컨트롤러, 도메인, dto 초안 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
nohy6630 committed Sep 9, 2023
1 parent 5efa4ba commit a25d8c7
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/main/java/com/teamB/pcs/controller/ArticleController.java
Original file line number Diff line number Diff line change
@@ -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<ArticleResponse> 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);
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/teamB/pcs/domain/Article.java
Original file line number Diff line number Diff line change
@@ -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<String> tagList;//따로 태그 엔티티를 파야하나?

@CreationTimestamp
private LocalDateTime createdAt;

@UpdateTimestamp
private LocalDateTime updatedAt;
}
4 changes: 4 additions & 0 deletions src/main/java/com/teamB/pcs/dto/request/ArticleRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.teamB.pcs.dto.request;

public class ArticleRequest {
}
36 changes: 36 additions & 0 deletions src/main/java/com/teamB/pcs/dto/response/ArticleResponse.java
Original file line number Diff line number Diff line change
@@ -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<String> 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();
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/teamB/pcs/repository/ArticleRepository.java
Original file line number Diff line number Diff line change
@@ -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<Article, Long> {
}
19 changes: 19 additions & 0 deletions src/main/java/com/teamB/pcs/service/ArticleService.java
Original file line number Diff line number Diff line change
@@ -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<ArticleResponse> getAll() {
return articleRepository.findAll().stream()
.map()
}
}

0 comments on commit a25d8c7

Please sign in to comment.