Skip to content

Commit

Permalink
Merge pull request #29 from enjay27/master
Browse files Browse the repository at this point in the history
주요 기능 추가
  • Loading branch information
enjay27 authored Jun 11, 2021
2 parents 3d74167 + 9e53ee8 commit e9c1cf8
Show file tree
Hide file tree
Showing 28 changed files with 792 additions and 125 deletions.
19 changes: 15 additions & 4 deletions src/main/java/com/devin/dev/controller/post/PostController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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;
Expand All @@ -28,14 +27,15 @@ public DefaultResponse<?> getPostList(@RequestParam(defaultValue = "-1") Long id
@GetMapping("/postlist/{id}")
public DefaultResponse<PostDetailsDto> getPostDetails(
@PathVariable("id") Long postId,
@RequestParam(defaultValue = "true", name = "sort_reply") boolean sort_reply) {
@RequestParam(defaultValue = "true", name = "sort_reply") boolean sort_reply,
HttpServletRequest request) {
ReplyOrderCondition replyOrderCondition = new ReplyOrderCondition();
if (!sort_reply) {
replyOrderCondition.setLatestDate(true);
} else {
replyOrderCondition.setLikeCount(true);
}
return postService.getPost(postId, replyOrderCondition);
return postService.getPost(postId, replyOrderCondition, request);
}

@GetMapping("/postlist")
Expand All @@ -52,6 +52,17 @@ public DefaultResponse<PostDetailsDto> deletePost(@PathVariable("id") Long postI

@PostMapping("/post")
public DefaultResponse<?> post(@RequestBody PostForm form, HttpServletRequest request) {
return postService.post(request, form);
return postService.post(form, request);
}

@PatchMapping("/post/{id}/like")
public DefaultResponse<?> changePostLike(@PathVariable("id") Long postId, HttpServletRequest request) {
return postService.changePostLike(postId, request);
}

@PutMapping("/post/{id}/update")
public DefaultResponse<?> reply(@PathVariable("id") Long replyId, @RequestBody PostUpdateForm form, HttpServletRequest request) {
return postService.editPost(replyId, form, request);
}

}
23 changes: 23 additions & 0 deletions src/main/java/com/devin/dev/controller/post/PostUpdateForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.devin.dev.controller.post;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
public class PostUpdateForm {
private String title;
private String content;
private List<String> post_images;
private List<String> post_tags;

public PostUpdateForm(Long id, String title, String content, List<String> post_images, List<String> post_tags) {
this.title = title;
this.content = content;
this.post_images = post_images;
this.post_tags = post_tags;
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/devin/dev/controller/post/ReplyUpdateForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.devin.dev.controller.post;

import lombok.Data;

import javax.validation.constraints.NotEmpty;
import java.util.List;

@Data
public class ReplyUpdateForm {
@NotEmpty
private String content;

private List<String> reply_image;
}
43 changes: 23 additions & 20 deletions src/main/java/com/devin/dev/controller/reply/ReplyController.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.devin.dev.controller.reply;

import com.devin.dev.controller.post.ReplyUpdateForm;
import com.devin.dev.dto.reply.ReplyDto;
import com.devin.dev.model.DefaultResponse;
import com.devin.dev.service.ReplyService;
Expand All @@ -10,6 +11,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;
Expand All @@ -20,16 +22,29 @@ public class ReplyController {

private final ReplyService replyService;

@PostMapping("/replies")
public DefaultResponse<?> saveReply(@RequestBody @Valid CreateReplyRequest request) {
return replyService.reply(request.getUserId(), request.getPostId(), request.getContent(), request.getReplyImages());
@PostMapping("/reply")
public DefaultResponse<?> reply(@RequestBody @Valid ReplyForm form, HttpServletRequest request) {
return replyService.reply(form, request);
}

@GetMapping("/reply/{id}")
public Page<ReplyDto> findReplies(
@PathVariable("id") Long postId, Pageable pageable) {
DefaultResponse<Page<ReplyDto>> response = replyService.findRepliesInPost(postId, pageable);
return response.getData();
@PutMapping("/reply/{id}/update")
public DefaultResponse<?> editReply(@PathVariable("id") Long replyId, @RequestBody @Valid ReplyUpdateForm form, HttpServletRequest request) {
return replyService.editReply(replyId, form, request);
}

@DeleteMapping("/reply/{id}")
public DefaultResponse<?> deleteReply(@PathVariable("id") Long replyId, HttpServletRequest request) {
return replyService.deleteReply(replyId, request);
}

@PatchMapping("/reply/{id}/like")
public DefaultResponse<?> changeReplyLike(@PathVariable("id") Long replyId, HttpServletRequest request) {
return replyService.changeReplyLike(replyId, request);
}

@PatchMapping("/reply/{id}/select")
public DefaultResponse<?> selectReply(@PathVariable("id") Long replyId, HttpServletRequest request) {
return replyService.selectReply(replyId, request);
}

@Data
Expand All @@ -41,18 +56,6 @@ public CreateReplyResponse(Long id) {
}
}

@Data
private static class CreateReplyRequest {
@NotEmpty
private Long postId;
@NotEmpty
private Long userId;
@NotEmpty
private String content;
@NotEmpty
private List<String> replyImages;
}

@Data
@AllArgsConstructor
static class Result<T> {
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/devin/dev/controller/reply/ReplyForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.devin.dev.controller.reply;

import lombok.Data;

import javax.validation.constraints.NotEmpty;
import java.util.List;

@Data
public class ReplyForm {
@NotEmpty
private Long id;
@NotEmpty
private String content;

private List<String> reply_image;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.devin.dev.controller.subject;

import com.devin.dev.model.DefaultResponse;
import com.devin.dev.service.SubjectService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequiredArgsConstructor
public class SubjectController {

private final SubjectService subjectService;

@PostMapping("/tags")
public DefaultResponse<?> addSubject(@RequestBody SubjectForm form, HttpServletRequest request) {
return subjectService.addSubject(form, request);
}

@DeleteMapping("/tags")
public DefaultResponse<?> deleteSubject(@RequestBody SubjectForm form, HttpServletRequest request) {
return subjectService.removeSubject(form, request);
}

@GetMapping("/tags")
public DefaultResponse<?> getSubject() {
return subjectService.getSubject();
}

}
11 changes: 11 additions & 0 deletions src/main/java/com/devin/dev/controller/subject/SubjectForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.devin.dev.controller.subject;

import lombok.Data;

import java.util.List;

@Data
public class SubjectForm {

private List<String> subjects;
}
34 changes: 32 additions & 2 deletions src/main/java/com/devin/dev/dto/post/PostDetailsDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.devin.dev.entity.post.Post;
import com.devin.dev.entity.post.PostImage;
import com.devin.dev.entity.post.PostStatus;
import com.devin.dev.entity.reply.ReplyStatus;
import com.devin.dev.entity.user.UserStatus;
import com.querydsl.core.annotations.QueryProjection;
import lombok.Data;

Expand All @@ -24,13 +26,14 @@ public class PostDetailsDto {
private List<String> post_images;
private List<String> post_tags;
private boolean status_accept;
private boolean like_post;
private LocalDateTime date_create;
private LocalDateTime date_update;
private Integer reply_num;
private List<PostReplyDto> reply;

@QueryProjection
public PostDetailsDto(Long post_id, Long publisher_id, String publisher_name, String publisher_profile, Long publisher_exp, String title, String content, List<String> post_images, List<String> post_tags, boolean status_accept, boolean like_post, LocalDateTime date_create, LocalDateTime date_update, Integer reply_num, List<PostReplyDto> replyDtos) {
public PostDetailsDto(Long post_id, Long publisher_id, String publisher_name, String publisher_profile, Long publisher_exp, String title, String content, List<String> post_images, List<String> post_tags, boolean status_accept, boolean like_post, LocalDateTime date_create, LocalDateTime date_update, Integer reply_num, List<PostReplyDto> reply) {
this.post_id = post_id;
this.publisher_id = publisher_id;
this.publisher_name = publisher_name;
Expand All @@ -41,10 +44,11 @@ public PostDetailsDto(Long post_id, Long publisher_id, String publisher_name, St
this.post_images = post_images;
this.post_tags = post_tags;
this.status_accept = status_accept;
this.like_post = like_post;
this.date_create = date_create;
this.date_update = date_update;
this.reply_num = reply_num;
this.reply = replyDtos;
this.reply = reply;
}

public PostDetailsDto(Post post) {
Expand All @@ -58,9 +62,35 @@ public PostDetailsDto(Post post) {
this.post_images = post.getImages().stream().map(PostImage::getPath).collect(Collectors.toList());
this.post_tags = post.getPostTags();
this.status_accept = post.getStatus() == PostStatus.SELECTED;
this.like_post = post.getLikes().size() > 0;
this.date_create = post.getCreatedDate();
this.date_update = post.getLastModifiedDate();
this.reply_num = post.getReplies().size();
this.reply = post.getReplies().stream().map(PostReplyDto::new).collect(Collectors.toList());
}

public PostDetailsDto(Post post, UserStatus status) {
this.post_id = post.getId();
this.publisher_id = post.getUser().getId();
this.publisher_name = post.getUser().getName();
this.publisher_profile = post.getUser().getProfile();
this.publisher_exp = post.getUser().getExp();
this.title = post.getTitle();
this.content = post.getContent();
this.post_images = post.getImages().stream().map(PostImage::getPath).collect(Collectors.toList());
this.post_tags = post.getPostTags();
this.status_accept = post.getStatus() == PostStatus.SELECTED;
this.like_post = post.getLikes().size() > 0;
this.date_create = post.getCreatedDate();
this.date_update = post.getLastModifiedDate();
this.reply_num = post.getReplies().size();
this.reply = status == UserStatus.ACTIVE || status == UserStatus.ADMIN ?
post.getReplies().stream().map(PostReplyDto::new).collect(Collectors.toList()) :
post.getReplies().stream().map(PostReplyDto::new).peek(dto -> {
if (dto.isStatus_accept()) {
dto.setContent("비회원은 볼 수 없습니다.");
dto.getReply_images().clear();
}
}).collect(Collectors.toList());
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/devin/dev/dto/post/PostInfoDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public PostInfoDto(Post post) {
this.title = post.getTitle();
this.tags = post.getPostTags();
this.statusAccept = post.getStatus() == PostStatus.SELECTED;
this.statusLike = post.getPostLikes().size() > 0;
this.statusLike = post.getLikes().size() > 0;
this.replyNum = post.getReplies().size();
this.likeNum = post.getPostLikes().size();
this.likeNum = post.getLikes().size();
this.createdDate = post.getCreatedDate();
this.userId = post.getUser().getId();
this.username = post.getUser().getName();
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/devin/dev/dto/reply/ReplyDto.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.devin.dev.dto.reply;

import com.devin.dev.entity.reply.Reply;
import com.devin.dev.entity.reply.ReplyImage;
import com.devin.dev.entity.reply.ReplyStatus;
import com.devin.dev.entity.user.UserStatus;
Expand Down Expand Up @@ -33,4 +34,11 @@ public ReplyDto(Long id, String name, String content, ReplyStatus status, Intege
this.like = like;
}

public ReplyDto(Reply reply) {
this.id = reply.getId();
this.name = reply.getUser().getName();
this.content = reply.getContent();
this.status = reply.getStatus();
this.like = reply.getLikes().size();
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/devin/dev/dto/subject/SubjectDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.devin.dev.dto.subject;

import com.devin.dev.entity.post.Subject;
import lombok.Data;

@Data
public class SubjectDto {

private Long tag_id;
private String tag_name;

public SubjectDto(Subject subject) {
this.tag_id = subject.getId();
this.tag_name = subject.getName();
}
}
9 changes: 8 additions & 1 deletion src/main/java/com/devin/dev/entity/post/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.devin.dev.entity.base.ModifiedCreated;
import com.devin.dev.entity.reply.Reply;
import com.devin.dev.entity.reply.ReplyLike;
import com.devin.dev.entity.user.User;
import lombok.AccessLevel;
import lombok.Getter;
Expand Down Expand Up @@ -36,7 +37,7 @@ public class Post extends ModifiedCreated {
private final List<PostTag> tags = new ArrayList<>();

@OneToMany(mappedBy = "post")
private final List<PostLike> postLikes = new ArrayList<>();
private final List<PostLike> likes = new ArrayList<>();

@OneToMany(mappedBy = "post")
private final List<PostImage> images = new ArrayList<>();
Expand Down Expand Up @@ -106,4 +107,10 @@ public void setPostImages(List<PostImage> postImages) {
public List<String> getPostTags() {
return this.tags.stream().map(tag -> tag.getTag().getName()).collect(Collectors.toList());
}

public PostLike like(User user, PostLike postLike) {
postLike.changePost(this);
postLike.setUser(user);
return postLike;
}
}
Loading

0 comments on commit e9c1cf8

Please sign in to comment.