-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/com/teamB/pcs/controller/ArticleController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
src/main/java/com/teamB/pcs/dto/response/ArticleResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
7
src/main/java/com/teamB/pcs/repository/ArticleRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |