Skip to content

Commit

Permalink
✨ [Feature] 로그인 사용자 프로필 정보 조회 API #912 (#913)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimjieun0301 authored Jul 27, 2024
1 parent f9e7a01 commit 7252f83
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@

import gg.agenda.api.user.agendaprofile.controller.request.AgendaProfileChangeReqDto;
import gg.agenda.api.user.agendaprofile.controller.response.AgendaProfileDetailsResDto;
import gg.agenda.api.user.agendaprofile.controller.response.AgendaProfileInfoDetailsResDto;
import gg.agenda.api.user.agendaprofile.service.AgendaProfileFindService;
import gg.agenda.api.user.agendaprofile.service.AgendaProfileService;
import gg.auth.UserDto;
import gg.auth.argumentresolver.Login;
import gg.data.user.type.RoleType;
import gg.repo.user.UserRepository;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;

Expand All @@ -27,6 +30,7 @@
public class AgendaProfileController {
private final AgendaProfileFindService agendaProfileFindService;
private final AgendaProfileService agendaProfileService;
private final UserRepository userRepository;
private static final Logger log = LoggerFactory.getLogger(AgendaProfileController.class);

/**
Expand All @@ -37,7 +41,8 @@ public class AgendaProfileController {
@GetMapping
public ResponseEntity<AgendaProfileDetailsResDto> myAgendaProfileDetails(
@Login @Parameter(hidden = true) UserDto user) {
AgendaProfileDetailsResDto agendaProfileDetails = agendaProfileFindService.detailsAgendaProfile(user.getId());
AgendaProfileDetailsResDto agendaProfileDetails = agendaProfileFindService.detailsAgendaProfile(
user.getIntraId());
return ResponseEntity.status(HttpStatus.OK).body(agendaProfileDetails);
}

Expand All @@ -53,5 +58,35 @@ public ResponseEntity<Void> agendaProfileModify(@Login @Parameter(hidden = true)
agendaProfileService.modifyAgendaProfile(user.getId(), reqDto);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

/**
* AgendaProfile 상세 조회 API
* @param user 로그인한 사용자 정보
* @return AgendaProfileDetailsResDto 객체와 HTTP 상태 코드를 포함한 ResponseEntity
*/
@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
// * @return List<CurrentAttendAgendaListResDto> 객체
// */
// @GetMapping("/current/list")
// public ResponseEntity<List<CurrentAttendAgendaListResDto>> getCurrentAttendAgendaList(
// @Login @Parameter(hidden = true) UserDto user) {
//
// List<CurrentAttendAgendaListResDto> currentAttendAgendaList = agendaProfileFindService.findCurrentAttendAgenda(
// user.getId());
// return ResponseEntity.ok(currentAttendAgendaList);
// }
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import gg.data.agenda.AgendaProfile;
import gg.data.agenda.type.Coalition;
import gg.data.agenda.type.Location;
import gg.data.user.User;
import lombok.Getter;
import lombok.NoArgsConstructor;

Expand All @@ -18,8 +17,8 @@ public class AgendaProfileDetailsResDto {
private Location userLocation;
private int ticketCount;

public AgendaProfileDetailsResDto(User user, AgendaProfile entity, int ticketCount) {
this.userIntraId = user.getIntraId();
public AgendaProfileDetailsResDto(String intraId, AgendaProfile entity, int ticketCount) {
this.userIntraId = intraId;
this.userContent = entity.getContent();
this.userGithub = entity.getGithubUrl();
this.userCoalition = entity.getCoalition();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package gg.agenda.api.user.agendaprofile.controller.response;

import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class AgendaProfileInfoDetailsResDto {
private String intraId;
private Boolean isAdmin;

public AgendaProfileInfoDetailsResDto(String intraId, Boolean isAdmin) {
this.intraId = intraId;
this.isAdmin = isAdmin;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import gg.agenda.api.user.agendaprofile.controller.response.AgendaProfileDetailsResDto;
import gg.data.agenda.AgendaProfile;
import gg.data.user.User;
import gg.repo.agenda.AgendaProfileRepository;
import gg.repo.agenda.AgendaTeamProfileRepository;
import gg.repo.agenda.AgendaTeamRepository;
import gg.repo.agenda.TicketRepository;
import gg.repo.user.UserRepository;
import gg.utils.exception.custom.NotExistException;
Expand All @@ -21,22 +22,50 @@ public class AgendaProfileFindService {
private final UserRepository userRepository;
private final AgendaProfileRepository agendaProfileRepository;
private final TicketRepository ticketRepository;
private final AgendaTeamProfileRepository agendaTeamProfileRepository;
private final AgendaTeamRepository agendaTeamRepository;

/**
* AgendaProfile 상세 정보를 조회하는 메서드
* @param userId 로그인한 유저의 id
* @param intraId 로그인한 유저의 id
* @return AgendaProfileDetailsResDto 객체
*/
@Transactional(readOnly = true)
public AgendaProfileDetailsResDto detailsAgendaProfile(Long userId) {
User loginUser = userRepository.getById(userId);

AgendaProfile agendaProfile = agendaProfileRepository.findByUserId(loginUser.getId())
public AgendaProfileDetailsResDto detailsAgendaProfile(String intraId) {
AgendaProfile agendaProfile = agendaProfileRepository.findByIntraId(intraId)
.orElseThrow(() -> new NotExistException(AGENDA_PROFILE_NOT_FOUND));

int ticketCount = ticketRepository.findByAgendaProfileIdAndIsUsedFalseAndIsApprovedTrue(agendaProfile.getId())
.size();

return new AgendaProfileDetailsResDto(loginUser, agendaProfile, ticketCount);
return new AgendaProfileDetailsResDto(intraId, agendaProfile, ticketCount);
}

// /**
// * 자기가 참여중인 Agenda 목록 조회하는 메서드
// * @param userId 로그인한 유저의 id
// * @return AgendaProfileDetailsResDto 객체
// */
// @Transactional(readOnly = true)
// public List<CurrentAttendAgendaListResDto> findCurrentAttendAgenda(Long userId) {
// User loginUser = userRepository.getById(userId);
//
// AgendaProfile agendaProfile = agendaProfileRepository.findByUserId(loginUser.getId())
// .orElseThrow(() -> new NotExistException(AGENDA_PROFILE_NOT_FOUND));
//
// List<AgendaTeamProfile> agendaTeamProfiles = agendaTeamProfileRepository.findByUserId(loginUser.getId());
//
// if (agendaTeamProfiles.isEmpty()) {
// throw new NotExistException(AGENDA_PROFILE_NOT_FOUND);
// }
//
// return agendaTeamProfiles.stream()
// .filter(agendaTeamProfile -> agendaTeamProfile.getAgenda().getStatus() == AgendaStatus.ON_GOING)
// .map(agendaTeamProfile -> {
// AgendaTeam agendaTeam = agendaTeamRepository.findById(agendaTeamProfile.getId())
// .orElseThrow(() -> new NotExistException(AGENDA_TEAM_NOT_FOUND));
// return new CurrentAttendAgendaListResDto(agendaTeamProfile, agendaTeam);
// })
// .collect(Collectors.toList());
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import gg.agenda.api.AgendaMockData;
import gg.agenda.api.user.agendaprofile.controller.request.AgendaProfileChangeReqDto;
import gg.agenda.api.user.agendaprofile.controller.response.AgendaProfileDetailsResDto;
import gg.agenda.api.user.agendaprofile.controller.response.AgendaProfileInfoDetailsResDto;
import gg.data.agenda.AgendaProfile;
import gg.data.user.User;
import gg.data.user.type.RoleType;
import gg.repo.agenda.AgendaProfileRepository;
import gg.utils.TestDataUtils;
import gg.utils.annotation.IntegrationTest;
Expand Down Expand Up @@ -200,5 +202,33 @@ void testAgendaProfileNotFound() throws Exception {
.andExpect(status().isNotFound());
}
}

@Nested
@DisplayName("개인 프로필 admin 여부 조회")
class GetAgendaProfileInfo {

@BeforeEach
void beforeEach() {
user = testDataUtils.createNewUser();
accessToken = testDataUtils.getLoginAccessTokenFromUser(user);
}

@Test
@DisplayName("로그인된 유저에 해당하는 Admin 여부를 조회합니다.")
void test() throws Exception {
//given
// when
String response = mockMvc.perform(get("/agenda/profile/info")
.header("Authorization", "Bearer " + accessToken))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString();
AgendaProfileInfoDetailsResDto result = objectMapper.readValue(response,
AgendaProfileInfoDetailsResDto.class);
// then
Boolean isAdmin = user.getRoleType() == RoleType.ADMIN;
assertThat(result.getIntraId()).isEqualTo(user.getIntraId());
assertThat(result.getIsAdmin()).isEqualTo(isAdmin);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@

public interface AgendaProfileRepository extends JpaRepository<AgendaProfile, Long> {
Optional<AgendaProfile> findByUserId(Long userId);

Optional<AgendaProfile> findByIntraId(String intraId);
}

0 comments on commit 7252f83

Please sign in to comment.