Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [Feature] Admin AgendaTeam 상세 조회하기 #901 #919

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gg.admin.repo.agenda;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -19,4 +21,7 @@ public interface AgendaTeamAdminRepository extends JpaRepository<AgendaTeam, Lon

@Query("SELECT at FROM AgendaTeam at WHERE at.agenda = :agenda")
Page<AgendaTeam> findAllByAgenda(Agenda agenda, Pageable pageable);

@Query("SELECT at FROM AgendaTeam at WHERE at.teamKey = :teamKey")
Optional<AgendaTeam> findByTeamKey(UUID teamKey);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package gg.admin.repo.agenda;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import gg.data.agenda.AgendaTeam;
import gg.data.agenda.AgendaTeamProfile;

@Repository
public interface AgendaTeamProfileAdminRepository extends JpaRepository<AgendaTeamProfile, Long> {

List<AgendaTeamProfile> findAllByAgendaTeamAndIsExistIsTrue(AgendaTeam agendaTeam);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import gg.agenda.api.admin.agendateam.controller.request.AgendaTeamKeyReqDto;
import gg.agenda.api.admin.agendateam.controller.response.AgendaTeamDetailResDto;
import gg.agenda.api.admin.agendateam.controller.response.AgendaTeamResDto;
import gg.agenda.api.admin.agendateam.service.AgendaTeamAdminService;
import gg.data.agenda.AgendaProfile;
import gg.data.agenda.AgendaTeam;
import gg.utils.dto.PageRequestDto;
import lombok.RequiredArgsConstructor;
Expand All @@ -41,4 +44,14 @@ public ResponseEntity<List<AgendaTeamResDto>> getAgendaTeamList(@RequestParam("a
.collect(Collectors.toList());
return ResponseEntity.ok(agendaTeamResDtoList);
}

@GetMapping
public ResponseEntity<AgendaTeamDetailResDto> getAgendaTeamDetail(
@RequestBody @Valid AgendaTeamKeyReqDto agendaTeamKeyReqDto) {
AgendaTeam agendaTeam = agendaTeamAdminService.getAgendaTeamByTeamKey(agendaTeamKeyReqDto.getTeamKey());
List<AgendaProfile> participants = agendaTeamAdminService.getAgendaProfileListByAgendaTeam(agendaTeam);
AgendaTeamDetailResDto agendaTeamDetailResDto = AgendaTeamDetailResDto.MapStruct.INSTANCE
.toDto(agendaTeam, participants);
return ResponseEntity.ok(agendaTeamDetailResDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package gg.agenda.api.admin.agendateam.controller.request;

import java.util.UUID;

import javax.validation.constraints.NotNull;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class AgendaTeamKeyReqDto {

@NotNull
private UUID teamKey;

@Builder
public AgendaTeamKeyReqDto(UUID teamKey) {
this.teamKey = teamKey;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package gg.agenda.api.admin.agendateam.controller.response;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import gg.data.agenda.AgendaProfile;
import gg.data.agenda.type.Coalition;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class AgendaProfileResDto {

private String intraId;

private Coalition coalition;

@Builder
public AgendaProfileResDto(String intraId, Coalition coalition) {
this.intraId = intraId;
this.coalition = coalition;
}

@Mapper
public interface MapStruct {

AgendaProfileResDto.MapStruct INSTANCE = Mappers.getMapper(AgendaProfileResDto.MapStruct.class);

@Mapping(target = "intraId", source = "intraId")
@Mapping(target = "coalition", source = "coalition")
AgendaProfileResDto toDto(AgendaProfile profile);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package gg.agenda.api.admin.agendateam.controller.response;

import java.util.List;
import java.util.stream.Collectors;

import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import gg.data.agenda.AgendaProfile;
import gg.data.agenda.AgendaTeam;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class AgendaTeamDetailResDto {

private String teamName;

private String teamLeaderIntraId;

private String teamStatus;

private String teamAward;

private int teamAwardPriority;

private boolean teamIsPrivate;

private List<AgendaProfileResDto> teamMates;

@Builder
public AgendaTeamDetailResDto(String teamName, String teamLeaderIntraId, String teamStatus, String teamAward,
int teamAwardPriority, boolean teamIsPrivate, List<AgendaProfileResDto> teamMates) {
this.teamName = teamName;
this.teamLeaderIntraId = teamLeaderIntraId;
this.teamStatus = teamStatus;
this.teamAward = teamAward;
this.teamAwardPriority = teamAwardPriority;
this.teamIsPrivate = teamIsPrivate;
this.teamMates = teamMates;
}

@Mapper
public interface MapStruct {

AgendaTeamDetailResDto.MapStruct INSTANCE = Mappers.getMapper(AgendaTeamDetailResDto.MapStruct.class);

@Mapping(target = "teamName", source = "team.name")
@Mapping(target = "teamLeaderIntraId", source = "team.leaderIntraId")
@Mapping(target = "teamStatus", source = "team.status")
@Mapping(target = "teamAward", source = "team.award")
@Mapping(target = "teamAwardPriority", source = "team.awardPriority")
@Mapping(target = "teamIsPrivate", source = "team.isPrivate")
@Mapping(target = "teamMates", source = "teamMates", qualifiedByName = "toAgendaProfileResDtoList")
AgendaTeamDetailResDto toDto(AgendaTeam team, List<AgendaProfile> teamMates);

@Named("toAgendaProfileResDtoList")
default List<AgendaProfileResDto> toAgendaProfileResDtoList(List<AgendaProfile> teamMates) {
return teamMates.stream()
.map(AgendaProfileResDto.MapStruct.INSTANCE::toDto)
.collect(Collectors.toList());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@

import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import gg.admin.repo.agenda.AgendaAdminRepository;
import gg.admin.repo.agenda.AgendaTeamAdminRepository;
import gg.admin.repo.agenda.AgendaTeamProfileAdminRepository;
import gg.data.agenda.Agenda;
import gg.data.agenda.AgendaProfile;
import gg.data.agenda.AgendaTeam;
import gg.data.agenda.AgendaTeamProfile;
import gg.utils.exception.custom.NotExistException;
import lombok.RequiredArgsConstructor;

Expand All @@ -23,9 +28,24 @@ public class AgendaTeamAdminService {

private final AgendaTeamAdminRepository agendaTeamAdminRepository;

private final AgendaTeamProfileAdminRepository agendaTeamProfileAdminRepository;

@Transactional(readOnly = true)
public List<AgendaTeam> getAgendaTeamList(UUID agendaKey, Pageable pageable) {
Agenda agenda = agendaAdminRepository.findByAgendaKey(agendaKey)
.orElseThrow(() -> new NotExistException(AGENDA_NOT_FOUND));
return agendaTeamAdminRepository.findAllByAgenda(agenda, pageable).getContent();
}

@Transactional(readOnly = true)
public AgendaTeam getAgendaTeamByTeamKey(UUID teamKey) {
return agendaTeamAdminRepository.findByTeamKey(teamKey)
.orElseThrow(() -> new NotExistException(AGENDA_TEAM_NOT_FOUND));
}

@Transactional(readOnly = true)
public List<AgendaProfile> getAgendaProfileListByAgendaTeam(AgendaTeam agendaTeam) {
return agendaTeamProfileAdminRepository.findAllByAgendaTeamAndIsExistIsTrue(agendaTeam).stream()
.map(AgendaTeamProfile::getProfile).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@

import gg.admin.repo.agenda.AgendaAdminRepository;
import gg.admin.repo.agenda.AgendaTeamAdminRepository;
import gg.agenda.api.admin.agendateam.controller.request.AgendaTeamKeyReqDto;
import gg.agenda.api.admin.agendateam.controller.response.AgendaProfileResDto;
import gg.agenda.api.admin.agendateam.controller.response.AgendaTeamDetailResDto;
import gg.agenda.api.admin.agendateam.controller.response.AgendaTeamResDto;
import gg.data.agenda.Agenda;
import gg.data.agenda.AgendaProfile;
import gg.data.agenda.AgendaTeam;
import gg.data.agenda.type.AgendaTeamStatus;
import gg.data.user.User;
Expand All @@ -35,7 +39,9 @@
import gg.utils.annotation.IntegrationTest;
import gg.utils.dto.PageRequestDto;
import gg.utils.fixture.agenda.AgendaFixture;
import gg.utils.fixture.agenda.AgendaProfileFixture;
import gg.utils.fixture.agenda.AgendaTeamFixture;
import gg.utils.fixture.agenda.AgendaTeamProfileFixture;

@IntegrationTest
@Transactional
Expand All @@ -57,6 +63,12 @@ public class AgendaTeamAdminControllerTest {
@Autowired
private AgendaTeamFixture agendaTeamFixture;

@Autowired
private AgendaProfileFixture agendaProfileFixture;

@Autowired
private AgendaTeamProfileFixture agendaTeamProfileFixture;

@Autowired
private AgendaTestDataUtils agendaTestDataUtils;

Expand Down Expand Up @@ -131,4 +143,85 @@ void getAgendaTeamListAdminFailedWithNoAgenda() throws Exception {
.andExpect(status().isNotFound());
}
}

@Nested
@DisplayName("Admin AgendaTeam 상세 조회")
class GetAgendaTeamDetailAdmin {
@Test
@DisplayName("Admin AgendaTeam 상세 조회 성공")
void getAgendaTeamDetailAdminSuccess() throws Exception {
// given
Agenda agenda = agendaFixture.createAgenda();
AgendaTeam team = agendaTeamFixture.createAgendaTeam(agenda);
List<AgendaProfile> profiles = agendaProfileFixture.createAgendaProfileList(10);
profiles.forEach(profile -> agendaTeamProfileFixture
.createAgendaTeamProfile(agenda, team, profile));
String request = objectMapper.writeValueAsString(new AgendaTeamKeyReqDto(team.getTeamKey()));

// when
String response = mockMvc.perform(get("/admin/agenda/team")
.header("Authorization", "Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON)
.content(request))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
AgendaTeamDetailResDto result = objectMapper.readValue(response, AgendaTeamDetailResDto.class);

// then
assertThat(result).isNotNull();
assertThat(result.getTeamName()).isEqualTo(team.getName());
assertThat(result.getTeamMates()).isNotNull();
assertThat(result.getTeamMates().size()).isEqualTo(profiles.size());
for (int i = 0; i < profiles.size(); i++) {
AgendaProfileResDto profile = result.getTeamMates().get(i);
assertThat(profile.getIntraId()).isEqualTo(profiles.get(i).getIntraId());
}
}

@Test
@DisplayName("Admin AgendaTeam 상세 조회 실패 - Team Key 없음")
void getAgendaTeamDetailAdminFailedWithNoTeamKey() throws Exception {
// given
// expected
mockMvc.perform(get("/admin/agenda/team")
.header("Authorization", "Bearer " + accessToken))
.andExpect(status().isBadRequest());
}

@Test
@DisplayName("Admin AgendaTeam 상세 조회 실패 - 존재하지 않는 Team")
void getAgendaTeamDetailAdminFailedWithNotFoundTeam() throws Exception {
// given
String request = objectMapper.writeValueAsString(new AgendaTeamKeyReqDto(UUID.randomUUID()));

// expected
mockMvc.perform(get("/admin/agenda/team")
.header("Authorization", "Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON)
.content(request))
.andExpect(status().isNotFound());
}

@Test
@DisplayName("Admin AgendaTeam 상세 조회 성공 - teamMate 없는 경우 빈 리스트")
void getAgendaTeamDetailAdminSuccessWithNoTeamMates() throws Exception {
// given
Agenda agenda = agendaFixture.createAgenda();
AgendaTeam team = agendaTeamFixture.createAgendaTeam(agenda);
String request = objectMapper.writeValueAsString(new AgendaTeamKeyReqDto(team.getTeamKey()));

// when
String response = mockMvc.perform(get("/admin/agenda/team")
.header("Authorization", "Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON)
.content(request))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
AgendaTeamDetailResDto result = objectMapper.readValue(response, AgendaTeamDetailResDto.class);

// then
assertThat(result).isNotNull();
assertThat(result.getTeamName()).isEqualTo(team.getName());
assertThat(result.getTeamMates()).isNotNull();
assertThat(result.getTeamMates().size()).isEqualTo(0);
}
}
}
Loading
Loading