-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from J2KB-3rd-Season/kyudong
게시글 기능 구현
- Loading branch information
Showing
15 changed files
with
423 additions
and
95 deletions.
There are no files selected for viewing
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
42 changes: 37 additions & 5 deletions
42
src/main/java/com/devin/dev/controller/post/PostController.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 |
---|---|---|
@@ -1,25 +1,57 @@ | ||
package com.devin.dev.controller.post; | ||
|
||
import com.devin.dev.controller.reply.ReplyOrderCondition; | ||
import com.devin.dev.dto.post.PostDetailsDto; | ||
import com.devin.dev.model.DefaultResponse; | ||
import com.devin.dev.security.JwtAuthTokenProvider; | ||
import com.devin.dev.service.PostService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class PostController { | ||
|
||
private final PostService postService; | ||
|
||
@GetMapping("/postlist/posts") | ||
public DefaultResponse<?> getPostList(@RequestParam(defaultValue = "-1")Long id, | ||
@PageableDefault(page = 0, sort = "createdDate", direction = Sort.Direction.DESC) Pageable pageable) { | ||
public DefaultResponse<?> getPostList(@RequestParam(defaultValue = "-1") Long id, | ||
@PageableDefault(page = 0, sort = "createdDate", direction = Sort.Direction.DESC) Pageable pageable) { | ||
return postService.getPostInfoList(id, pageable); | ||
} | ||
|
||
@GetMapping("/postlist/{id}") | ||
public DefaultResponse<PostDetailsDto> getPostDetails( | ||
@PathVariable("id") Long postId, | ||
@RequestParam(defaultValue = "true", name = "sort_reply") boolean sort_reply) { | ||
ReplyOrderCondition replyOrderCondition = new ReplyOrderCondition(); | ||
if (!sort_reply) { | ||
replyOrderCondition.setLatestDate(true); | ||
} else { | ||
replyOrderCondition.setLikeCount(true); | ||
} | ||
return postService.getPost(postId, replyOrderCondition); | ||
} | ||
|
||
@GetMapping("/postlist") | ||
public DefaultResponse<?> getPostListByCondition( | ||
PostSearchCondition condition, | ||
@PageableDefault(page = 0, sort = "createdDate", direction = Sort.Direction.DESC) Pageable pageable) { | ||
return postService.getPostInfoListByCondition(condition, pageable); | ||
} | ||
|
||
@DeleteMapping("/post/{id}") | ||
public DefaultResponse<PostDetailsDto> deletePost(@PathVariable("id") Long postId) { | ||
return postService.deletePost(postId); | ||
} | ||
|
||
@PostMapping("/post") | ||
public DefaultResponse<?> post(@RequestBody PostForm form, HttpServletRequest request) { | ||
return postService.post(request, form); | ||
} | ||
} |
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,13 @@ | ||
package com.devin.dev.controller.post; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class PostForm { | ||
private String title; | ||
private String content; | ||
private List<String> post_images; | ||
private List<String> post_tags; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/devin/dev/controller/reply/ReplyOrderCondition.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,9 @@ | ||
package com.devin.dev.controller.reply; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class ReplyOrderCondition { | ||
private boolean likeCount; | ||
private boolean latestDate; | ||
} |
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
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 |
---|---|---|
@@ -1,25 +1,56 @@ | ||
package com.devin.dev.dto.post; | ||
|
||
import com.devin.dev.entity.reply.Reply; | ||
import com.devin.dev.entity.reply.ReplyImage; | ||
import com.devin.dev.entity.reply.ReplyStatus; | ||
import com.querydsl.core.annotations.QueryProjection; | ||
import lombok.Data; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Data | ||
public class PostReplyDto { | ||
|
||
private Long postId; | ||
private Long userId; | ||
private String username; | ||
private Long reply_id; | ||
private Long publisher_id; | ||
private String publisher_name; | ||
private String publisher_profile; | ||
private Long publisher_exp; | ||
private String content; | ||
private List<String> imagePaths; | ||
private List<String> reply_images; | ||
private boolean status_accept; | ||
private Integer like_num; | ||
private LocalDateTime date_create; | ||
private LocalDateTime date_update; | ||
|
||
@QueryProjection | ||
public PostReplyDto(Long postId, Long userId, String username, String content, List<String> imagePaths) { | ||
this.postId = postId; | ||
this.userId = userId; | ||
this.username = username; | ||
public PostReplyDto(Long reply_id, Long publisher_id, String publisher_name, String publisher_profile, Long publisher_exp, String content, List<String> reply_images, boolean status_accept, boolean like_reply, Integer like_num, LocalDateTime date_create, LocalDateTime date_update) { | ||
this.reply_id = reply_id; | ||
this.publisher_id = publisher_id; | ||
this.publisher_name = publisher_name; | ||
this.publisher_profile = publisher_profile; | ||
this.publisher_exp = publisher_exp; | ||
this.content = content; | ||
this.imagePaths = imagePaths; | ||
this.reply_images = reply_images; | ||
this.status_accept = status_accept; | ||
this.like_num = like_num; | ||
this.date_create = date_create; | ||
this.date_update = date_update; | ||
} | ||
|
||
public PostReplyDto(Reply reply) { | ||
this.reply_id = reply.getId(); | ||
this.publisher_id = reply.getUser().getId(); | ||
this.publisher_name = reply.getUser().getName(); | ||
this.publisher_profile = reply.getUser().getProfile(); | ||
this.publisher_exp = reply.getUser().getExp(); | ||
this.content = reply.getContent(); | ||
this.reply_images = reply.getImages().stream().map(ReplyImage::getPath).collect(Collectors.toList()); | ||
this.status_accept = ReplyStatus.SELECTED == reply.getStatus(); | ||
this.like_num = reply.getLikes().size(); | ||
this.date_create = reply.getCreatedDate(); | ||
this.date_update = reply.getLastModifiedDate(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/devin/dev/repository/post/PostLikeRepository.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.devin.dev.repository.post; | ||
|
||
import com.devin.dev.entity.post.PostLike; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PostLikeRepository extends JpaRepository<PostLike, Long> { | ||
} |
8 changes: 7 additions & 1 deletion
8
src/main/java/com/devin/dev/repository/post/PostRepositoryQuery.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 |
---|---|---|
@@ -1,21 +1,27 @@ | ||
package com.devin.dev.repository.post; | ||
|
||
import com.devin.dev.controller.post.PostSearchCondition; | ||
import com.devin.dev.controller.reply.ReplyOrderCondition; | ||
import com.devin.dev.dto.post.PostDetailsDto; | ||
import com.devin.dev.dto.post.PostInfoDto; | ||
import com.devin.dev.dto.post.PostSimpleDto; | ||
import com.devin.dev.entity.post.Post; | ||
import com.devin.dev.entity.user.User; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface PostRepositoryQuery { | ||
|
||
Page<String> findPostnamePageByUser(User user, Pageable pageable); | ||
|
||
Page<PostSimpleDto> findPostDtoPageWithCondition(PostSearchCondition condition, Pageable pageable); | ||
Page<PostInfoDto> findPostInfoDtoPageByCondition(PostSearchCondition condition, Pageable pageable); | ||
|
||
List<PostSimpleDto> findPostDtoByUser(User user); | ||
|
||
Page<Post> findAllByTagId(Long id, Pageable pageable); | ||
|
||
Optional<PostDetailsDto> findPostDetailsById(Long id, ReplyOrderCondition condition); | ||
} |
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
Oops, something went wrong.