Skip to content
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

[feature/10] 인기 피드 전체 조회 #57

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main/java/com/umc/TheGoods/domain/community/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ public class Comment extends BaseDateTimeEntity {
@Column(columnDefinition = "TEXT", nullable = false)
private String content;


@OneToMany(mappedBy = "comment", cascade = CascadeType.ALL)
private List<CommentLike> commentLikeList = new ArrayList<>();

@OneToMany(mappedBy = "comment", cascade = CascadeType.ALL)
private List<CommentMention> commentMentionList = new ArrayList<>();

// 엔티티 핵심 메서드
public void setContent(String newContent) {
this.content = newContent;
}

public void removeCommentLike(Long id) {
this.commentLikeList.removeIf((like) -> like.getId() == id);
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/umc/TheGoods/domain/community/Inquiry.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public class Inquiry extends BaseDateTimeEntity {
@JoinColumn(name = "item_id")
private Item item;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "seller_id")
private Member seller;

@OneToMany(mappedBy = "inquiry", cascade = CascadeType.ALL)
private List<InquiryReply> inquiryReplyList = new ArrayList<>();

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/umc/TheGoods/domain/member/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ public class Member extends BaseDateTimeEntity {
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
private List<Inquiry> inquiryList = new ArrayList<>();

@OneToMany(mappedBy = "seller", cascade = CascadeType.ALL)
private List<Inquiry> incommingInquiryList = new ArrayList<>();

// Payment 양방향 매핑
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL)
private List<Payment> paymentList = new ArrayList<>();
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/umc/TheGoods/repository/PostRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.umc.TheGoods.repository;

import com.umc.TheGoods.domain.community.Post;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PostRepository extends JpaRepository<Post, Long> {
Page<Post> getPostsOrderByLikes(Pageable pageable);
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.umc.TheGoods.service.PostService;

public interface PostCommandService {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.umc.TheGoods.service.PostService;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
@RequiredArgsConstructor
@Transactional
public class PostCommandServiceImpl implements PostCommandService {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.umc.TheGoods.service.PostService;

import com.umc.TheGoods.web.dto.post.PostResponseDto;

import java.util.List;

public interface PostQueryService {
List<PostResponseDto.PostViewDto> getPostsOrderByLike();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.umc.TheGoods.service.PostService;

import com.umc.TheGoods.repository.PostRepository;
import com.umc.TheGoods.web.dto.post.PostResponseDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class PostQueryServiceImpl implements PostQueryService {

final PostRepository postRepository;

@Override
public List<PostResponseDto.PostViewDto> getPostsOrderByLike() {
return null;
}
}
52 changes: 52 additions & 0 deletions src/main/java/com/umc/TheGoods/web/controller/PostController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.umc.TheGoods.web.controller;

import com.umc.TheGoods.apiPayload.ApiResponse;
import com.umc.TheGoods.service.PostService.PostQueryService;
import com.umc.TheGoods.web.dto.post.PostResponseDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/posts")
public class PostController {

final PostQueryService queryService;

@GetMapping("/")
@Operation(summary = "인기 사장님 피드 전체 조회 API", description = "포스트의 기본 디폴트 정렬로, 좋아요 순으로 내림차순 정렬합니다. \n\n")
@ApiResponses(value = {
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"),
})
public ApiResponse<PostResponseDto.PostListViewDto> posts(@RequestParam("like") boolean like) {
return ApiResponse.onSuccess((PostResponseDto.PostListViewDto) queryService.getPostsOrderByLike());
}

@GetMapping("/follow")
public ApiResponse<PostResponseDto.PostListViewDto> following(@RequestParam("like") boolean like) {
return null;
}

@GetMapping("/{postId}")
public ApiResponse<PostResponseDto.PostViewDto> post(@PathVariable Long postId) {
return null;
}

@PostMapping("/{postId}")
public ApiResponse<PostResponseDto.PostStatusDto> registerPost(@PathVariable Long postId) {
return null;
}

@PatchMapping("/{postId}")
public ApiResponse<PostResponseDto.PostStatusDto> updatePost(@PathVariable Long postId) {
return null;
}

@DeleteMapping("/{postId}")
public ApiResponse<PostResponseDto.PostStatusDto> deletePost(@PathVariable Long postId) {
return null;
}

}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.umc.TheGoods.web.dto.post;

public class PostRequestDto {
}
47 changes: 47 additions & 0 deletions src/main/java/com/umc/TheGoods/web/dto/post/PostResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.umc.TheGoods.web.dto.post;

import com.umc.TheGoods.domain.images.PostImg;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

public class PostResponseDto {

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class PostViewDto {
Long id;
String title;
String content;
LocalDateTime createdDate;
LocalDateTime updatedDate;
Integer likes;
List<PostImg> images;
Long writerId;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class PostListViewDto {
Integer offset;
Integer size;
List<PostViewDto> posts;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class PostStatusDto {
Long postId;
String status;
}
}
Loading