-
Notifications
You must be signed in to change notification settings - Fork 1
Refactory of PR #13 #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 39 commits
e313192
fe9b97e
d85b433
5a563f8
71c21fb
10e249c
67e0277
247011c
c305540
bdc530d
e76bd33
e33831b
55fa8a2
3d14903
ea9c945
6630e49
8a8d54a
3d08cfe
877e468
a72394c
5d5be0a
9c66e7c
dd1ba9b
48c9199
d2f4145
7c153c1
2073414
ac9ac26
3b99ccf
6fd13b0
a8d6e2f
66e9e2c
3f9dd47
735a3b1
12108ba
0a096e7
770b41a
0f4ae6a
7404b0f
53fcee5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.gdsc.blog.mapper; | ||
|
|
||
| import com.gdsc.blog.article.dto.ArticleDto; | ||
| import com.gdsc.blog.article.entity.Article; | ||
| import com.gdsc.blog.comment.entity.Comment; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import javax.annotation.processing.Generated; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Generated( | ||
| value = "org.mapstruct.ap.MappingProcessor", | ||
| date = "2023-07-17T01:17:13+0900", | ||
| comments = "version: 1.5.5.Final, compiler: javac, environment: Java 17.0.7 (Oracle Corporation)" | ||
| ) | ||
| @Component | ||
| public class ArticleMapperImpl implements ArticleMapper { | ||
|
|
||
| @Override | ||
| public ArticleDto toDto(Article article) { | ||
| if ( article == null ) { | ||
| return null; | ||
| } | ||
|
|
||
| ArticleDto.ArticleDtoBuilder articleDto = ArticleDto.builder(); | ||
|
|
||
| articleDto.idx( article.getIdx() ); | ||
| articleDto.title( article.getTitle() ); | ||
| articleDto.content( article.getContent() ); | ||
| List<Comment> list = article.getComments(); | ||
| if ( list != null ) { | ||
| articleDto.comments( new ArrayList<Comment>( list ) ); | ||
| } | ||
|
|
||
| articleDto.username( article.getUser().getUsername() ); | ||
| articleDto.createdAt( article.getCreateDate().toLocalDateTime() ); | ||
| articleDto.modifiedAt( article.getModifyDate().toLocalDateTime() ); | ||
|
|
||
| return articleDto.build(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| package com.gdsc.blog.article.controller; | ||
|
|
||
| import com.gdsc.blog.article.dto.ArticleCreateDto; | ||
| import com.gdsc.blog.article.dto.ArticleDto; | ||
| import com.gdsc.blog.article.dto.ArticleUpdateDto; | ||
| import com.gdsc.blog.article.service.ArticleService; | ||
| import com.gdsc.blog.security.jwt.JwtTokenProvider; | ||
| import com.gdsc.blog.user.service.UserService; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Controller | ||
| @RequestMapping("/api/article") | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @Tag(name = "게시글 Controller", description = "Article controller API") | ||
| @Slf4j | ||
| public class ArticleController { | ||
|
|
||
| private final ArticleService articleService; | ||
| private final UserService userService; | ||
| private final JwtTokenProvider jwtTokenProvider; | ||
|
|
||
| /** | ||
| * 게시글 생성 API | ||
| * | ||
| * @param articleCreateDto 게시글 생성 DTO | ||
| * @return 생성된 게시글 | ||
| */ | ||
| @PostMapping //컨트롤러 메핑 | ||
| @Operation(summary = "게시글 생성") //swagger 설명 | ||
| public ArticleDto createArticle( | ||
| @Parameter(name = "게시글 생성 DTO") @RequestBody ArticleCreateDto articleCreateDto, | ||
| @Parameter(hidden = true) HttpServletRequest req) { | ||
|
|
||
| String username = jwtTokenProvider.getUsername(jwtTokenProvider.resolveToken(req)); | ||
| return articleService.createArticle(articleCreateDto, username); | ||
| } | ||
|
|
||
| /** | ||
| * 최근 게시글 조회 API | ||
| * | ||
| * @return 게시글 목록 | ||
| */ | ||
| @GetMapping | ||
| @Operation(summary = "최근 게시글 조회") | ||
| public List<ArticleDto> getUserArticle() { | ||
| return articleService.getRecentArticle(); | ||
| } | ||
|
|
||
| /** | ||
| * id 로 게시글 조회 | ||
| * | ||
| * @param id 게시글 id | ||
| * @param req HTTP 파싱 객체 | ||
| * @return 게시글 | ||
| */ | ||
| @GetMapping("/{id}") | ||
| @Operation(summary = "id로 게시글 조회") | ||
| public ArticleDto getArticleById( | ||
| @Parameter(description = "게시글 id") @PathVariable("id") Long id) { | ||
| return articleService.getArticleById(id); | ||
| } | ||
|
|
||
| /** | ||
| * 제목으로 게시글 조회 | ||
| * | ||
| * @param title 게시글 제목 | ||
| * @param req HTTP 파싱 객체 | ||
| * @return 게시글 | ||
| */ | ||
| @GetMapping("/search") | ||
| @Operation(summary = "제목으로 게시글 조회") | ||
| public List<ArticleDto> getArticleByTitle( | ||
| @Parameter(description = "게시글 제목") @RequestParam String title, | ||
| @Parameter(hidden = true) HttpServletRequest req) { | ||
| return articleService.findArticleByTitle(title); | ||
| } | ||
|
|
||
| /** | ||
| * 게시글 수정 | ||
| * | ||
| * @param id 게시글 id | ||
| * @param dto 게시글 수정 정보 | ||
| * @param req HTTP 파싱 객체 | ||
| */ | ||
| @PatchMapping("/{id}") | ||
| @Operation(summary = "게시글 수정") | ||
| public ArticleDto updateArticle( | ||
| @Parameter(description = "게시글 id") @PathVariable(value = "id") Long id, | ||
| @Parameter(name = "게시글 수정 DTO") @RequestBody ArticleUpdateDto dto, | ||
| @Parameter(hidden = true) HttpServletRequest req) { | ||
|
|
||
| String username = jwtTokenProvider.getUsername(jwtTokenProvider.resolveToken(req)); | ||
| return articleService.updateArticle(id, dto, username); | ||
| } | ||
|
|
||
| /** | ||
| * 게시글 삭제 API | ||
| * | ||
| * @param id 게시글 id | ||
| * @param req HTTP 파싱 객체 | ||
| */ | ||
| @DeleteMapping("/{id}") | ||
| @PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_CLIENT')") | ||
| @Operation(summary = "게시글 삭제") | ||
| public void deleteArticle( | ||
| @Parameter(description = "게시글 id") @PathVariable(value = "id") Long id, | ||
| @Parameter(hidden = true) HttpServletRequest req) { | ||
|
|
||
| String username = jwtTokenProvider.getUsername(jwtTokenProvider.resolveToken(req)); | ||
| articleService.deleteArticle(id, username); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.gdsc.blog.article.dto; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import lombok.*; | ||
|
|
||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Builder | ||
| @Getter | ||
| @Setter | ||
| public class ArticleCreateDto { | ||
| @Schema(description = "제목", example = "게시글 제목") | ||
| public String title; | ||
|
|
||
| @Schema(description = "내용", example = "게시글 내용") | ||
| public String content; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package com.gdsc.blog.article.dto; | ||
|
|
||
| import com.gdsc.blog.comment.entity.Comment; | ||
| import lombok.*; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
|
|
||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @ToString | ||
| @Builder | ||
| @Getter | ||
| @Setter | ||
| public class ArticleDto { | ||
| private Long idx; | ||
| private String title; | ||
| private String content; | ||
| private LocalDateTime createdAt; | ||
| private LocalDateTime modifiedAt; | ||
| private String username; | ||
| private List<Comment> comments; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.gdsc.blog.article.dto; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import lombok.*; | ||
|
|
||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Builder | ||
| @Getter | ||
| @Setter | ||
| public class ArticleUpdateDto { | ||
| @Schema(description = "수정할 제목", example = "수정된 게시글 제목") | ||
| public String title; | ||
|
|
||
| @Schema(description = "수정할 내용", example = "수정된 게시글 내용") | ||
| public String content; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generated 코드가 깃으로 올라오면 곤란한데... 이거는 실수로 올라온 건지 확인이 필요할 거 같네요