Skip to content

Commit

Permalink
Merge branch 'develop' into feat/#207
Browse files Browse the repository at this point in the history
  • Loading branch information
kjeongh authored Jun 10, 2023
2 parents f5b3dce + 3b4ae6a commit 98d6c32
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class CommentService {
private final CommentMapper commentMapper;

public Comment createComment(CommentDto.CommentCreateRequest dto, Long userId) {
findByCommentId(dto.getParentId());
Comment entity = commentMapper.toCommentEntity(dto, userId);
return commentRepository.save(entity);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rising.backend.domain.post.controller;

import com.rising.backend.domain.post.domain.PostType;
import com.rising.backend.domain.post.dto.PostDto;
import com.rising.backend.domain.post.dto.PostDto.PostUpdateRequest;
import com.rising.backend.domain.post.service.PostService;
Expand Down Expand Up @@ -43,13 +44,15 @@ public ResponseEntity<ResultResponse> create(
}

@GetMapping
public ResponseEntity<ResultResponse> getList(@PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) final Pageable pageable) {
List<PostDto.PostGetListResponse> list = postService.pageList(pageable);
return ResponseEntity.ok(ResultResponse.of(ResultCode.POST_PAGINATION_SUCCESS, list));
public ResponseEntity<ResultResponse> getList(@RequestParam(value = "type", required = false) PostType postType, @PageableDefault(size = 10, sort = "createdAt", direction = Sort.Direction.DESC) final Pageable pageable) {
List<PostDto.PostGetListResponse> result = null;
if (postType == null)
result = postService.pageList(pageable);
else
result = postService.getPostsByType(postType, pageable);
return ResponseEntity.ok(ResultResponse.of(ResultCode.POST_PAGINATION_SUCCESS, result));
}



@LoginRequired
@GetMapping("/{postId}/session")
public ResponseEntity<ResultResponse> getSession(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class Post extends BaseEntity {

@NotNull
@Enumerated(EnumType.STRING)
private PostType type;
private PostType postType;

@ManyToMany
@JoinTable(name = "POST_TAG",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Post toPostEntity(PostCreateRequest postCreate, User loginUser) {
.title(postCreate.getTitle())
.videoUrl(null)
.sessionUrl(uuidConverter.toBase64(UUID.randomUUID()))
.type(postCreate.getType()).build();
.postType(postCreate.getType()).build();
}

public PostDto.PostDetailResponse toPostDto(Post post, List<String> tags) {
Expand Down Expand Up @@ -70,7 +70,7 @@ public PostGetListResponse toPostListResponse(Post post) {
.content(post.getContent())
.created_at(post.getCreatedAt().toLocalDate())
.title(post.getTitle())
.type(post.getType())
.type(post.getPostType())
.tags(TagtoString(post.getTag()))
.commentCount(commentRepository.countByPost_Id(post.getId()))
.build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.rising.backend.domain.post.repository;

import com.rising.backend.domain.post.domain.Post;
import com.rising.backend.domain.post.domain.PostType;
import com.rising.backend.domain.post.domain.Tag;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
Expand All @@ -11,4 +14,6 @@ public interface PostRepository extends JpaRepository<Post, Long> {
List<Post> findByUserId(Long userId);

List<Tag> findTagById(Long id);

Page<Post> findByPostType(PostType postType, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rising.backend.domain.post.service;

import com.rising.backend.domain.post.domain.Post;
import com.rising.backend.domain.post.domain.PostType;
import com.rising.backend.domain.post.domain.Tag;
import com.rising.backend.domain.post.dto.PostDto;
import com.rising.backend.domain.post.mapper.PostMapper;
Expand Down Expand Up @@ -57,6 +58,11 @@ public List<PostGetListResponse> pageList(Pageable pageable) {
return postMapper.toDtoPageList(postList).getContent();
}

public List<PostGetListResponse> getPostsByType(PostType postType, Pageable pageable) {
Page<Post> posts = postRepository.findByPostType(postType, pageable);
return postMapper.toDtoPageList(posts).getContent();
}

public String getSessionUrl(Long postId, User user) {
Post post = findPostById(postId);
if (!checkIsAuthor(post, user)) {
Expand Down

0 comments on commit 98d6c32

Please sign in to comment.