-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEAT] 일반 유저용 멤버 관련 API 구현
- Loading branch information
Showing
67 changed files
with
2,434 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/java/com/umc/networkingService/config/SwaggerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 4 additions & 5 deletions
9
src/main/java/com/umc/networkingService/domain/friend/entity/Friend.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/com/umc/networkingService/domain/friend/repository/FriendRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.umc.networkingService.domain.friend.repository; | ||
|
||
import com.umc.networkingService.domain.friend.entity.Friend; | ||
import com.umc.networkingService.domain.member.entity.Member; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.UUID; | ||
|
||
public interface FriendRepository extends JpaRepository<Friend, UUID> { | ||
boolean existsBySenderAndReceiver(Member sender, Member receiver); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/umc/networkingService/domain/friend/service/FriendService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.umc.networkingService.domain.friend.service; | ||
|
||
import com.umc.networkingService.domain.member.entity.Member; | ||
|
||
public interface FriendService { | ||
boolean checkFriend(Member sender, Member receiver); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/umc/networkingService/domain/friend/service/FriendServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.umc.networkingService.domain.friend.service; | ||
|
||
import com.umc.networkingService.domain.friend.repository.FriendRepository; | ||
import com.umc.networkingService.domain.member.entity.Member; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class FriendServiceImpl implements FriendService { | ||
|
||
private final FriendRepository friendRepository; | ||
|
||
@Override | ||
public boolean checkFriend(Member sender, Member receiver) { | ||
return friendRepository.existsBySenderAndReceiver(sender, receiver); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/com/umc/networkingService/domain/member/client/GithubMemberClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.umc.networkingService.domain.member.client; | ||
|
||
import com.umc.networkingService.domain.member.dto.client.github.GithubAccessTokenResponse; | ||
import com.umc.networkingService.domain.member.dto.client.github.GithubInfoResponse; | ||
import com.umc.networkingService.global.common.exception.ErrorCode; | ||
import com.umc.networkingService.global.common.exception.RestApiException; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.util.LinkedMultiValueMap; | ||
import org.springframework.util.MultiValueMap; | ||
import org.springframework.web.reactive.function.BodyInserters; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
@Component | ||
public class GithubMemberClient { | ||
|
||
@Value("${github.client-id}") | ||
private String clientId; | ||
|
||
@Value("${github.client-secret}") | ||
private String clientSecret; | ||
|
||
@Value("${github.redirect-uri}") | ||
private String redirectUri; | ||
|
||
private final WebClient webClient; | ||
|
||
public GithubMemberClient() { | ||
this.webClient = generateWebClient(); | ||
} | ||
|
||
private WebClient generateWebClient() { | ||
return WebClient.builder() | ||
.baseUrl("https://github.com/login/oauth/access_token") | ||
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE) | ||
.defaultHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE) | ||
.build(); | ||
} | ||
|
||
public String getAccessToken(final String code) { | ||
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); | ||
formData.add("client_id", clientId); | ||
formData.add("client_secret", clientSecret); | ||
formData.add("code", code); | ||
formData.add("redirect_uri", redirectUri); | ||
|
||
GithubAccessTokenResponse response = webClient | ||
.post() | ||
.body(BodyInserters.fromFormData(formData)) | ||
.retrieve() | ||
.bodyToMono(GithubAccessTokenResponse.class) | ||
.blockOptional() | ||
.orElseThrow(() -> new RestApiException(ErrorCode.FAILED_GITHUB_AUTHENTICATION)); | ||
|
||
if (response == null) | ||
throw new RestApiException(ErrorCode.FAILED_GITHUB_AUTHENTICATION); | ||
|
||
return response.getAccessToken(); | ||
} | ||
|
||
public String getGithubNickname(final String code) { | ||
String accessToken = getAccessToken(code); | ||
|
||
WebClient userWebClient = WebClient.builder() | ||
.baseUrl("https://api.github.com/user") | ||
.build(); | ||
|
||
GithubInfoResponse response = userWebClient | ||
.get() | ||
.headers(headers -> headers.setBearerAuth(accessToken)) | ||
.retrieve() | ||
.bodyToMono(GithubInfoResponse.class) | ||
.block(); | ||
|
||
if (response == null) | ||
throw new RestApiException(ErrorCode.FAILED_SOCIAL_LOGIN); | ||
|
||
return response.getLogin(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.