Search in sources :

Example 1 with GithubProfileResponse

use of wooteco.prolog.login.application.dto.GithubProfileResponse in project prolog by woowacourse.

the class StudylogTagServiceTest method setUp.

@BeforeEach
void setUp() {
    SessionResponse session = sessionService.create(new SessionRequest("세션1"));
    MissionResponse mission = missionService.create(new MissionRequest("미션 이름", session.getId()));
    this.member = memberService.findOrCreateMember(new GithubProfileResponse("이름", "별명", "1", "image"));
}
Also used : MissionRequest(wooteco.prolog.session.application.dto.MissionRequest) GithubProfileResponse(wooteco.prolog.login.application.dto.GithubProfileResponse) MissionResponse(wooteco.prolog.session.application.dto.MissionResponse) SessionResponse(wooteco.prolog.session.application.dto.SessionResponse) SessionRequest(wooteco.prolog.session.application.dto.SessionRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with GithubProfileResponse

use of wooteco.prolog.login.application.dto.GithubProfileResponse in project prolog by woowacourse.

the class MemberServiceTest method findOrCreateMemberTest.

@DisplayName("Member 조회 성공시 정보를 가져오고, 실패시 Member를 생성한다.")
@Test
void findOrCreateMemberTest() {
    // given
    GithubProfileResponse brownResponse = new GithubProfileResponse("브라운", "gracefulBrown", "1", "imageUrl1");
    GithubProfileResponse jasonResponse = new GithubProfileResponse("제이슨", "pjs", "2", "imageUrl2");
    Member를_생성한다(brownResponse.toMember());
    // when
    Member brown = memberService.findOrCreateMember(brownResponse);
    Member jason = memberService.findOrCreateMember(jasonResponse);
    // then
    assertThat(memberRepository.findById(brown.getId())).isPresent();
    assertThat(memberRepository.findById(jason.getId())).isPresent();
}
Also used : GithubProfileResponse(wooteco.prolog.login.application.dto.GithubProfileResponse) Member(wooteco.prolog.member.domain.Member) LoginMember(wooteco.prolog.login.ui.LoginMember) Test(org.junit.jupiter.api.Test) IntegrationTest(wooteco.support.utils.IntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with GithubProfileResponse

use of wooteco.prolog.login.application.dto.GithubProfileResponse in project prolog by woowacourse.

the class StudylogTagServiceTest method setUp.

@BeforeEach
void setUp() {
    SessionResponse session = sessionService.create(new SessionRequest("세션1"));
    MissionResponse mission = missionService.create(new MissionRequest("미션 이름", session.getId()));
    this.member = memberService.findOrCreateMember(new GithubProfileResponse("이름", "별명", "1", "image"));
}
Also used : MissionRequest(wooteco.prolog.session.application.dto.MissionRequest) GithubProfileResponse(wooteco.prolog.login.application.dto.GithubProfileResponse) MissionResponse(wooteco.prolog.session.application.dto.MissionResponse) SessionResponse(wooteco.prolog.session.application.dto.SessionResponse) SessionRequest(wooteco.prolog.session.application.dto.SessionRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with GithubProfileResponse

use of wooteco.prolog.login.application.dto.GithubProfileResponse in project prolog by woowacourse.

the class GithubLoginService method createToken.

public TokenResponse createToken(TokenRequest tokenRequest) {
    String githubAccessToken = githubClient.getAccessTokenFromGithub(tokenRequest.getCode());
    GithubProfileResponse githubProfile = githubClient.getGithubProfileFromGithub(githubAccessToken);
    Member member = memberService.findOrCreateMember(githubProfile);
    String accessToken = jwtTokenProvider.createToken(member);
    return TokenResponse.of(accessToken);
}
Also used : GithubProfileResponse(wooteco.prolog.login.application.dto.GithubProfileResponse) Member(wooteco.prolog.member.domain.Member)

Example 5 with GithubProfileResponse

use of wooteco.prolog.login.application.dto.GithubProfileResponse in project prolog by woowacourse.

the class GithubClient method getGithubProfileFromGithub.

public GithubProfileResponse getGithubProfileFromGithub(String accessToken) {
    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "token " + accessToken);
    HttpEntity httpEntity = new HttpEntity<>(headers);
    RestTemplate restTemplate = new RestTemplate();
    try {
        return restTemplate.exchange(profileUrl, HttpMethod.GET, httpEntity, GithubProfileResponse.class).getBody();
    } catch (HttpClientErrorException e) {
        throw new GithubConnectionException();
    }
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) GithubProfileResponse(wooteco.prolog.login.application.dto.GithubProfileResponse) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HttpEntity(org.springframework.http.HttpEntity) RestTemplate(org.springframework.web.client.RestTemplate) GithubConnectionException(wooteco.prolog.login.excetpion.GithubConnectionException)

Aggregations

GithubProfileResponse (wooteco.prolog.login.application.dto.GithubProfileResponse)9 BeforeEach (org.junit.jupiter.api.BeforeEach)4 MissionRequest (wooteco.prolog.session.application.dto.MissionRequest)4 MissionResponse (wooteco.prolog.session.application.dto.MissionResponse)4 SessionRequest (wooteco.prolog.session.application.dto.SessionRequest)4 SessionResponse (wooteco.prolog.session.application.dto.SessionResponse)4 LoginMember (wooteco.prolog.login.ui.LoginMember)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 Member (wooteco.prolog.member.domain.Member)2 Mission (wooteco.prolog.session.domain.Mission)2 Session (wooteco.prolog.session.domain.Session)2 Studylog (wooteco.prolog.studylog.domain.Studylog)2 DisplayName (org.junit.jupiter.api.DisplayName)1 Test (org.junit.jupiter.api.Test)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)1 RestTemplate (org.springframework.web.client.RestTemplate)1 GithubConnectionException (wooteco.prolog.login.excetpion.GithubConnectionException)1 IntegrationTest (wooteco.support.utils.IntegrationTest)1