From 9d4cb34a34c0798038be85263ec948f40ab0ff44 Mon Sep 17 00:00:00 2001 From: jeongwpa <55525927+yhames@users.noreply.github.com> Date: Mon, 26 Aug 2024 14:20:21 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20[Feature]=20=EB=8B=A4=EB=A5=B8=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=9E=90=20AgendaProfile=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20#977=20(#978)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/response/AgendaTeamResDto.java | 8 ++- .../controller/AgendaHostController.java | 14 ++-- .../controller/AgendaProfileController.java | 55 +++++++++------- .../response/AgendaProfileDetailsResDto.java | 27 +++++--- .../MyAgendaProfileDetailsResDto.java | 55 ++++++++++++++++ .../service/IntraProfileUtils.java | 37 ++++++++--- .../AgendaHostControllerTest.java | 8 +-- .../AgendaProfileControllerTest.java | 65 +++++++++++++++++-- 8 files changed, 209 insertions(+), 60 deletions(-) create mode 100644 gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/response/MyAgendaProfileDetailsResDto.java diff --git a/gg-agenda-api/src/main/java/gg/agenda/api/admin/agendateam/controller/response/AgendaTeamResDto.java b/gg-agenda-api/src/main/java/gg/agenda/api/admin/agendateam/controller/response/AgendaTeamResDto.java index 939864087..850b2e1b6 100644 --- a/gg-agenda-api/src/main/java/gg/agenda/api/admin/agendateam/controller/response/AgendaTeamResDto.java +++ b/gg-agenda-api/src/main/java/gg/agenda/api/admin/agendateam/controller/response/AgendaTeamResDto.java @@ -7,6 +7,7 @@ import org.mapstruct.factory.Mappers; import gg.data.agenda.AgendaTeam; +import gg.data.agenda.type.Location; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -32,11 +33,14 @@ public class AgendaTeamResDto { private String teamAward; + private Location teamLocation; + private Integer teamAwardPriority; @Builder public AgendaTeamResDto(String teamName, String teamStatus, boolean teamIsPrivate, String teamLeaderIntraId, - int teamMateCount, UUID teamKey, String teamAward, Integer teamAwardPriority, String teamContent) { + int teamMateCount, UUID teamKey, String teamAward, Integer teamAwardPriority, String teamContent, + Location teamLocation) { this.teamName = teamName; this.teamContent = teamContent; this.teamStatus = teamStatus; @@ -46,6 +50,7 @@ public AgendaTeamResDto(String teamName, String teamStatus, boolean teamIsPrivat this.teamKey = teamKey; this.teamAward = teamAward; this.teamAwardPriority = teamAwardPriority; + this.teamLocation = teamLocation; } @Mapper @@ -60,6 +65,7 @@ public interface MapStruct { @Mapping(target = "teamLeaderIntraId", source = "leaderIntraId") @Mapping(target = "teamMateCount", source = "mateCount") @Mapping(target = "teamKey", source = "teamKey") + @Mapping(target = "teamLocation", source = "location") @Mapping(target = "teamAward", source = "award", defaultValue = "AgendaTeam.DEFAULT_AWARD") @Mapping(target = "teamAwardPriority", source = "awardPriority", defaultValue = "0") AgendaTeamResDto toDto(AgendaTeam agendaTeam); diff --git a/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/AgendaHostController.java b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/AgendaHostController.java index a0b873cfb..87062f5c8 100644 --- a/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/AgendaHostController.java +++ b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/AgendaHostController.java @@ -12,6 +12,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -32,15 +33,14 @@ public class AgendaHostController { private final AgendaProfileFindService agendaProfileFindService; - @GetMapping("/history/list") + @GetMapping("/history/list/{intraId}") public ResponseEntity> hostedAgendaList( - @Login @Parameter(hidden = true) UserDto user, - @ModelAttribute @Valid PageRequestDto pageRequestDto) { + @PathVariable String intraId, @ModelAttribute @Valid PageRequestDto pageRequestDto) { int page = pageRequestDto.getPage(); int size = pageRequestDto.getSize(); Pageable pageable = PageRequest.of(page - 1, size, Sort.by("id").descending()); - Page hostedAgendas = agendaProfileFindService.findHostedAgenda(user.getIntraId(), pageable); + Page hostedAgendas = agendaProfileFindService.findHostedAgenda(intraId, pageable); List agendaResDtos = hostedAgendas.stream() .map(HostedAgendaResDto.MapStruct.INSTANCE::toDto) @@ -50,15 +50,15 @@ public ResponseEntity> hostedAgendaList( return ResponseEntity.ok(pageResponseDto); } - @GetMapping("/current/list") + @GetMapping("/current/list/{intraId}") public ResponseEntity> hostingAgendaList( - @Login @Parameter(hidden = true) UserDto user, + @PathVariable String intraId, @ModelAttribute @Valid PageRequestDto pageRequestDto) { int page = pageRequestDto.getPage(); int size = pageRequestDto.getSize(); Pageable pageable = PageRequest.of(page - 1, size, Sort.by("id").descending()); - Page hostedAgendas = agendaProfileFindService.findHostingAgenda(user.getIntraId(), pageable); + Page hostedAgendas = agendaProfileFindService.findHostingAgenda(intraId, pageable); List agendaResDtos = hostedAgendas.stream() .map(HostedAgendaResDto.MapStruct.INSTANCE::toDto) 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 0d127b76f..0e5755efe 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 @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -23,6 +24,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.MyAgendaProfileDetailsResDto; import gg.agenda.api.user.agendaprofile.service.AgendaProfileFindService; import gg.agenda.api.user.agendaprofile.service.AgendaProfileService; import gg.agenda.api.user.agendaprofile.service.IntraProfileUtils; @@ -49,18 +51,33 @@ public class AgendaProfileController { private final TicketService ticketService; private final IntraProfileUtils intraProfileUtils; + /** + * AgendaProfile admin 여부 조회 API + * @param user 로그인한 사용자 정보 + */ + @GetMapping("/info") + public ResponseEntity myAgendaProfileInfoDetails( + @Login @Parameter(hidden = true) UserDto user) { + String intraId = user.getIntraId(); + Boolean isAdmin = user.getRoleType() == RoleType.ADMIN; + + AgendaProfileInfoDetailsResDto agendaProfileInfoDetails = new AgendaProfileInfoDetailsResDto(intraId, isAdmin); + + return ResponseEntity.ok(agendaProfileInfoDetails); + } + /** * AgendaProfile 상세 조회 API * @param user 로그인한 사용자 정보 * @return AgendaProfileDetailsResDto 객체와 HTTP 상태 코드를 포함한 ResponseEntity */ @GetMapping - public ResponseEntity myAgendaProfileDetails( + public ResponseEntity myAgendaProfileDetails( @Login @Parameter(hidden = true) UserDto user) { AgendaProfile profile = agendaProfileFindService.findAgendaProfileByIntraId(user.getIntraId()); int ticketCount = ticketService.findTicketList(profile).size(); IntraProfile intraProfile = intraProfileUtils.getIntraProfile(); - AgendaProfileDetailsResDto agendaProfileDetails = AgendaProfileDetailsResDto.toDto( + MyAgendaProfileDetailsResDto agendaProfileDetails = MyAgendaProfileDetailsResDto.toDto( profile, ticketCount, intraProfile); return ResponseEntity.ok(agendaProfileDetails); } @@ -78,21 +95,6 @@ public ResponseEntity agendaProfileModify(@Login @Parameter(hidden = true) return ResponseEntity.status(HttpStatus.NO_CONTENT).build(); } - /** - * AgendaProfile admin 여부 조회 API - * @param user 로그인한 사용자 정보 - */ - @GetMapping("/info") - public ResponseEntity myAgendaProfileInfoDetails( - @Login @Parameter(hidden = true) UserDto user) { - String intraId = user.getIntraId(); - Boolean isAdmin = user.getRoleType() == RoleType.ADMIN; - - AgendaProfileInfoDetailsResDto agendaProfileInfoDetails = new AgendaProfileInfoDetailsResDto(intraId, isAdmin); - - return ResponseEntity.ok(agendaProfileInfoDetails); - } - /** * 현재 참여중인 Agenda 목록 조회하는 메서드 * @param user 로그인한 유저의 id @@ -101,23 +103,28 @@ public ResponseEntity myAgendaProfileInfoDetails @GetMapping("/current/list") public ResponseEntity> getCurrentAttendAgendaList( @Login @Parameter(hidden = true) UserDto user) { - String intraId = user.getIntraId(); - - List currentAttendAgendaList = agendaProfileFindService.findCurrentAttendAgenda( - intraId); + List currentAttendAgendaList = agendaProfileFindService + .findCurrentAttendAgenda(user.getIntraId()); return ResponseEntity.ok(currentAttendAgendaList); } + @GetMapping("/{intraId}") + public ResponseEntity agendaProfileDetails(@PathVariable String intraId) { + AgendaProfile profile = agendaProfileFindService.findAgendaProfileByIntraId(intraId); + IntraProfile intraProfile = intraProfileUtils.getIntraProfile(intraId); + AgendaProfileDetailsResDto resDto = AgendaProfileDetailsResDto.toDto(profile, intraProfile); + return ResponseEntity.ok(resDto); + } + /** * 과거에 참여했던 Agenda 목록 조회하는 메서드 * @param pageRequest 페이지네이션 요청 정보, agendaId 아젠다 아이디 */ - @GetMapping("/history/list") + @GetMapping("/history/list/{intraId}") public ResponseEntity> getAttendedAgendaList( - @Login @Parameter(hidden = true) UserDto user, @ModelAttribute @Valid PageRequestDto pageRequest) { + @PathVariable String intraId, @ModelAttribute @Valid PageRequestDto pageRequest) { int page = pageRequest.getPage(); int size = pageRequest.getSize(); - String intraId = user.getIntraId(); Pageable pageable = PageRequest.of(page - 1, size, Sort.by("id").descending()); Page attendedAgendaList = agendaProfileFindService 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 fe479063c..c7f224121 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,46 +1,53 @@ 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; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; @Getter -@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED) +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class AgendaProfileDetailsResDto { - private String userIntraId; private String userContent; private String userGithub; private Coalition userCoalition; private Location userLocation; - private int ticketCount; - private IntraProfile intraProfile; + private URL imageUrl; + private List achievements; @Builder public AgendaProfileDetailsResDto(String userIntraId, String userContent, String userGithub, - Coalition userCoalition, Location userLocation, int ticketCount, IntraProfile intraProfile) { + Coalition userCoalition, Location userLocation, URL imageUrl, + List achievements) { this.userIntraId = userIntraId; this.userContent = userContent; this.userGithub = userGithub; this.userCoalition = userCoalition; this.userLocation = userLocation; - this.ticketCount = ticketCount; - this.intraProfile = intraProfile; + this.imageUrl = imageUrl; + this.achievements = achievements; } - public static AgendaProfileDetailsResDto toDto(AgendaProfile profile, int ticketCount, IntraProfile intraProfile) { + public static AgendaProfileDetailsResDto toDto(AgendaProfile profile, IntraProfile intraProfile) { return AgendaProfileDetailsResDto.builder() .userIntraId(profile.getIntraId()) .userContent(profile.getContent()) .userGithub(profile.getGithubUrl()) .userCoalition(profile.getCoalition()) .userLocation(profile.getLocation()) - .ticketCount(ticketCount) - .intraProfile(intraProfile) + .imageUrl(intraProfile.getImageUrl()) + .achievements(intraProfile.getAchievements()) .build(); } } diff --git a/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/response/MyAgendaProfileDetailsResDto.java b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/response/MyAgendaProfileDetailsResDto.java new file mode 100644 index 000000000..abb0d37fa --- /dev/null +++ b/gg-agenda-api/src/main/java/gg/agenda/api/user/agendaprofile/controller/response/MyAgendaProfileDetailsResDto.java @@ -0,0 +1,55 @@ +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 gg.data.agenda.AgendaProfile; +import gg.data.agenda.type.Coalition; +import gg.data.agenda.type.Location; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED) +public class MyAgendaProfileDetailsResDto { + + private String userIntraId; + private String userContent; + private String userGithub; + private Coalition userCoalition; + private Location userLocation; + private int ticketCount; + private URL imageUrl; + private List achievements; + + @Builder + public MyAgendaProfileDetailsResDto(String userIntraId, String userContent, String userGithub, + Coalition userCoalition, Location userLocation, int ticketCount, URL imageUrl, + List achievements) { + this.userIntraId = userIntraId; + this.userContent = userContent; + this.userGithub = userGithub; + this.userCoalition = userCoalition; + this.userLocation = userLocation; + this.ticketCount = ticketCount; + this.imageUrl = imageUrl; + this.achievements = achievements; + } + + public static MyAgendaProfileDetailsResDto toDto(AgendaProfile profile, int ticketCount, + IntraProfile intraProfile) { + return MyAgendaProfileDetailsResDto.builder() + .userIntraId(profile.getIntraId()) + .userContent(profile.getContent()) + .userGithub(profile.getGithubUrl()) + .userCoalition(profile.getCoalition()) + .userLocation(profile.getLocation()) + .ticketCount(ticketCount) + .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 890d2980f..6e7c39e95 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 @@ -23,34 +23,55 @@ @Component @RequiredArgsConstructor public class IntraProfileUtils { + private static final String INTRA_PROFILE_URL = "https://api.intra.42.fr/v2/me"; + private static final String INTRA_USERS_URL = "https://api.intra.42.fr/v2/users/"; private final FortyTwoAuthUtil fortyTwoAuthUtil; private final ApiUtil apiUtil; public IntraProfile getIntraProfile() { - IntraProfileResponse intraProfileResponse = requestIntraProfile(); - intraProfileResponseValidation(intraProfileResponse); - IntraImage intraImage = intraProfileResponse.getImage(); - List intraAchievements = intraProfileResponse.getAchievements(); - return new IntraProfile(intraImage.getLink(), intraAchievements); + try { + IntraProfileResponse intraProfileResponse = requestIntraProfile(INTRA_PROFILE_URL); + intraProfileResponseValidation(intraProfileResponse); + IntraImage intraImage = intraProfileResponse.getImage(); + List intraAchievements = intraProfileResponse.getAchievements(); + return new IntraProfile(intraImage.getLink(), intraAchievements); + } catch (Exception e) { + log.error("42 Intra Profile API 호출 실패", e); + throw new AuthenticationException(AUTH_NOT_FOUND); + } + } + + public IntraProfile getIntraProfile(String intraId) { + try { + IntraProfileResponse intraProfileResponse = requestIntraProfile(INTRA_USERS_URL + intraId); + intraProfileResponseValidation(intraProfileResponse); + IntraImage intraImage = intraProfileResponse.getImage(); + List intraAchievements = intraProfileResponse.getAchievements(); + return new IntraProfile(intraImage.getLink(), intraAchievements); + } catch (Exception e) { + log.error("42 Intra Profile API 호출 실패", e); + throw new AuthenticationException(AUTH_NOT_FOUND); + } } - private IntraProfileResponse requestIntraProfile() { + private IntraProfileResponse requestIntraProfile(String requestUrl) { try { String accessToken = fortyTwoAuthUtil.getAccessToken(); HttpHeaders headers = new HttpHeaders(); headers.setBearerAuth(accessToken); - return apiUtil.apiCall(INTRA_PROFILE_URL, IntraProfileResponse.class, headers, HttpMethod.GET); + return apiUtil.apiCall(requestUrl, IntraProfileResponse.class, headers, HttpMethod.GET); } catch (Exception e) { String accessToken = fortyTwoAuthUtil.refreshAccessToken(); HttpHeaders headers = new HttpHeaders(); headers.setBearerAuth(accessToken); - return apiUtil.apiCall(INTRA_PROFILE_URL, IntraProfileResponse.class, headers, HttpMethod.GET); + return apiUtil.apiCall(requestUrl, IntraProfileResponse.class, headers, HttpMethod.GET); } } + private void intraProfileResponseValidation(IntraProfileResponse intraProfileResponse) { if (Objects.isNull(intraProfileResponse)) { throw new AuthenticationException(AUTH_NOT_FOUND); diff --git a/gg-agenda-api/src/test/java/gg/agenda/api/user/agendaprofile/AgendaHostControllerTest.java b/gg-agenda-api/src/test/java/gg/agenda/api/user/agendaprofile/AgendaHostControllerTest.java index d2499409f..4dbe4935f 100644 --- a/gg-agenda-api/src/test/java/gg/agenda/api/user/agendaprofile/AgendaHostControllerTest.java +++ b/gg-agenda-api/src/test/java/gg/agenda/api/user/agendaprofile/AgendaHostControllerTest.java @@ -76,7 +76,7 @@ void hostedAgendaListSuccess(int page) throws Exception { .collect(Collectors.toList()); // when - String response = mockMvc.perform(get("/agenda/host/history/list") + String response = mockMvc.perform(get("/agenda/host/history/list/" + user.getIntraId()) .header("Authorization", "Bearer " + accessToken) .param("page", String.valueOf(page)) .param("size", String.valueOf(size))) @@ -105,7 +105,7 @@ void hostedAgendaListSuccessWithEmptyAgenda() throws Exception { // given // when - String response = mockMvc.perform(get("/agenda/host/history/list") + String response = mockMvc.perform(get("/agenda/host/history/list/" + user.getIntraId()) .header("Authorization", "Bearer " + accessToken) .param("page", "1") .param("size", "10")) @@ -141,7 +141,7 @@ void hostingAgendaListSuccess(int page) throws Exception { .collect(Collectors.toList()); // when - String response = mockMvc.perform(get("/agenda/host/current/list") + String response = mockMvc.perform(get("/agenda/host/current/list/" + user.getIntraId()) .header("Authorization", "Bearer " + accessToken) .param("page", String.valueOf(page)) .param("size", String.valueOf(size))) @@ -170,7 +170,7 @@ void hostingAgendaListSuccessWithEmptyList() throws Exception { // given // when - String response = mockMvc.perform(get("/agenda/host/current/list") + String response = mockMvc.perform(get("/agenda/host/current/list/" + user.getIntraId()) .header("Authorization", "Bearer " + accessToken) .param("page", "1") .param("size", "10")) 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 477028add..c04c000fc 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 @@ -34,6 +34,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.MyAgendaProfileDetailsResDto; import gg.agenda.api.user.agendaprofile.service.IntraProfileUtils; import gg.agenda.api.user.agendaprofile.service.intraprofile.IntraProfile; import gg.data.agenda.Agenda; @@ -73,8 +74,8 @@ public class AgendaProfileControllerTest { AgendaProfile agendaProfile; @Nested - @DisplayName("agenda profile 상세 조회") - class GetAgendaProfile { + @DisplayName("나의 agenda profile 상세 조회") + class GetMyAgendaProfile { @BeforeEach void beforeEach() { @@ -96,7 +97,7 @@ void test() throws Exception { .header("Authorization", "Bearer " + accessToken)) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(); - AgendaProfileDetailsResDto result = objectMapper.readValue(response, AgendaProfileDetailsResDto.class); + MyAgendaProfileDetailsResDto result = objectMapper.readValue(response, MyAgendaProfileDetailsResDto.class); // then assertThat(result.getUserIntraId()).isEqualTo(user.getIntraId()); assertThat(result.getUserContent()).isEqualTo(agendaProfile.getContent()); @@ -129,6 +130,58 @@ void testAgendaProfileNotFound() throws Exception { } } + @Nested + @DisplayName("agenda profile 상세 조회") + class GetAgendaProfile { + + @BeforeEach + void beforeEach() { + user = testDataUtils.createNewUser(); + accessToken = testDataUtils.getLoginAccessTokenFromUser(user); + } + + @Test + @DisplayName("agenda profile 상세 조회 성공") + void getAgendaProfileSuccess() throws Exception { + //given + URL url = new URL("http://localhost:8080"); + IntraProfile intraProfile = new IntraProfile(url, List.of()); + Mockito.when(intraProfileUtils.getIntraProfile(user.getIntraId())).thenReturn(intraProfile); + AgendaProfile agendaProfile = agendaMockData.createAgendaProfile(user, SEOUL); + agendaMockData.createTicket(agendaProfile); + // when + String response = mockMvc.perform(get("/agenda/profile/" + user.getIntraId()) + .header("Authorization", "Bearer " + accessToken)) + .andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString(); + AgendaProfileDetailsResDto result = objectMapper.readValue(response, + AgendaProfileDetailsResDto.class); + + // then + assertThat(result.getUserIntraId()).isEqualTo(user.getIntraId()); + assertThat(result.getUserContent()).isEqualTo(agendaProfile.getContent()); + assertThat(result.getUserGithub()).isEqualTo(agendaProfile.getGithubUrl()); + assertThat(result.getUserCoalition()).isEqualTo(agendaProfile.getCoalition()); + assertThat(result.getUserLocation()).isEqualTo(agendaProfile.getLocation()); + } + + @Test + @DisplayName("agenda profile 상세 조회 성공 - 존재하지 않는 사용자인 경우") + void getAgendaProfileFailedWithInvalidIntraId() throws Exception { + //given + URL url = new URL("http://localhost:8080"); + IntraProfile intraProfile = new IntraProfile(url, List.of()); + Mockito.when(intraProfileUtils.getIntraProfile()).thenReturn(intraProfile); + AgendaProfile agendaProfile = agendaMockData.createAgendaProfile(user, SEOUL); + agendaMockData.createTicket(agendaProfile); + + // when + mockMvc.perform(get("/agenda/profile/" + "invalidIntraId") + .header("Authorization", "Bearer " + accessToken)) + .andExpect(status().isNotFound()); + } + } + @Nested @DisplayName("개인 프로필 정보 변경") class UpdateAgendaProfile { @@ -384,7 +437,7 @@ void getAttendedAgendaListSuccess(int page) throws Exception { String request = objectMapper.writeValueAsString(pageRequest); // when - String response = mockMvc.perform(get("/agenda/profile/history/list") + String response = mockMvc.perform(get("/agenda/profile/history/list/" + user.getIntraId()) .header("Authorization", "Bearer " + accessToken) .param("page", String.valueOf(page)) .param("size", String.valueOf(size)) @@ -427,7 +480,7 @@ void getAttendedAgendaListSuccessNoAgenda() throws Exception { String request = objectMapper.writeValueAsString(pageRequest); // when - String response = mockMvc.perform(get("/agenda/profile/history/list") + String response = mockMvc.perform(get("/agenda/profile/history/list/" + user.getIntraId()) .header("Authorization", "Bearer " + accessToken) .param("page", "1") .param("size", "10") @@ -452,7 +505,7 @@ void getAttendedAgendaListBadRequest() throws Exception { String request = objectMapper.writeValueAsString(pageRequest); // when & then - mockMvc.perform(get("/agenda/profile/history/list") + mockMvc.perform(get("/agenda/profile/history/list/" + user.getIntraId()) .header("Authorization", "Bearer " + accessToken) .param("page", "0") .param("size", "10")