Skip to content

Commit

Permalink
#4 fix: git conflict 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
Haeun-Y committed Sep 15, 2023
1 parent 6ffe9aa commit 5e10f96
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.ewhatever.qna.answer.entity.Answer;
import com.ewhatever.qna.post.entity.Post;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -10,4 +12,7 @@
@Repository
public interface AnswerRepository extends JpaRepository<Answer, Long> {
List<Answer> findAllByPost(Post post);
Long countByAnswerer_UserIdxAndStatusEquals(Long userIdx, String status);
Page<Answer> findByAnswerer_UserIdxAndPost_IsJuicyAndStatusEquals(Long userIdx, Boolean isJuicy, String status, Pageable pageable);
Long countByPost_PostIdxAndStatusEquals(Long postIdx, String status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum BaseResponseStatus {
INVALID_CATEGORY(false, 2300, "잘못된 카테고리입니다."),

// user(2400-2499)
INVALID_USER(false, 2400, "존재하지 않는 사용자에 대한 요청입니다."),


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface PostRepository extends JpaRepository<Post, Long> {
Page<Post> findAllByIsJuicy(Pageable pageable, Boolean isJuicy);
Boolean existsByCategory(Category category);
Page<Post> findByCategory(Category category, Pageable pageable);
Long countByQuestioner_UserIdxAndStatusEquals(Long userIdx, String status);
Page<Post> findByQuestioner_UserIdxAndIsJuicyAndStatusEquals(Long userIdx, Boolean isJuicy, String status, Pageable pageable);
}
34 changes: 34 additions & 0 deletions src/main/java/com/ewhatever/qna/scrap/entity/Scrap.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.ewhatever.qna.scrap.entity;

import com.ewhatever.qna.common.Base.BaseEntity;
import com.ewhatever.qna.post.entity.Post;
import com.ewhatever.qna.user.entity.User;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Scrap extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long scrapIdx;

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "post_idx")
private Post post;

@NotNull
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_idx")
private User user;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ewhatever.qna.scrap.repository;

import com.ewhatever.qna.scrap.entity.Scrap;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ScrapRepository extends JpaRepository<Scrap, Long> {
Long countByUser_UserIdxAndStatusEquals(Long userIdx, String status);
Page<Scrap> findByUser_UserIdxAndStatusEquals(Long userIdx, String status, Pageable pageable);
}
12 changes: 6 additions & 6 deletions src/main/java/com/ewhatever/qna/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.ArrayList;
import java.util.List;

import static com.ewhatever.qna.common.Base.BaseResponseStatus.COMMON_NOT_FOUND;
import static com.ewhatever.qna.common.Base.BaseResponseStatus.INVALID_USER;

@Service
@RequiredArgsConstructor
Expand All @@ -33,15 +33,15 @@ public class UserService {

// TODO : 이거 BaseResponse 말고 객체 반환하도록 수정
public BaseResponse<?> getProfile() throws BaseException {
User user = userRepository.findById(getUserIdx()).orElseThrow(()-> new BaseException(COMMON_NOT_FOUND));
User user = userRepository.findById(getUserIdx()).orElseThrow(()-> new BaseException(INVALID_USER));
if(user.getRole().equals("SINY")) return getSinyProfile(user);
else return getJunyProfile(user);
}

// TODO : code duplication 해결
// TODO : getPageable 메소드 호출
public Page<GetSinyAnswerResponse> getMyAnswers(String status, int requestPageNum) throws BaseException {
User user = userRepository.findById(getUserIdx()).orElseThrow(()-> new BaseException(COMMON_NOT_FOUND));
User user = userRepository.findById(getUserIdx()).orElseThrow(()-> new BaseException(INVALID_USER));
List<Sort.Order> sorts = new ArrayList<>();
Boolean isJuicy;
if(status.equals("completed")) {//쥬시 완료
Expand All @@ -58,7 +58,7 @@ public Page<GetSinyAnswerResponse> getMyAnswers(String status, int requestPageNu
}

public Page<GetJunyQuestionResponse> getMyQuestions(String status, int requestPageNum) throws BaseException {
User user = userRepository.findById(getUserIdx()).orElseThrow(()-> new BaseException(COMMON_NOT_FOUND));
User user = userRepository.findById(getUserIdx()).orElseThrow(()-> new BaseException(INVALID_USER));
List<Sort.Order> sorts = new ArrayList<>();
Boolean isJuicy;
if(status.equals("completed")) {//쥬시 완료
Expand All @@ -75,13 +75,13 @@ public Page<GetJunyQuestionResponse> getMyQuestions(String status, int requestPa
}

public Page<GetCommentResponse> getMyComments(int requestPageNum) throws BaseException {
User user = userRepository.findById(getUserIdx()).orElseThrow(()-> new BaseException(COMMON_NOT_FOUND));
User user = userRepository.findById(getUserIdx()).orElseThrow(()-> new BaseException(INVALID_USER));
Pageable pageable = getPageable(requestPageNum, 10, "created_date");
return commentRepository.findByWriter_UserIdxAndStatusEquals(user.getUserIdx(), "active", pageable).map(GetCommentResponse::fromComment);
}

public Page<GetScrapResponse> getMyScraps(int requestPageNum) throws BaseException {
User user = userRepository.findById(getUserIdx()).orElseThrow(()-> new BaseException(COMMON_NOT_FOUND));
User user = userRepository.findById(getUserIdx()).orElseThrow(()-> new BaseException(INVALID_USER));
Pageable pageable = getPageable(requestPageNum, 10, "created_date");
return scrapRepository.findByUser_UserIdxAndStatusEquals(user.getUserIdx(), "active", pageable).map(GetScrapResponse::fromScrap);

Expand Down

0 comments on commit 5e10f96

Please sign in to comment.