Skip to content

Commit

Permalink
Merge pull request #38 from KNU-HAEDAL/refactor/naming
Browse files Browse the repository at this point in the history
Refactor/naming
  • Loading branch information
bayy1216 authored Jul 4, 2024
2 parents 848c997 + ce23c8f commit 17b1639
Show file tree
Hide file tree
Showing 20 changed files with 189 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.haedal.zzansuni.domain.auth.AuthService;
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroupService;
import org.springframework.http.HttpStatus;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;

@Tag(name = "admin", description = "관리자 API")
Expand All @@ -17,12 +18,14 @@
public class AdminController {
private final AuthService authService;
private final ChallengeGroupService challengeGroupService;
private final BCryptPasswordEncoder passwordEncoder;

@ResponseStatus(HttpStatus.CREATED)
@Operation(summary= "매니저 등록", description = "매니저를 등록한다.")
@PostMapping("/api/admin/auth/manager")
public ApiResponse<Void> createManager(@RequestBody @Valid AuthReq.EmailSignupRequest request) {
authService.createManager(request.toCommand());
authService.createManager(request.toCommand()
.changePassword(passwordEncoder.encode(request.password())));
return ApiResponse.success(null, "매니저 등록 성공");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.haedal.zzansuni.domain.user.UserModel;
import org.haedal.zzansuni.global.jwt.JwtToken;
import org.springframework.data.util.Pair;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
Expand All @@ -19,6 +20,7 @@
@RestController
public class AuthController {
private final AuthService authService;
private final BCryptPasswordEncoder passwordEncoder;

@Operation(summary = "oauth2 로그인", description = "oauth2 code를 이용하여 로그인한다.")
@PostMapping("/api/auth/oauth2")
Expand All @@ -31,7 +33,10 @@ public ApiResponse<AuthRes.LoginResponse> oauth2(@RequestBody @Valid AuthReq.OAu
@Operation(summary = "이메일 회원가입", description = "이메일 회원가입을 한다.")
@PostMapping("/api/auth/signup")
public ApiResponse<AuthRes.LoginResponse> signup(@RequestBody @Valid AuthReq.EmailSignupRequest request) {
Pair<JwtToken, UserModel> pair = authService.signup(request.toCommand());
Pair<JwtToken, UserModel> pair = authService.signup(
request.toCommand()
.changePassword(passwordEncoder.encode(request.password()))
);
var response = AuthRes.LoginResponse.from(pair.getFirst(), pair.getSecond());
return ApiResponse.success(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public class AuthRes {
public record LoginResponse(
String accessToken,
String refreshToken,
UserRes.UserInfoDto userInfo
UserRes.UserInfo userInfo
) {
public static LoginResponse from(JwtToken jwtToken, UserModel userModel) {
var userInfo = UserRes.UserInfoDto.from(userModel);
var userInfo = UserRes.UserInfo.from(userModel);
return LoginResponse.builder()
.accessToken(jwtToken.getAccessToken())
.refreshToken(jwtToken.getRefreshToken())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,50 +25,50 @@ public class ChallengeGroupController {

@Operation(summary = "챌린지 그룹 목록 페이징", description = "챌린지 그룹 페이징 조회.")
@GetMapping("/api/challengeGroups")
public ApiResponse<PagingResponse<ChallengeGroupRes.ChallengeGroupDto>> getChallengesPaging(
public ApiResponse<PagingResponse<ChallengeGroupRes.Info>> getChallengesPaging(
@Valid PagingRequest pagingRequest,
@RequestParam ChallengeCategory category
) {
var page = challengeGroupQueryService.getChallengeGroupsPaging(pagingRequest.toPageable(), category);
var response = PagingResponse.from(page, ChallengeGroupRes.ChallengeGroupDto::from);
var response = PagingResponse.from(page, ChallengeGroupRes.Info::from);
return ApiResponse.success(response);
}

@Operation(summary = "챌린지 그룹 상세 조회", description = "챌린지 상세 조회한다.")
@GetMapping("/api/challengeGroups/{challengeGroupId}")
public ApiResponse<ChallengeGroupRes.ChallengeGroupDetailDto> getChallengeDetail(
public ApiResponse<ChallengeGroupRes.Detail> getChallengeDetail(
@PathVariable Long challengeGroupId
) {
ChallengeGroupModel.Detail challengeGroupDetail = challengeGroupQueryService.getChallengeGroupDetail(challengeGroupId);
var response = ChallengeGroupRes.ChallengeGroupDetailDto.from(challengeGroupDetail);
var response = ChallengeGroupRes.Detail.from(challengeGroupDetail);
return ApiResponse.success(response);
}



@Operation(summary = "챌린지 그룹 랭킹 조회", description = "챌린지 랭킹 조회한다.")
@GetMapping("/api/challengeGroups/{challengeGroupId}/rankings")
public ApiResponse<ChallengeGroupRes.ChallengeGroupRankingPagingResponse> getChallengeRankings(
public ApiResponse<ChallengeGroupRes.RankingPagingResponse> getChallengeRankings(
@AuthenticationPrincipal JwtUser jwtUser,
@PathVariable Long challengeGroupId,
@Valid PagingRequest pagingRequest
) {
var rankingPage = challengeGroupQueryService.getChallengeGroupRankingsPaging(challengeGroupId, pagingRequest.toPageable());
var rankingModel = challengeGroupQueryService.getChallengeGroupRanking(challengeGroupId, jwtUser.getId());
var response = ChallengeGroupRes.ChallengeGroupRankingPagingResponse
var response = ChallengeGroupRes.RankingPagingResponse
.from(rankingPage, rankingModel);
return ApiResponse.success(response);
}

//숏폼 조회
@Operation(summary = "챌린지 그룹 숏폼 페이징", description = "챌린지 숏폼 페이징 조회한다.")
@GetMapping("/api/challengeGroups/shorts")
public ApiResponse<PagingResponse<ChallengeGroupRes.ChallengeGroupDto>> getChallengeShortsPaging(
public ApiResponse<PagingResponse<ChallengeGroupRes.Info>> getChallengeShortsPaging(
@Valid PagingRequest pagingRequest,
@AuthenticationPrincipal JwtUser jwtUser
) {
var page = challengeGroupQueryService.getChallengeGroupsShortsPaging(pagingRequest.toPageable(), jwtUser.getId());
var response = PagingResponse.from(page, ChallengeGroupRes.ChallengeGroupDto::from);
var response = PagingResponse.from(page, ChallengeGroupRes.Info::from);

return ApiResponse.success(response);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ChallengeGroupRes {


@Builder
public record ChallengeGroupDto(
public record Info(
Long id,
String title,
String content,
Expand All @@ -25,10 +25,10 @@ public record ChallengeGroupDto(
ChallengeCategory category

) {
public static ChallengeGroupDto from(
public static Info from(
ChallengeGroupModel.Detail challengeGroupDetail
){
return ChallengeGroupDto.builder()
return Info.builder()
.id(challengeGroupDetail.getId())
.title(challengeGroupDetail.getTitle())
.content(challengeGroupDetail.getContent())
Expand All @@ -38,10 +38,10 @@ public static ChallengeGroupDto from(
.category(challengeGroupDetail.getCategory())
.build();
}
public static ChallengeGroupDto from(
public static Info from(
ChallengeGroupModel.Info challengeGroupInfo
){
return ChallengeGroupDto.builder()
return Info.builder()
.id(challengeGroupInfo.getId())
.title(challengeGroupInfo.getTitle())
.content(challengeGroupInfo.getContent())
Expand All @@ -55,7 +55,7 @@ public static ChallengeGroupDto from(
}

@Builder
public record ChallengeGroupDetailDto(
public record Detail(
Long id,
String title,
String content,
Expand All @@ -67,9 +67,9 @@ public record ChallengeGroupDetailDto(
String guide,
Integer maxDifficulty,
List<String> imageUrls,
List<ChallengeDto> challenges
List<Challenge> challenges
) {
public static ChallengeGroupDetailDto from(
public static Detail from(
ChallengeGroupModel.Detail challengeGroupDetail
){
List<ChallengeModel> challenges = challengeGroupDetail
Expand All @@ -81,7 +81,7 @@ public static ChallengeGroupDetailDto from(
.orElse(0);


return ChallengeGroupDetailDto.builder()
return Detail.builder()
.id(challengeGroupDetail.getId())
.title(challengeGroupDetail.getTitle())
.content(challengeGroupDetail.getContent())
Expand All @@ -93,15 +93,15 @@ public static ChallengeGroupDetailDto from(
.maxDifficulty(maxDifficulty)
.imageUrls(challengeGroupDetail.getImageUrls())
.challenges(challenges.stream()
.map(ChallengeDto::from)
.map(Challenge::from)
.toList())
.build();
}

}

@Builder
public record ChallengeDto(
public record Challenge(
Long id,
Integer participantCount,

Expand All @@ -111,10 +111,10 @@ public record ChallengeDto(
DayType dayType,
Integer dayCount
) {
public static ChallengeDto from(
public static Challenge from(
ChallengeModel challenge
){
return ChallengeDto.builder()
return Challenge.builder()
.id(challenge.getId())
.participantCount(challenge.getRequiredCount())
.difficulty(challenge.getDifficulty())
Expand All @@ -131,40 +131,40 @@ public static ChallengeDto from(


@Builder
public record ChallengeGroupRankingPagingResponse(
List<ChallengeGroupRankingDto> data,
Integer totalPage,
ChallengeGroupRankingDto myRanking //null이면 랭킹이 없는 것
public record RankingPagingResponse(
List<ChallengeGroupRes.Ranking> data,
Integer totalPage,
ChallengeGroupRes.Ranking myRanking //null이면 랭킹이 없는 것
) {
public static ChallengeGroupRankingPagingResponse from(
public static RankingPagingResponse from(
Page<ChallengeGroupModel.Ranking> rankingPage,
ChallengeGroupModel.Ranking myRanking
){
var data = rankingPage.getContent().stream()
.map(ChallengeGroupRankingDto::from)
.map(ChallengeGroupRes.Ranking::from)
.toList();
return ChallengeGroupRankingPagingResponse.builder()
return RankingPagingResponse.builder()
.data(data)
.totalPage(rankingPage.getTotalPages())
.myRanking(ChallengeGroupRankingDto.from(myRanking))
.myRanking(ChallengeGroupRes.Ranking.from(myRanking))
.build();
}

}


@Builder
public record ChallengeGroupRankingDto(
public record Ranking(
Integer ranking,
//획득 포인트
Integer acquiredPoint,
UserRes.UserDto user
UserRes.User user
) {
public static ChallengeGroupRankingDto from(
public static Ranking from(
ChallengeGroupModel.Ranking model
){
var user = UserRes.UserDto.from(model.getUser());
return ChallengeGroupRankingDto.builder()
var user = UserRes.User.from(model.getUser());
return Ranking.builder()
.ranking(model.getRank())
.acquiredPoint(model.getAccumulatedPoint())
.user(user)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ApiResponse<Void> challengeParticipation(
public ApiResponse<ChallengeRes.ChallengeVerificationResponse> challengeVerification(
@AuthenticationPrincipal JwtUser jwtUser,
@PathVariable Long challengeId,
@RequestPart("body") ChallengeReq.ChallengeVerificationRequest request,
@RequestPart("body") ChallengeReq.Verification request,
@RequestPart("image") MultipartFile image
) {
ChallengeCommand.Verificate command = request.toCommand(image);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public class ChallengeReq {

public record ChallengeVerificationRequest(
public record Verification(
String content
) {

Expand All @@ -18,7 +18,7 @@ public ChallengeCommand.Verificate toCommand(MultipartFile image) {

}

public record ChallengeReviewCreateRequest(
public record ReviewCreate(
String content,
Integer rating
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public class ChallengeReviewController {

@Operation(summary = "챌린지 그룹 최근 리뷰 페이징", description = "챌린지 최근 리뷰 페이징 조회.")
@GetMapping("/api/challengeGroups/reviews")
public ApiResponse<PagingResponse<ChallengeReviewRes.ChallengeReviewDto>> getChallengeReviews(
public ApiResponse<PagingResponse<ChallengeReviewRes.Info>> getChallengeReviews(
@Valid PagingRequest pagingRequest
//TODO SORTING
) {
Page<ChallengeReviewWithUserInfo> page = challengeService.getChallengeReviews(
pagingRequest.toPageable());

PagingResponse<ChallengeReviewRes.ChallengeReviewDto> response = PagingResponse.from(
page, ChallengeReviewRes.ChallengeReviewDto::from
PagingResponse<ChallengeReviewRes.Info> response = PagingResponse.from(
page, ChallengeReviewRes.Info::from
);

return ApiResponse.success(response);
Expand All @@ -45,16 +45,16 @@ public ApiResponse<PagingResponse<ChallengeReviewRes.ChallengeReviewDto>> getCha

@Operation(summary = "챌린지 그룹 리뷰 페이징", description = "챌린지 그룹 하위의 모든 챌린지 리뷰 페이징 조회.")
@GetMapping("/api/challengeGroups/{challengeGroupId}/reviews")
public ApiResponse<PagingResponse<ChallengeReviewRes.ChallengeReviewWithChallengeDto>> getChallengeReviewsPaging(
public ApiResponse<PagingResponse<ChallengeReviewRes.InfoWithChallenge>> getChallengeReviewsPaging(
@PathVariable Long challengeGroupId,
@Valid PagingRequest pagingRequest
//TODO SORTING
) {
Page<ChallengeReviewWithChallenge> page = challengeService.getChallengeReviewsByGroupId(
challengeGroupId, pagingRequest.toPageable());

PagingResponse<ChallengeReviewRes.ChallengeReviewWithChallengeDto> response = PagingResponse.from(
page, ChallengeReviewRes.ChallengeReviewWithChallengeDto::from
PagingResponse<ChallengeReviewRes.InfoWithChallenge> response = PagingResponse.from(
page, ChallengeReviewRes.InfoWithChallenge::from
);

return ApiResponse.success(response);
Expand All @@ -67,7 +67,7 @@ public ApiResponse<PagingResponse<ChallengeReviewRes.ChallengeReviewWithChalleng
public ApiResponse<Long> challengeReviewCreate(
@PathVariable Long challengeId,
@AuthenticationPrincipal JwtUser jwtUser,
@RequestBody ChallengeReq.ChallengeReviewCreateRequest request
@RequestBody ChallengeReq.ReviewCreate request
) {
Long response = challengeService.createReview(request.toCommand(), challengeId,
jwtUser.getId());
Expand All @@ -77,10 +77,10 @@ public ApiResponse<Long> challengeReviewCreate(
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "챌린지 그룹별 리뷰 평점 조회", description = "챌린지 그룹별 리뷰 평점 조회")
@GetMapping("/api/challengeGroups/{challengeGroupId}/reviews/score")
public ApiResponse<ChallengeReviewRes.ChallengeReviewScoreResponse> getChallengeGroupReviewScore(
public ApiResponse<ChallengeReviewRes.ScoreResponse> getChallengeGroupReviewScore(
@PathVariable Long challengeGroupId
) {
var response = ChallengeReviewRes.ChallengeReviewScoreResponse.from(
var response = ChallengeReviewRes.ScoreResponse.from(
challengeService.getChallengeGroupReviewScore(challengeGroupId));
return ApiResponse.success(response, "챌린지 그룹별 리뷰 평점 조회에 성공하였습니다.");
}
Expand Down
Loading

0 comments on commit 17b1639

Please sign in to comment.