Skip to content

Commit

Permalink
[feat #43] 마이페이지 크레딧 내역 조회 API (#79)
Browse files Browse the repository at this point in the history
* [rename] : CreditHistory, CreditType 패키지 이동

* [test] : CreditHistory, CreditType 패키지 이동

* [feat] : detail로 CreditType 찾는 메서드 추가

* [feat] : 크레딧 내역 목록 응답 DTO 추가

* [feat] : 크레딧 내역 목록 QueryDSL 추가

* [feat] : 크레딧 내역 목록 조회 Controller/Service 로직 추가

* [fix] : 크레딧 내역 조회 응답 DTO 필드 수정

* [feat] : 크레딧 내역 조회 시 '전체' 타입 값 처리 로직 추가

* [test] : 크레딧 내역 조회 Respository 단위테스트 추가

* [test] : 크레딧 내역 조회 Controller 통합테스트 추가

* [test] : merge 병합으로 인한 토큰 저장 위치 수정(header -> cookie)

* [fix] 충돌 해결

* [test] 충돌 해결

* [test] : 크레딧 내역 필터 상황 테스트 실패 해결

* [fix] : type 필드 데이터 매칭 수정

* [test] : type 필드 매칭 데이터 변경으로 인한 수정

* [rename] : 응답 DTO 클래스명/필드명 네이밍 변경

* [test] : 응답 DTO 필드명 네이밍 변경에 따른 테스트 코드 수정

* [test] : queryString -> param() 수정

* [sytle] : 코드 포맷팅
  • Loading branch information
dudxo authored Aug 23, 2024
1 parent 05ec534 commit b4e69c8
Show file tree
Hide file tree
Showing 18 changed files with 503 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dnd.gongmuin.credit_history;
package com.dnd.gongmuin.credit_history.domain;

import static jakarta.persistence.FetchType.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dnd.gongmuin.credit_history;
package com.dnd.gongmuin.credit_history.domain;

import java.util.Arrays;

Expand Down Expand Up @@ -27,4 +27,15 @@ public static CreditType of(String input) {
private boolean isEqual(String input) {
return input.equals(this.label);
}

public static CreditType fromDetail(String detail) {
return Arrays.stream(values())
.filter(type -> type.isDetailEqual(detail))
.findAny()
.orElseThrow(IllegalArgumentException::new);
}

private boolean isDetailEqual(String input) {
return input.equals(this.detail);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dnd.gongmuin.credit_history.dto;

import com.dnd.gongmuin.credit_history.CreditHistory;
import com.dnd.gongmuin.credit_history.CreditType;
import com.dnd.gongmuin.credit_history.domain.CreditHistory;
import com.dnd.gongmuin.credit_history.domain.CreditType;
import com.dnd.gongmuin.member.domain.Member;

import lombok.AccessLevel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.springframework.data.jpa.repository.JpaRepository;

import com.dnd.gongmuin.credit_history.CreditHistory;
import com.dnd.gongmuin.credit_history.domain.CreditHistory;

public interface CreditHistoryRepository extends JpaRepository<CreditHistory, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.transaction.annotation.Transactional;

import com.dnd.gongmuin.answer.domain.Answer;
import com.dnd.gongmuin.credit_history.CreditType;
import com.dnd.gongmuin.credit_history.domain.CreditType;
import com.dnd.gongmuin.credit_history.dto.CreditHistoryMapper;
import com.dnd.gongmuin.credit_history.repository.CreditHistoryRepository;
import com.dnd.gongmuin.question_post.domain.QuestionPost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.dnd.gongmuin.common.dto.PageResponse;
import com.dnd.gongmuin.member.domain.Member;
import com.dnd.gongmuin.member.dto.request.UpdateMemberProfileRequest;
import com.dnd.gongmuin.member.dto.response.AnsweredQuestionPostsByMemberResponse;
import com.dnd.gongmuin.member.dto.response.BookmarksByMemberResponse;
import com.dnd.gongmuin.member.dto.response.AnsweredQuestionPostsResponse;
import com.dnd.gongmuin.member.dto.response.BookmarksResponse;
import com.dnd.gongmuin.member.dto.response.CreditHistoryResponse;
import com.dnd.gongmuin.member.dto.response.MemberProfileResponse;
import com.dnd.gongmuin.member.dto.response.QuestionPostsByMemberResponse;
import com.dnd.gongmuin.member.dto.response.QuestionPostsResponse;
import com.dnd.gongmuin.member.service.MemberService;

import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -54,10 +56,10 @@ public ResponseEntity<MemberProfileResponse> updateMemberProfile(
@Operation(summary = "작성한 질문 전체 조회 API", description = "작성한 질문을 전체 조회한다.")
@ApiResponse(useReturnTypeSchema = true)
@GetMapping("/question-posts")
public ResponseEntity<PageResponse<QuestionPostsByMemberResponse>> getQuestionPostsByMember(
public ResponseEntity<PageResponse<QuestionPostsResponse>> getQuestionPostsByMember(
@AuthenticationPrincipal Member member,
Pageable pageable) {
PageResponse<QuestionPostsByMemberResponse> response =
PageResponse<QuestionPostsResponse> response =
memberService.getQuestionPostsByMember(member, pageable);

return ResponseEntity.ok(response);
Expand All @@ -66,10 +68,10 @@ public ResponseEntity<PageResponse<QuestionPostsByMemberResponse>> getQuestionPo
@Operation(summary = "댓글 단 질문 전체 조회 API", description = "댓글 단 질문을 전체 조회한다.")
@ApiResponse(useReturnTypeSchema = true)
@GetMapping("/question-posts/answers")
public ResponseEntity<PageResponse<AnsweredQuestionPostsByMemberResponse>> getAnsweredQuestionPostsByMember(
public ResponseEntity<PageResponse<AnsweredQuestionPostsResponse>> getAnsweredQuestionPostsByMember(
@AuthenticationPrincipal Member member,
Pageable pageable) {
PageResponse<AnsweredQuestionPostsByMemberResponse> response =
PageResponse<AnsweredQuestionPostsResponse> response =
memberService.getAnsweredQuestionPostsByMember(member, pageable);

return ResponseEntity.ok(response);
Expand All @@ -78,13 +80,26 @@ public ResponseEntity<PageResponse<AnsweredQuestionPostsByMemberResponse>> getAn
@Operation(summary = "스크랩 질문 전체 조회 API", description = "스크랩한 질문을 전체 조회한다.")
@ApiResponse(useReturnTypeSchema = true)
@GetMapping("/question-posts/bookmarks")
public ResponseEntity<PageResponse<BookmarksByMemberResponse>> getBookmarksByMember(
public ResponseEntity<PageResponse<BookmarksResponse>> getBookmarksByMember(
@AuthenticationPrincipal Member member,
Pageable pageable) {
PageResponse<BookmarksByMemberResponse> response =
PageResponse<BookmarksResponse> response =
memberService.getBookmarksByMember(member, pageable);

return ResponseEntity.ok(response);
}

@Operation(summary = "크레딧 목록 전체 조회 API", description = "타입에 맞는 크레딧 목록을 전체 조회한다.")
@ApiResponse(useReturnTypeSchema = true)
@GetMapping("/credit/histories")
public ResponseEntity<PageResponse<CreditHistoryResponse>> getCreditHistoryByMember(
@RequestParam("type") String type,
@AuthenticationPrincipal Member member,
Pageable pageable) {
PageResponse<CreditHistoryResponse> response =
memberService.getCreditHistoryByMember(type, member, pageable);

return ResponseEntity.ok(response);
}

}
4 changes: 2 additions & 2 deletions src/main/java/com/dnd/gongmuin/member/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
@NoArgsConstructor(access = PROTECTED)
public class Member extends TimeBaseEntity {

@Column(name = "profile_image_no", nullable = false)
private final int profileImageNo = setRandomNumber();
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "member_id")
Expand All @@ -48,6 +46,8 @@ public class Member extends TimeBaseEntity {
private int credit;
@Column(name = "role", nullable = false)
private String role;
@Column(name = "profile_image_no", nullable = false)
private final int profileImageNo = setRandomNumber();

@Builder(access = PRIVATE)
private Member(String nickname, String socialName, JobGroup jobGroup, JobCategory jobCategory, String socialEmail,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
import com.dnd.gongmuin.question_post.domain.QuestionPost;
import com.querydsl.core.annotations.QueryProjection;

public record AnsweredQuestionPostsByMemberResponse(
public record AnsweredQuestionPostsResponse(
Long questionPostId,
String title,
String content,
String questionTitle,
String questionContent,
String jobGroup,
int reward,
String questionPostCreatedAt,
boolean isChosen,
int savedTotalCount,
int recommendTotalCount,
int bookmarkCount,
int recommendCount,
Long answerId,
String answerContent,
String answerCreatedAt
) {

@QueryProjection
public AnsweredQuestionPostsByMemberResponse(
public AnsweredQuestionPostsResponse(
QuestionPost questionPost,
int savedTotalCount,
int recommendTotalCount,
int bookmarkCount,
int recommendCount,
Answer answer) {
this(
questionPost.getId(),
Expand All @@ -33,8 +33,8 @@ public AnsweredQuestionPostsByMemberResponse(
questionPost.getReward(),
questionPost.getCreatedAt().toString(),
questionPost.getIsChosen(),
savedTotalCount,
recommendTotalCount,
bookmarkCount,
recommendCount,
answer.getId(),
answer.getContent(),
answer.getCreatedAt().toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
import com.dnd.gongmuin.question_post.domain.QuestionPost;
import com.querydsl.core.annotations.QueryProjection;

public record BookmarksByMemberResponse(
public record BookmarksResponse(
Long questionPostId,
String title,
String content,
String questionTitle,
String questionContent,
String jobGroup,
int reward,
String createdAt,
boolean isChosen,
int savedTotalCount,
int recommendTotalCount
int bookmarkCount,
int recommendCount
) {
@QueryProjection
public BookmarksByMemberResponse(
public BookmarksResponse(
QuestionPost questionPost,
int savedTotalCount,
int recommendTotalCount
int bookmarkCount,
int recommendCount
) {
this(
questionPost.getId(),
Expand All @@ -28,8 +28,8 @@ public BookmarksByMemberResponse(
questionPost.getReward(),
questionPost.getCreatedAt().toString(),
questionPost.getIsChosen(),
savedTotalCount,
recommendTotalCount
bookmarkCount,
recommendCount
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.dnd.gongmuin.member.dto.response;

import com.dnd.gongmuin.credit_history.domain.CreditHistory;
import com.querydsl.core.annotations.QueryProjection;

public record CreditHistoryResponse(
Long id,
String type,
String detail,
int amount
) {
@QueryProjection
public CreditHistoryResponse(CreditHistory creditHistory) {
this(
creditHistory.getId(),
creditHistory.getType().getLabel(),
creditHistory.getDetail(),
creditHistory.getAmount()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
import com.dnd.gongmuin.question_post.domain.QuestionPost;
import com.querydsl.core.annotations.QueryProjection;

public record QuestionPostsByMemberResponse(
public record QuestionPostsResponse(
Long questionPostId,
String title,
String content,
String questionTitle,
String questionContent,
String jobGroup,
int reward,
String createdAt,
boolean isChosen,
int savedTotalCount,
int recommendTotalCount
int bookmarkCount,
int recommendCount
) {

@QueryProjection
public QuestionPostsByMemberResponse(
public QuestionPostsResponse(
QuestionPost questionPost,
int savedTotalCount,
int recommendTotalCount
int bookmarkCount,
int recommendCount
) {
this(
questionPost.getId(),
Expand All @@ -29,8 +29,8 @@ public QuestionPostsByMemberResponse(
questionPost.getReward(),
questionPost.getCreatedAt().toString(),
questionPost.getIsChosen(),
savedTotalCount,
recommendTotalCount
bookmarkCount,
recommendCount
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
import org.springframework.data.domain.Slice;

import com.dnd.gongmuin.member.domain.Member;
import com.dnd.gongmuin.member.dto.response.AnsweredQuestionPostsByMemberResponse;
import com.dnd.gongmuin.member.dto.response.BookmarksByMemberResponse;
import com.dnd.gongmuin.member.dto.response.QuestionPostsByMemberResponse;
import com.dnd.gongmuin.member.dto.response.AnsweredQuestionPostsResponse;
import com.dnd.gongmuin.member.dto.response.BookmarksResponse;
import com.dnd.gongmuin.member.dto.response.CreditHistoryResponse;
import com.dnd.gongmuin.member.dto.response.QuestionPostsResponse;

public interface MemberCustom {
Slice<QuestionPostsByMemberResponse> getQuestionPostsByMember(Member member, Pageable pageable);
Slice<QuestionPostsResponse> getQuestionPostsByMember(Member member, Pageable pageable);

Slice<AnsweredQuestionPostsByMemberResponse> getAnsweredQuestionPostsByMember(Member member, Pageable pageable);
Slice<AnsweredQuestionPostsResponse> getAnsweredQuestionPostsByMember(Member member, Pageable pageable);

Slice<BookmarksByMemberResponse> getBookmarksByMember(Member member, Pageable pageable);
Slice<BookmarksResponse> getBookmarksByMember(Member member, Pageable pageable);

Slice<CreditHistoryResponse> getCreditHistoryByMember(String type, Member member, Pageable pageable);
}
Loading

0 comments on commit b4e69c8

Please sign in to comment.