diff --git a/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/AgendaProfileController.java b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/AgendaProfileController.java index 4f3abac15..09f8ff60b 100644 --- a/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/AgendaProfileController.java +++ b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/AgendaProfileController.java @@ -25,6 +25,7 @@ import gg.agenda.api.user.agendaprofile.controller.response.AgendaProfileInfoDetailsResDto; import gg.agenda.api.user.agendaprofile.controller.response.AttendedAgendaListResDto; import gg.agenda.api.user.agendaprofile.controller.response.CurrentAttendAgendaListResDto; +import gg.agenda.api.user.agendaprofile.controller.response.IntraProfileResDto; import gg.agenda.api.user.agendaprofile.controller.response.MyAgendaProfileDetailsResDto; import gg.agenda.api.user.agendaprofile.service.AgendaProfileFindService; import gg.agenda.api.user.agendaprofile.service.AgendaProfileService; @@ -109,12 +110,18 @@ public ResponseEntity> getCurrentAttendAgend return ResponseEntity.ok(currentAttendAgendaList); } - @GetMapping("/{intraId}") - public ResponseEntity agendaProfileDetails(@PathVariable String intraId, - HttpServletResponse response) { + @GetMapping("{intraId}") + public ResponseEntity agendaProfileDetails(@PathVariable String intraId) { AgendaProfile profile = agendaProfileFindService.findAgendaProfileByIntraId(intraId); + AgendaProfileDetailsResDto resDto = AgendaProfileDetailsResDto.toDto(profile); + return ResponseEntity.ok(resDto); + } + + @GetMapping("/intra/{intraId}") + public ResponseEntity intraProfileDetails(@PathVariable String intraId, + HttpServletResponse response) { IntraProfile intraProfile = intraProfileUtils.getIntraProfile(intraId, response); - AgendaProfileDetailsResDto resDto = AgendaProfileDetailsResDto.toDto(profile, intraProfile); + IntraProfileResDto resDto = IntraProfileResDto.toDto(intraProfile); return ResponseEntity.ok(resDto); } diff --git a/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/response/AgendaProfileDetailsResDto.java b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/response/AgendaProfileDetailsResDto.java index c7f224121..104d8332c 100644 --- a/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/response/AgendaProfileDetailsResDto.java +++ b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/response/AgendaProfileDetailsResDto.java @@ -1,12 +1,5 @@ package gg.agenda.api.user.agendaprofile.controller.response; -import java.net.URL; -import java.util.List; - -import org.mapstruct.Mapper; - -import gg.agenda.api.user.agendaprofile.service.intraprofile.IntraAchievement; -import gg.agenda.api.user.agendaprofile.service.intraprofile.IntraProfile; import gg.data.agenda.AgendaProfile; import gg.data.agenda.type.Coalition; import gg.data.agenda.type.Location; @@ -23,31 +16,24 @@ public class AgendaProfileDetailsResDto { private String userGithub; private Coalition userCoalition; private Location userLocation; - private URL imageUrl; - private List achievements; @Builder public AgendaProfileDetailsResDto(String userIntraId, String userContent, String userGithub, - Coalition userCoalition, Location userLocation, URL imageUrl, - List achievements) { + Coalition userCoalition, Location userLocation) { this.userIntraId = userIntraId; this.userContent = userContent; this.userGithub = userGithub; this.userCoalition = userCoalition; this.userLocation = userLocation; - this.imageUrl = imageUrl; - this.achievements = achievements; } - public static AgendaProfileDetailsResDto toDto(AgendaProfile profile, IntraProfile intraProfile) { + public static AgendaProfileDetailsResDto toDto(AgendaProfile profile) { return AgendaProfileDetailsResDto.builder() .userIntraId(profile.getIntraId()) .userContent(profile.getContent()) .userGithub(profile.getGithubUrl()) .userCoalition(profile.getCoalition()) .userLocation(profile.getLocation()) - .imageUrl(intraProfile.getImageUrl()) - .achievements(intraProfile.getAchievements()) .build(); } } diff --git a/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/response/IntraProfileResDto.java b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/response/IntraProfileResDto.java new file mode 100644 index 000000000..b3b7a791b --- /dev/null +++ b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/response/IntraProfileResDto.java @@ -0,0 +1,33 @@ +package gg.agenda.api.user.agendaprofile.controller.response; + +import java.net.URL; +import java.util.List; + +import gg.agenda.api.user.agendaprofile.service.intraprofile.IntraAchievement; +import gg.agenda.api.user.agendaprofile.service.intraprofile.IntraProfile; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED) +public class IntraProfileResDto { + private String intraId; + private URL imageUrl; + private List achievements; + + @Builder + public IntraProfileResDto(String intraId, URL imageUrl, List achievements) { + this.intraId = intraId; + this.imageUrl = imageUrl; + this.achievements = achievements; + } + + public static IntraProfileResDto toDto(IntraProfile intraProfile) { + return IntraProfileResDto.builder() + .intraId(intraProfile.getIntraId()) + .imageUrl(intraProfile.getImageUrl()) + .achievements(intraProfile.getAchievements()) + .build(); + } +} diff --git a/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/service/IntraProfileUtils.java b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/service/IntraProfileUtils.java index 610c16db5..e342ed9cb 100644 --- a/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/service/IntraProfileUtils.java +++ b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/service/IntraProfileUtils.java @@ -9,7 +9,9 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; +import org.springframework.web.client.HttpClientErrorException; import gg.agenda.api.user.agendaprofile.service.intraprofile.IntraAchievement; import gg.agenda.api.user.agendaprofile.service.intraprofile.IntraImage; @@ -18,6 +20,7 @@ import gg.auth.FortyTwoAuthUtil; import gg.utils.cookie.CookieUtil; import gg.utils.exception.custom.AuthenticationException; +import gg.utils.exception.custom.NotExistException; import gg.utils.external.ApiUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -42,7 +45,7 @@ public IntraProfile getIntraProfile(HttpServletResponse response) { intraProfileResponseValidation(intraProfileResponse); IntraImage intraImage = intraProfileResponse.getImage(); List intraAchievements = intraProfileResponse.getAchievements(); - return new IntraProfile(intraImage.getLink(), intraAchievements); + return new IntraProfile(intraProfileResponse.getLogin(), intraImage.getLink(), intraAchievements); } catch (Exception e) { log.error("42 Intra Profile API 호출 실패", e); cookieUtil.deleteCookie(response, "refresh_token"); @@ -56,11 +59,14 @@ public IntraProfile getIntraProfile(String intraId, HttpServletResponse response intraProfileResponseValidation(intraProfileResponse); IntraImage intraImage = intraProfileResponse.getImage(); List intraAchievements = intraProfileResponse.getAchievements(); - return new IntraProfile(intraImage.getLink(), intraAchievements); + return new IntraProfile(intraProfileResponse.getLogin(), intraImage.getLink(), intraAchievements); } catch (Exception e) { + if (e instanceof NotExistException) { + throw new NotExistException(AUTH_NOT_FOUND); + } log.error("42 Intra Profile API 호출 실패", e); cookieUtil.deleteCookie(response, "refresh_token"); - throw new AuthenticationException(AUTH_NOT_FOUND); + throw new AuthenticationException(AUTH_NOT_VALID); } } @@ -70,7 +76,10 @@ private IntraProfileResponse requestIntraProfile(String requestUrl) { HttpHeaders headers = new HttpHeaders(); headers.setBearerAuth(accessToken); return apiUtil.apiCall(requestUrl, IntraProfileResponse.class, headers, HttpMethod.GET); - } catch (Exception e) { + } catch (HttpClientErrorException e) { + if (e.getStatusCode() == HttpStatus.NOT_FOUND) { + throw new NotExistException(AUTH_NOT_FOUND); + } String accessToken = fortyTwoAuthUtil.refreshAccessToken(); HttpHeaders headers = new HttpHeaders(); headers.setBearerAuth(accessToken); @@ -82,6 +91,9 @@ private void intraProfileResponseValidation(IntraProfileResponse intraProfileRes if (Objects.isNull(intraProfileResponse)) { throw new AuthenticationException(AUTH_NOT_FOUND); } + if (Objects.isNull(intraProfileResponse.getLogin())) { + throw new AuthenticationException(AUTH_NOT_FOUND); + } if (Objects.isNull(intraProfileResponse.getImage())) { throw new AuthenticationException(AUTH_NOT_FOUND); } diff --git a/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/service/intraprofile/IntraProfile.java b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/service/intraprofile/IntraProfile.java index 6ed2b7862..801b304f1 100644 --- a/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/service/intraprofile/IntraProfile.java +++ b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/service/intraprofile/IntraProfile.java @@ -11,13 +11,15 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class IntraProfile { + private String intraId; private URL imageUrl; private List achievements; @Builder - public IntraProfile(URL imageUrl, List achievements) { + public IntraProfile(String intraId, URL imageUrl, List achievements) { + this.intraId = intraId; this.imageUrl = imageUrl; this.achievements = achievements; } diff --git a/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/service/intraprofile/IntraProfileResponse.java b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/service/intraprofile/IntraProfileResponse.java index 8031e3561..86e295a10 100644 --- a/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/service/intraprofile/IntraProfileResponse.java +++ b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/service/intraprofile/IntraProfileResponse.java @@ -10,13 +10,15 @@ @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class IntraProfileResponse { + String login; IntraImage image; List achievements; @Builder - public IntraProfileResponse(IntraImage image, List achievements) { + public IntraProfileResponse(String login, IntraImage image, List achievements) { + this.login = login; this.image = image; this.achievements = achievements; } diff --git a/gg-agenda-api/src/test/java/gg/agenda/api/user/agenda/service/AgendaServiceTest.java b/gg-agenda-api/src/test/java/gg/agenda/api/user/agenda/service/AgendaServiceTest.java index c2f0549ca..96bbb7811 100644 --- a/gg-agenda-api/src/test/java/gg/agenda/api/user/agenda/service/AgendaServiceTest.java +++ b/gg-agenda-api/src/test/java/gg/agenda/api/user/agenda/service/AgendaServiceTest.java @@ -116,9 +116,9 @@ void getAgendaListSuccess() { int nonOfficialSize = 6; List agendas = new ArrayList<>(); IntStream.range(0, officialSize).forEach(i -> agendas.add(Agenda.builder().isOfficial(true) - .deadline(LocalDateTime.now().plusDays(i + 3)).build())); + .deadline(LocalDateTime.now().plusDays(i + 5)).build())); IntStream.range(0, nonOfficialSize).forEach(i -> agendas.add(Agenda.builder().isOfficial(false) - .deadline(LocalDateTime.now().plusDays(i + 3)).build())); + .deadline(LocalDateTime.now().plusDays(i + 2)).build())); when(agendaRepository.findAllByStatusIs(AgendaStatus.OPEN)).thenReturn(agendas); // when diff --git a/gg-agenda-api/src/test/java/gg/agenda/api/user/agendaprofile/AgendaProfileControllerTest.java b/gg-agenda-api/src/test/java/gg/agenda/api/user/agendaprofile/AgendaProfileControllerTest.java index a01fc39ec..53cbe832b 100644 --- a/gg-agenda-api/src/test/java/gg/agenda/api/user/agendaprofile/AgendaProfileControllerTest.java +++ b/gg-agenda-api/src/test/java/gg/agenda/api/user/agendaprofile/AgendaProfileControllerTest.java @@ -90,7 +90,7 @@ void beforeEach() { void test() throws Exception { //given URL url = new URL("http://localhost:8080"); - IntraProfile intraProfile = new IntraProfile(url, List.of()); + IntraProfile intraProfile = new IntraProfile(user.getIntraId(), url, List.of()); Mockito.when(intraProfileUtils.getIntraProfile(any(HttpServletResponse.class))) .thenReturn(intraProfile); AgendaProfile agendaProfile = agendaMockData.createAgendaProfile(user, SEOUL); @@ -148,7 +148,7 @@ void beforeEach() { void getAgendaProfileSuccess() throws Exception { //given URL url = new URL("http://localhost:8080"); - IntraProfile intraProfile = new IntraProfile(url, List.of()); + IntraProfile intraProfile = new IntraProfile(user.getIntraId(), url, List.of()); AgendaProfile agendaProfile = agendaMockData.createAgendaProfile(user, SEOUL); agendaMockData.createTicket(agendaProfile); Mockito.when(intraProfileUtils.getIntraProfile(any(String.class), any(HttpServletResponse.class))) @@ -174,7 +174,7 @@ void getAgendaProfileSuccess() throws Exception { void getAgendaProfileFailedWithInvalidIntraId() throws Exception { //given URL url = new URL("http://localhost:8080"); - IntraProfile intraProfile = new IntraProfile(url, List.of()); + IntraProfile intraProfile = new IntraProfile(user.getIntraId(), url, List.of()); HttpServletResponse res = Mockito.mock(HttpServletResponse.class); Mockito.when(intraProfileUtils.getIntraProfile(res)).thenReturn(intraProfile); AgendaProfile agendaProfile = agendaMockData.createAgendaProfile(user, SEOUL); diff --git a/gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java b/gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java index b83615326..9a6b6299d 100644 --- a/gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java +++ b/gg-auth/src/main/java/gg/auth/FortyTwoAuthUtil.java @@ -86,6 +86,7 @@ private OAuth2AuthorizedClient requestNewClient(OAuth2AuthorizedClient client, C params.add("refresh_token", client.getRefreshToken().getTokenValue()); params.add("client_id", registration.getClientId()); params.add("client_secret", registration.getClientSecret()); + params.add("redirect_uri", registration.getRedirectUri()); List> responseBody = apiUtil.apiCall( registration.getProviderDetails().getTokenUri(), diff --git a/gg-utils/src/main/java/gg/utils/exception/ErrorCode.java b/gg-utils/src/main/java/gg/utils/exception/ErrorCode.java index cdc8162f1..e39ddf8fa 100644 --- a/gg-utils/src/main/java/gg/utils/exception/ErrorCode.java +++ b/gg-utils/src/main/java/gg/utils/exception/ErrorCode.java @@ -193,6 +193,7 @@ public enum ErrorCode { INVALID_CHECKLIST(400, "RE001", "잘못된 요청 데이터입니다."), // agenda + AUTH_NOT_VALID(401, "AG001", "인증이 유효하지 않습니다."), AGENDA_TEAM_FULL(400, "AG101", "팀이 꽉 찼습니다."), LOCATION_NOT_VALID(400, "AG102", "유효하지 않은 지역입니다."), AGENDA_AWARD_EMPTY(400, "AG103", "시상 정보가 없습니다."), @@ -216,7 +217,7 @@ public enum ErrorCode { TEAM_LEADER_FORBIDDEN(403, "AG207", "팀장이 아닙니다."), AGENDA_TEAM_FORBIDDEN(403, "AG208", "일정에 참여한 팀이 있습니다."), AGENDA_MODIFICATION_FORBIDDEN(403, "AG209", "개최자만 일정을 수정할 수 있습니다."), - AUTH_NOT_FOUND(404, "AG301", "42 정보가 만료되었습니다."), + AUTH_NOT_FOUND(404, "AG301", "42 정보를 찾을 수 없습니다."), TICKET_NOT_FOUND(404, "AG302", "해당 티켓이 존재하지 않습니다."), AGENDA_NOT_FOUND(404, "AG303", "해당 일정이 존재하지 않습니다."), NOT_SETUP_TICKET(404, "AG304", "티켓 신청이 되어있지 않습니다."),