Skip to content

Commit

Permalink
Merge pull request #53 from KNU-HAEDAL/refactor/package
Browse files Browse the repository at this point in the history
Refactor/package
  • Loading branch information
momnpa333 authored Aug 12, 2024
2 parents ac5e9c8 + 6bb35b1 commit cdf104b
Show file tree
Hide file tree
Showing 63 changed files with 646 additions and 586 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.haedal.zzansuni.controller.auth.AuthReq;
import org.haedal.zzansuni.core.api.ApiResponse;
import org.haedal.zzansuni.domain.auth.AuthService;
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroupService;
import org.haedal.zzansuni.domain.challengegroup.application.ChallengeGroupService;
import org.springframework.http.HttpStatus;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.haedal.zzansuni.controller.challengegroup.challenge;
package org.haedal.zzansuni.controller.challenge;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -7,14 +7,13 @@
import lombok.extern.slf4j.Slf4j;
import org.haedal.zzansuni.controller.PagingRequest;
import org.haedal.zzansuni.controller.PagingResponse;
import org.haedal.zzansuni.controller.challengegroup.challenge.ChallengeRes.ChallengeCompleteResponse;
import org.haedal.zzansuni.controller.challenge.ChallengeRes.ChallengeCompleteResponse;
import org.haedal.zzansuni.core.api.ApiResponse;
import org.haedal.zzansuni.domain.ImageUploader;
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand;
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel.ChallengeComplete;
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel.ChallengeCurrent;
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeService;
import org.haedal.zzansuni.domain.userchallenge.UserChallengeService;
import org.haedal.zzansuni.domain.challengegroup.ChallengeCommand;
import org.haedal.zzansuni.domain.userchallenge.application.ChallengeRecordService;
import org.haedal.zzansuni.domain.userchallenge.application.UserChallengeModel;
import org.haedal.zzansuni.domain.userchallenge.application.UserChallengeService;
import org.haedal.zzansuni.global.jwt.JwtUser;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
Expand All @@ -28,7 +27,7 @@
@Slf4j
public class ChallengeController {

private final ChallengeService challengeService;
private final ChallengeRecordService challengeRecordService;
private final UserChallengeService userChallengeService;
private final ImageUploader imageUploader;

Expand Down Expand Up @@ -70,7 +69,7 @@ public ApiResponse<ChallengeRes.ChallengeRecordResponse> getChallengeRecord(
@AuthenticationPrincipal JwtUser jwtUser
) {
ChallengeRes.ChallengeRecordResponse response = ChallengeRes.ChallengeRecordResponse.from(
challengeService.getChallengeRecord(jwtUser.getId(), challengeId)
challengeRecordService.getChallengeRecord(jwtUser.getId(), challengeId)
);
return ApiResponse.success(response, "챌린지 기록 조회에 성공하였습니다.");
}
Expand All @@ -83,7 +82,7 @@ public ApiResponse<ChallengeRes.ChallengeRecordDetailDto> getChallengeRecordDeta
@AuthenticationPrincipal JwtUser jwtUser
) {
ChallengeRes.ChallengeRecordDetailDto response = ChallengeRes.ChallengeRecordDetailDto.from(
challengeService.getChallengeRecordDetail(recordId)
challengeRecordService.getChallengeRecordDetail(recordId)
);
log.info("response: {}", response);
return ApiResponse.success(response, "챌린지 기록 상세 조회에 성공하였습니다.");
Expand All @@ -95,7 +94,7 @@ public ApiResponse<PagingResponse<ChallengeRes.ChallengeCurrentResponse>> getCha
@Valid PagingRequest pagingRequest,
@AuthenticationPrincipal JwtUser jwtUser
) {
Page<ChallengeCurrent> page = userChallengeService.getCurrentChallenges(
Page<UserChallengeModel.Current> page = userChallengeService.getCurrentChallenges(
jwtUser.getId(), pagingRequest.toPageable());

PagingResponse<ChallengeRes.ChallengeCurrentResponse> response = PagingResponse.from(
Expand All @@ -110,7 +109,7 @@ public ApiResponse<PagingResponse<ChallengeCompleteResponse>> getChallengeComple
@Valid PagingRequest pagingRequest,
@AuthenticationPrincipal JwtUser jwtUser
) {
Page<ChallengeComplete> page = userChallengeService.getCompleteChallenges(
Page<UserChallengeModel.Complete> page = userChallengeService.getCompleteChallenges(
jwtUser.getId(), pagingRequest.toPageable());

PagingResponse<ChallengeCompleteResponse> response = PagingResponse.from(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.haedal.zzansuni.controller.challengegroup.challenge;
package org.haedal.zzansuni.controller.challenge;

import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeCommand;
import org.haedal.zzansuni.domain.challengegroup.ChallengeCommand;
import org.springframework.web.multipart.MultipartFile;

public class ChallengeReq {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package org.haedal.zzansuni.controller.challengegroup.challenge;
package org.haedal.zzansuni.controller.challenge;

import lombok.Builder;
import org.haedal.zzansuni.domain.challengegroup.ChallengeCategory;
import org.haedal.zzansuni.domain.challengegroup.application.ChallengeModel;
import org.haedal.zzansuni.domain.userchallenge.application.ChallengeVerificationModel;
import org.haedal.zzansuni.domain.userchallenge.application.UserChallengeModel;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel;
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel.ChallengeComplete;
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel.ChallengeCurrent;
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel.ChallengeRecord;
import org.haedal.zzansuni.domain.userchallenge.verification.ChallengeVerificationModel;

public class ChallengeRes {

Expand Down Expand Up @@ -41,7 +39,7 @@ public record ChallengeRecordResponse(
List<Long> recordIds
) {

public static ChallengeRecordResponse from(ChallengeRecord dto) {
public static ChallengeRecordResponse from(UserChallengeModel.Record dto) {
return ChallengeRecordResponse.builder()
.title(dto.title())
.totalCount(dto.totalCount())
Expand Down Expand Up @@ -90,17 +88,17 @@ public record ChallengeCurrentResponse(

) {

public static ChallengeCurrentResponse from(ChallengeCurrent challengeCurrent) {
public static ChallengeCurrentResponse from(UserChallengeModel.Current current) {
return ChallengeCurrentResponse.builder()
.challengeId(challengeCurrent.challengeId())
.title(challengeCurrent.title())
.successCount(challengeCurrent.successCount())
.totalCount(challengeCurrent.totalCount())
.participationDate(challengeCurrent.participationDate())
.startDate(challengeCurrent.startDate())
.endDate(challengeCurrent.endDate())
.category(challengeCurrent.category())
.reviewWritten(challengeCurrent.reviewWritten())
.challengeId(current.challengeId())
.title(current.title())
.successCount(current.successCount())
.totalCount(current.totalCount())
.participationDate(current.participationDate())
.startDate(current.startDate())
.endDate(current.endDate())
.category(current.category())
.reviewWritten(current.reviewWritten())
.build();
}
}
Expand All @@ -114,13 +112,13 @@ public record ChallengeCompleteResponse(
Boolean reviewWritten
) {

public static ChallengeCompleteResponse from(ChallengeComplete challengeComplete) {
public static ChallengeCompleteResponse from(UserChallengeModel.Complete complete) {
return ChallengeCompleteResponse.builder()
.id(challengeComplete.challengeId())
.title(challengeComplete.title())
.successDate(challengeComplete.successDate())
.category(challengeComplete.category())
.reviewWritten(challengeComplete.reviewWritten())
.id(complete.challengeId())
.title(complete.title())
.successDate(complete.successDate())
.category(complete.category())
.reviewWritten(complete.reviewWritten())
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import org.haedal.zzansuni.controller.PagingResponse;
import org.haedal.zzansuni.core.api.ApiResponse;
import org.haedal.zzansuni.domain.challengegroup.ChallengeCategory;
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroupModel;
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroupQueryService;
import org.haedal.zzansuni.domain.challengegroup.application.ChallengeGroupModel;
import org.haedal.zzansuni.domain.challengegroup.application.ChallengeGroupQueryService;
import org.haedal.zzansuni.domain.userchallenge.application.ChallengeRankingService;
import org.haedal.zzansuni.global.jwt.JwtUser;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -22,6 +23,7 @@
@RestController
public class ChallengeGroupController {
private final ChallengeGroupQueryService challengeGroupQueryService;
private final ChallengeRankingService challengeRankingService;

@Operation(summary = "챌린지 그룹 목록 페이징", description = "챌린지 그룹 페이징 조회.")
@GetMapping("/api/challengeGroups")
Expand Down Expand Up @@ -53,8 +55,8 @@ public ApiResponse<ChallengeGroupRes.RankingPagingResponse> getChallengeRankings
@PathVariable Long challengeGroupId,
@Valid PagingRequest pagingRequest
) {
var rankingPage = challengeGroupQueryService.getChallengeGroupRankingsPaging(challengeGroupId, pagingRequest.toPageable());
var rankingModel = challengeGroupQueryService.getChallengeGroupRanking(challengeGroupId, jwtUser.getId());
var rankingPage = challengeRankingService.getChallengeGroupRankingsPaging(challengeGroupId, pagingRequest.toPageable());
var rankingModel = challengeRankingService.getChallengeGroupRanking(challengeGroupId, jwtUser.getId());
var response = ChallengeGroupRes.RankingPagingResponse
.from(rankingPage, rankingModel);
return ApiResponse.success(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import lombok.Builder;
import org.haedal.zzansuni.controller.user.UserRes;
import org.haedal.zzansuni.domain.challengegroup.ChallengeCategory;
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroupModel;
import org.haedal.zzansuni.domain.challengegroup.application.ChallengeGroupModel;
import org.haedal.zzansuni.domain.challengegroup.DayType;
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel;
import org.haedal.zzansuni.domain.challengegroup.application.ChallengeModel;
import org.haedal.zzansuni.domain.userchallenge.application.ChallengeGroupRankingModel;
import org.springframework.data.domain.Page;

import java.time.LocalDate;
Expand Down Expand Up @@ -137,8 +138,8 @@ public record RankingPagingResponse(
ChallengeGroupRes.Ranking myRanking //null이면 랭킹이 없는 것
) {
public static RankingPagingResponse from(
Page<ChallengeGroupModel.Ranking> rankingPage,
ChallengeGroupModel.Ranking myRanking
Page<ChallengeGroupRankingModel.Main> rankingPage,
ChallengeGroupRankingModel.Main myRanking
){
var data = rankingPage.getContent().stream()
.map(ChallengeGroupRes.Ranking::from)
Expand All @@ -161,7 +162,7 @@ public record Ranking(
UserRes.User user
) {
public static Ranking from(
ChallengeGroupModel.Ranking model
ChallengeGroupRankingModel.Main model
){
var user = UserRes.User.from(model.user());
return Ranking.builder()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.haedal.zzansuni.controller.challengegroup.review;
package org.haedal.zzansuni.controller.challengereview;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.haedal.zzansuni.controller.PagingRequest;
import org.haedal.zzansuni.controller.PagingResponse;
import org.haedal.zzansuni.controller.challengegroup.challenge.ChallengeReq;
import org.haedal.zzansuni.controller.challenge.ChallengeReq;
import org.haedal.zzansuni.core.api.ApiResponse;
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeService;
import org.haedal.zzansuni.domain.userchallenge.review.ChallengeReviewModel.ChallengeReviewWithChallenge;
import org.haedal.zzansuni.domain.userchallenge.review.ChallengeReviewModel.ChallengeReviewWithUserInfo;
import org.haedal.zzansuni.domain.userchallenge.application.ChallengeReviewModel.ChallengeReviewWithChallenge;
import org.haedal.zzansuni.domain.userchallenge.application.ChallengeReviewModel.ChallengeReviewWithUserInfo;
import org.haedal.zzansuni.domain.userchallenge.application.ChallengeReviewService;
import org.haedal.zzansuni.global.jwt.JwtUser;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
Expand All @@ -22,7 +22,7 @@
@RequiredArgsConstructor
public class ChallengeReviewController {

private final ChallengeService challengeService;
private final ChallengeReviewService challengeReviewService;


@Operation(summary = "챌린지 그룹 최근 리뷰 페이징", description = "챌린지 최근 리뷰 페이징 조회.")
Expand All @@ -31,7 +31,7 @@ public ApiResponse<PagingResponse<ChallengeReviewRes.Info>> getChallengeReviews(
@Valid PagingRequest pagingRequest
//TODO SORTING
) {
Page<ChallengeReviewWithUserInfo> page = challengeService.getChallengeReviews(
Page<ChallengeReviewWithUserInfo> page = challengeReviewService.getChallengeReviews(
pagingRequest.toPageable());

PagingResponse<ChallengeReviewRes.Info> response = PagingResponse.from(
Expand All @@ -50,7 +50,7 @@ public ApiResponse<PagingResponse<ChallengeReviewRes.InfoWithChallenge>> getChal
@Valid PagingRequest pagingRequest
//TODO SORTING
) {
Page<ChallengeReviewWithChallenge> page = challengeService.getChallengeReviewsByGroupId(
Page<ChallengeReviewWithChallenge> page = challengeReviewService.getChallengeReviewsByGroupId(
challengeGroupId, pagingRequest.toPageable());

PagingResponse<ChallengeReviewRes.InfoWithChallenge> response = PagingResponse.from(
Expand All @@ -69,7 +69,7 @@ public ApiResponse<Long> challengeReviewCreate(
@AuthenticationPrincipal JwtUser jwtUser,
@RequestBody ChallengeReq.ReviewCreate request
) {
Long response = challengeService.createReview(request.toCommand(), challengeId,
Long response = challengeReviewService.createReview(request.toCommand(), challengeId,
jwtUser.getId());
return ApiResponse.success(response, "챌린지 리뷰 작성에 성공하였습니다.");
}
Expand All @@ -81,7 +81,7 @@ public ApiResponse<ChallengeReviewRes.ScoreResponse> getChallengeGroupReviewScor
@PathVariable Long challengeGroupId
) {
var response = ChallengeReviewRes.ScoreResponse.from(
challengeService.getChallengeGroupReviewScore(challengeGroupId));
challengeReviewService.getChallengeGroupReviewScore(challengeGroupId));
return ApiResponse.success(response, "챌린지 그룹별 리뷰 평점 조회에 성공하였습니다.");
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.haedal.zzansuni.controller.challengegroup.review;
package org.haedal.zzansuni.controller.challengereview;

import java.util.Map;
import lombok.Builder;
import org.haedal.zzansuni.controller.user.UserRes;
import org.haedal.zzansuni.domain.userchallenge.review.ChallengeReviewModel;
import org.haedal.zzansuni.domain.userchallenge.review.ChallengeReviewModel.ChallengeReviewWithChallenge;
import org.haedal.zzansuni.domain.userchallenge.review.ChallengeReviewModel.ChallengeReviewWithUserInfo;
import org.haedal.zzansuni.domain.userchallenge.application.ChallengeReviewModel;
import org.haedal.zzansuni.domain.userchallenge.application.ChallengeReviewModel.ChallengeReviewWithChallenge;
import org.haedal.zzansuni.domain.userchallenge.application.ChallengeReviewModel.ChallengeReviewWithUserInfo;

public class ChallengeReviewRes {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.haedal.zzansuni.domain.challengegroup.challenge;
package org.haedal.zzansuni.domain.challengegroup;

import jakarta.persistence.*;

Expand All @@ -9,9 +9,6 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.haedal.zzansuni.domain.BaseTimeEntity;
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroup;
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroupCommand;
import org.haedal.zzansuni.domain.challengegroup.DayType;

@Entity
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.haedal.zzansuni.domain.challengegroup.challenge;
package org.haedal.zzansuni.domain.challengegroup;

import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.haedal.zzansuni.domain.BaseTimeEntity;
import org.haedal.zzansuni.domain.challengegroup.challenge.Challenge;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package org.haedal.zzansuni.domain.challengegroup;
package org.haedal.zzansuni.domain.challengegroup.application;

import lombok.Builder;
import org.haedal.zzansuni.domain.challengegroup.ChallengeCategory;
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroup;
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroupImage;
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel;
import org.haedal.zzansuni.domain.userchallenge.userexp.ChallengeGroupUserExp;
import org.haedal.zzansuni.domain.user.UserModel;

import java.time.LocalDate;
import java.util.List;
Expand Down Expand Up @@ -116,19 +113,6 @@ public static Detail from(ChallengeGroup challengeGroup, List<ChallengeGroupImag
}
}

@Builder
public record Ranking(
UserModel.Main user,
Integer rank,
Integer accumulatedPoint
) {
public static Ranking from(ChallengeGroupUserExp challengeGroupUserExp, int rank) {
return Ranking.builder()
.user(UserModel.Main.from(challengeGroupUserExp.getUser()))
.rank(rank)
.accumulatedPoint(challengeGroupUserExp.getTotalExp())
.build();
}
}


}
Loading

0 comments on commit cdf104b

Please sign in to comment.