Skip to content

Commit

Permalink
Merge pull request #27 from Leets-Official/24-fearture-마이페이지-구현
Browse files Browse the repository at this point in the history
24 fearture 마이페이지 구현
  • Loading branch information
zzu-yaaa authored Jul 30, 2024
2 parents 701705c + 1433633 commit 6f088cc
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 8 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {

// GSON
implementation "com.google.code.gson:gson:2.8.9"

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.util.Optional;

import com.leets.commitatobe.domain.user.presentation.dto.response.UserInfoResponse;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -16,4 +17,5 @@ public interface UserRepository extends JpaRepository<User, UUID> {

//경험치순으로 유저를 페이징하여 조회하는 메서드
Page<User> findAllByOrderByExpDesc(Pageable pageable);

}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.leets.commitatobe.domain.user.presentation;

import com.leets.commitatobe.domain.login.usecase.LoginQueryService;
import com.leets.commitatobe.domain.user.presentation.dto.response.UserInfoResponse;
import com.leets.commitatobe.domain.user.presentation.dto.response.UserRankResponse;
import com.leets.commitatobe.domain.user.presentation.dto.response.UserSearchResponse;
import com.leets.commitatobe.domain.user.usecase.UserQueryService;
import com.leets.commitatobe.global.response.ApiResponse;
import com.leets.commitatobe.global.response.CustomPageResponse;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;


@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserController {
private final UserQueryService userQueryService;

private final LoginQueryService loginQueryService;
@Operation(
summary = "유저 정보 검색",
description = "깃허브 아이디로 검색합니다."
Expand All @@ -37,4 +37,11 @@ public ApiResponse<CustomPageResponse<UserRankResponse>> getUsersByExp(@RequestP
@RequestParam(name = "size") int size) {
return ApiResponse.onSuccess(userQueryService.getUsersOrderByExp(page, size));
}

@GetMapping("/{githubId}")
public ApiResponse<UserInfoResponse> getUserInfo(@PathVariable String githubId, HttpServletRequest request){
String myGitHubId = loginQueryService.getGitHubId(request);
return ApiResponse.onSuccess(userQueryService.findUserInfo(githubId, myGitHubId));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.leets.commitatobe.domain.user.presentation.dto.response;

import com.leets.commitatobe.domain.commit.domain.Commit;
import com.leets.commitatobe.domain.user.domain.User;
import lombok.AccessLevel;
import lombok.Builder;

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

@Builder(access = AccessLevel.PRIVATE)
public record UserInfoResponse(
Boolean isMyAccount,
String githubId,
String tierName,
String characterUrl,
Integer consecutiveCommitDays,
Integer todayCommitCount,
Integer totalCommitCount,
LocalDateTime updatedAt
) {
public static UserInfoResponse of(boolean isMyAccount, User user){
return UserInfoResponse.builder()
.isMyAccount(isMyAccount)
.githubId(user.getGithubId())
.tierName(user.getTier().getTierName())
.characterUrl(user.getTier().getCharacterUrl())
.consecutiveCommitDays(user.getConsecutiveCommitDays())
.todayCommitCount(user.getTodayCommitCount())
.totalCommitCount(user.getTotalCommitCount())
.updatedAt(user.getUpdatedAt())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.leets.commitatobe.domain.user.usecase;


import com.leets.commitatobe.domain.user.presentation.dto.response.UserInfoResponse;
import com.leets.commitatobe.domain.user.presentation.dto.response.UserRankResponse;
import com.leets.commitatobe.domain.user.presentation.dto.response.UserSearchResponse;
import com.leets.commitatobe.global.response.CustomPageResponse;

public interface UserQueryService {
UserSearchResponse searchUsersByGithubId(String GithubId);//유저 이름으로 유저 정보를 검색하는 메서드

CustomPageResponse<UserRankResponse> getUsersOrderByExp(int page, int size);//경험치 순으로 페이징된 유저 정보를 조회

String getUserGitHubAccessToken(String githubId);


UserInfoResponse findUserInfo(String githubId, String myGitHubId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.leets.commitatobe.domain.tier.domain.Tier;
import com.leets.commitatobe.domain.user.domain.User;
import com.leets.commitatobe.domain.user.domain.repository.UserRepository;
import com.leets.commitatobe.domain.user.presentation.dto.response.UserInfoResponse;
import com.leets.commitatobe.domain.user.presentation.dto.response.UserRankResponse;
import com.leets.commitatobe.domain.user.presentation.dto.response.UserSearchResponse;
import com.leets.commitatobe.global.exception.ApiException;
Expand Down Expand Up @@ -62,7 +63,7 @@ public CustomPageResponse<UserRankResponse> getUsersOrderByExp(int page, int siz
user.getUsername(),
user.getExp(),
user.getConsecutiveCommitDays(),
tier!=null?tier.getTierName():"Unranked",
tier != null ? tier.getTierName() : "Unranked",
user.getRanking());//랭킹 추가
});

Expand All @@ -77,4 +78,12 @@ public String getUserGitHubAccessToken(String githubId) {

return loginCommandService.decrypt(gitHubAccessToken);
}

@Override
public UserInfoResponse findUserInfo(String githubId, String myGitHubId) {
User user = userRepository.findByGithubId(githubId).orElseThrow(() -> new ApiException(_USER_NOT_FOUND));
return UserInfoResponse.of(githubId.equals(myGitHubId), user);
}


}
4 changes: 2 additions & 2 deletions src/main/resources/application-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ spring:
datasource:
url: jdbc:mysql://localhost:3306/commitato
username: root
password:
password: 1220
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
show-sql: true
hibernate:
ddl-auto: create-drop
ddl-auto: update
database: mysql
database-platform: org.hibernate.dialect.MySQLDialect
properties:
Expand Down

0 comments on commit 6f088cc

Please sign in to comment.