Skip to content

Commit

Permalink
✨ [Feature] 다른 사용자 AgendaProfile 조회 API #977 (#978)
Browse files Browse the repository at this point in the history
  • Loading branch information
yhames authored Aug 26, 2024
1 parent ef93835 commit 9d4cb34
Show file tree
Hide file tree
Showing 8 changed files with 209 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -32,15 +33,14 @@ public class AgendaHostController {

private final AgendaProfileFindService agendaProfileFindService;

@GetMapping("/history/list")
@GetMapping("/history/list/{intraId}")
public ResponseEntity<PageResponseDto<HostedAgendaResDto>> 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<Agenda> hostedAgendas = agendaProfileFindService.findHostedAgenda(user.getIntraId(), pageable);
Page<Agenda> hostedAgendas = agendaProfileFindService.findHostedAgenda(intraId, pageable);

List<HostedAgendaResDto> agendaResDtos = hostedAgendas.stream()
.map(HostedAgendaResDto.MapStruct.INSTANCE::toDto)
Expand All @@ -50,15 +50,15 @@ public ResponseEntity<PageResponseDto<HostedAgendaResDto>> hostedAgendaList(
return ResponseEntity.ok(pageResponseDto);
}

@GetMapping("/current/list")
@GetMapping("/current/list/{intraId}")
public ResponseEntity<PageResponseDto<HostedAgendaResDto>> 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<Agenda> hostedAgendas = agendaProfileFindService.findHostingAgenda(user.getIntraId(), pageable);
Page<Agenda> hostedAgendas = agendaProfileFindService.findHostingAgenda(intraId, pageable);

List<HostedAgendaResDto> agendaResDtos = hostedAgendas.stream()
.map(HostedAgendaResDto.MapStruct.INSTANCE::toDto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -49,18 +51,33 @@ public class AgendaProfileController {
private final TicketService ticketService;
private final IntraProfileUtils intraProfileUtils;

/**
* AgendaProfile admin 여부 조회 API
* @param user 로그인한 사용자 정보
*/
@GetMapping("/info")
public ResponseEntity<AgendaProfileInfoDetailsResDto> 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<AgendaProfileDetailsResDto> myAgendaProfileDetails(
public ResponseEntity<MyAgendaProfileDetailsResDto> 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);
}
Expand All @@ -78,21 +95,6 @@ public ResponseEntity<Void> agendaProfileModify(@Login @Parameter(hidden = true)
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

/**
* AgendaProfile admin 여부 조회 API
* @param user 로그인한 사용자 정보
*/
@GetMapping("/info")
public ResponseEntity<AgendaProfileInfoDetailsResDto> 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
Expand All @@ -101,23 +103,28 @@ public ResponseEntity<AgendaProfileInfoDetailsResDto> myAgendaProfileInfoDetails
@GetMapping("/current/list")
public ResponseEntity<List<CurrentAttendAgendaListResDto>> getCurrentAttendAgendaList(
@Login @Parameter(hidden = true) UserDto user) {
String intraId = user.getIntraId();

List<CurrentAttendAgendaListResDto> currentAttendAgendaList = agendaProfileFindService.findCurrentAttendAgenda(
intraId);
List<CurrentAttendAgendaListResDto> currentAttendAgendaList = agendaProfileFindService
.findCurrentAttendAgenda(user.getIntraId());
return ResponseEntity.ok(currentAttendAgendaList);
}

@GetMapping("/{intraId}")
public ResponseEntity<AgendaProfileDetailsResDto> 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<PageResponseDto<AttendedAgendaListResDto>> 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<AgendaTeamProfile> attendedAgendaList = agendaProfileFindService
Expand Down
Original file line number Diff line number Diff line change
@@ -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<IntraAchievement> 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<IntraAchievement> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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<IntraAchievement> achievements;

@Builder
public MyAgendaProfileDetailsResDto(String userIntraId, String userContent, String userGithub,
Coalition userCoalition, Location userLocation, int ticketCount, URL imageUrl,
List<IntraAchievement> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<IntraAchievement> intraAchievements = intraProfileResponse.getAchievements();
return new IntraProfile(intraImage.getLink(), intraAchievements);
try {
IntraProfileResponse intraProfileResponse = requestIntraProfile(INTRA_PROFILE_URL);
intraProfileResponseValidation(intraProfileResponse);
IntraImage intraImage = intraProfileResponse.getImage();
List<IntraAchievement> 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<IntraAchievement> 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);
Expand Down
Loading

0 comments on commit 9d4cb34

Please sign in to comment.