Skip to content

Commit

Permalink
๐Ÿ”จ [Refactoring] Agenda Admin ์กฐํšŒ Query Parameter ๋ณ€๊ฒฝ #948 (#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
yhames authored Aug 12, 2024
1 parent 1f65e80 commit 2fd2968
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -41,7 +40,7 @@ public class AgendaAdminController {

@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Agenda ์š”์ฒญ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ ์„ฑ๊ณต")})
@GetMapping("/request/list")
public ResponseEntity<List<AgendaAdminResDto>> agendaList(@RequestBody @Valid PageRequestDto pageDto) {
public ResponseEntity<List<AgendaAdminResDto>> agendaList(@ModelAttribute @Valid PageRequestDto pageDto) {
int page = pageDto.getPage();
int size = pageDto.getSize();
Pageable pageable = PageRequest.of(page - 1, size, Sort.by("id").descending());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.springframework.data.domain.Sort;
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.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -33,7 +34,7 @@ public class AgendaAnnouncementAdminController {

@GetMapping()
public ResponseEntity<List<AgendaAnnouncementAdminResDto>> agendaAnnouncementList(
@RequestParam("agenda_key") UUID agendaKey, @RequestBody @Valid PageRequestDto pageRequest) {
@RequestParam("agenda_key") UUID agendaKey, @ModelAttribute @Valid PageRequestDto pageRequest) {
int page = pageRequest.getPage();
int size = pageRequest.getSize();
Pageable pageable = PageRequest.of(page - 1, size, Sort.by("id").descending());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import org.springframework.http.HttpStatus;
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.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
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.request.AgendaTeamUpdateDto;
import gg.agenda.api.admin.agendateam.controller.response.AgendaTeamDetailResDto;
import gg.agenda.api.admin.agendateam.controller.response.AgendaTeamResDto;
Expand All @@ -37,7 +37,7 @@ public class AgendaTeamAdminController {

@GetMapping("/list")
public ResponseEntity<List<AgendaTeamResDto>> agendaTeamList(@RequestParam("agenda_key") UUID agendaKey,
@RequestBody @Valid PageRequestDto pageRequestDto) {
@ModelAttribute @Valid PageRequestDto pageRequestDto) {
int page = pageRequestDto.getPage();
int size = pageRequestDto.getSize();
Pageable pageable = PageRequest.of(page - 1, size, Sort.by("id").descending());
Expand All @@ -49,9 +49,8 @@ public ResponseEntity<List<AgendaTeamResDto>> agendaTeamList(@RequestParam("agen
}

@GetMapping
public ResponseEntity<AgendaTeamDetailResDto> agendaTeamDetail(
@RequestBody @Valid AgendaTeamKeyReqDto agendaTeamKeyReqDto) {
AgendaTeam agendaTeam = agendaTeamAdminService.getAgendaTeamByTeamKey(agendaTeamKeyReqDto.getTeamKey());
public ResponseEntity<AgendaTeamDetailResDto> agendaTeamDetail(@RequestParam("team_key") UUID agendaTeamKey) {
AgendaTeam agendaTeam = agendaTeamAdminService.getAgendaTeamByTeamKey(agendaTeamKey);
List<AgendaProfile> participants = agendaTeamAdminService.getAgendaProfileListByAgendaTeam(agendaTeam);
AgendaTeamDetailResDto agendaTeamDetailResDto = AgendaTeamDetailResDto.MapStruct.INSTANCE
.toDto(agendaTeam, participants);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,12 @@ void findAgendaByAgendaKeySuccessAdmin(int page) throws Exception {
agendas.addAll(agendaMockData.createNonOfficialAgendaList(5, AgendaStatus.OPEN));
agendas.addAll(agendaMockData.createNonOfficialAgendaList(5, AgendaStatus.FINISH));
agendas.addAll(agendaMockData.createNonOfficialAgendaList(5, AgendaStatus.CANCEL));
PageRequestDto pageRequestDto = new PageRequestDto(page, size);
String request = objectMapper.writeValueAsString(pageRequestDto);

// when
String response = mockMvc.perform(get("/agenda/admin/request/list")
.header("Authorization", "Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON).content(request))
.param("page", String.valueOf(page))
.param("size", String.valueOf(size)))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
AgendaAdminResDto[] result = objectMapper.readValue(response, AgendaAdminResDto[].class);

Expand All @@ -131,12 +130,12 @@ void findAgendaByAgendaKeySuccessAdminWithNoContent() throws Exception {
int page = 1;
int size = 10;
PageRequestDto pageRequestDto = new PageRequestDto(page, size);
String request = objectMapper.writeValueAsString(pageRequestDto);

// when
String response = mockMvc.perform(get("/agenda/admin/request/list")
.header("Authorization", "Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON).content(request))
.param("page", String.valueOf(page))
.param("size", String.valueOf(size)))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
AgendaAdminResDto[] result = objectMapper.readValue(response, AgendaAdminResDto[].class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,13 @@ void getAgendaAnnouncementAdminSuccess(int page) throws Exception {
Agenda agenda = agendaFixture.createAgenda();
List<AgendaAnnouncement> announcements =
agendaAnnouncementFixture.createAgendaAnnouncementList(agenda, 37);
PageRequestDto pageDto = new PageRequestDto(page, size);
String request = objectMapper.writeValueAsString(pageDto);

// when
String response = mockMvc.perform(get("/agenda/admin/announcement")
.header("Authorization", "Bearer " + accessToken)
.param("agenda_key", agenda.getAgendaKey().toString())
.contentType(MediaType.APPLICATION_JSON)
.content(request))
.param("page", String.valueOf(page))
.param("size", String.valueOf(size)))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
AgendaAnnouncementResDto[] result =
objectMapper.readValue(response, AgendaAnnouncementResDto[].class);
Expand All @@ -121,15 +119,13 @@ void getAgendaAnnouncementAdminSuccessWithNoContent() throws Exception {
int page = 1;
int size = 10;
Agenda agenda = agendaFixture.createAgenda();
PageRequestDto pageDto = new PageRequestDto(page, size);
String request = objectMapper.writeValueAsString(pageDto);

// when
String response = mockMvc.perform(get("/agenda/admin/announcement")
.header("Authorization", "Bearer " + accessToken)
.param("agenda_key", agenda.getAgendaKey().toString())
.contentType(MediaType.APPLICATION_JSON)
.content(request))
.param("page", String.valueOf(page))
.param("size", String.valueOf(size)))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
AgendaAnnouncementResDto[] result =
objectMapper.readValue(response, AgendaAnnouncementResDto[].class);
Expand All @@ -144,15 +140,13 @@ void getAgendaAnnouncementAdminFailedWithNoAgenda() throws Exception {
// given
int page = 1;
int size = 10;
PageRequestDto pageDto = new PageRequestDto(page, size);
String request = objectMapper.writeValueAsString(pageDto);

// expected
mockMvc.perform(get("/agenda/admin/announcement")
.header("Authorization", "Bearer " + accessToken)
.param("agenda_key", UUID.randomUUID().toString())
.contentType(MediaType.APPLICATION_JSON)
.content(request))
.param("page", String.valueOf(page))
.param("size", String.valueOf(size)))
.andExpect(status().isNotFound());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import gg.admin.repo.agenda.AgendaAdminRepository;
import gg.admin.repo.agenda.AgendaTeamAdminRepository;
import gg.admin.repo.agenda.AgendaTeamProfileAdminRepository;
import gg.agenda.api.admin.agendateam.controller.request.AgendaTeamKeyReqDto;
import gg.agenda.api.admin.agendateam.controller.request.AgendaTeamMateReqDto;
import gg.agenda.api.admin.agendateam.controller.request.AgendaTeamUpdateDto;
import gg.agenda.api.admin.agendateam.controller.response.AgendaTeamDetailResDto;
Expand Down Expand Up @@ -114,15 +113,13 @@ void getAgendaTeamListAdminSuccess(int page) throws Exception {
Agenda agenda = agendaFixture.createAgenda(2, 50, 1, 10);
List<AgendaTeam> teams = agendaTeamFixture
.createAgendaTeamList(agenda, AgendaTeamStatus.CONFIRM, total);
PageRequestDto pageRequestDto = new PageRequestDto(page, size);
String request = objectMapper.writeValueAsString(pageRequestDto);

// when
String response = mockMvc.perform(get("/agenda/admin/team/list")
.header("Authorization", "Bearer " + accessToken)
.param("agenda_key", agenda.getAgendaKey().toString())
.contentType(MediaType.APPLICATION_JSON)
.content(request))
.param("page", String.valueOf(page))
.param("size", String.valueOf(size)))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
AgendaTeamResDto[] result = objectMapper.readValue(response, AgendaTeamResDto[].class);

Expand All @@ -140,15 +137,15 @@ void getAgendaTeamListAdminSuccess(int page) throws Exception {
@DisplayName("Admin AgendaTeam ์ „์ฒด ์กฐํšŒ ์‹คํŒจ - Agenda ์—†์Œ")
void getAgendaTeamListAdminFailedWithNoAgenda() throws Exception {
// given
PageRequestDto pageRequestDto = new PageRequestDto(1, 10);
String request = objectMapper.writeValueAsString(pageRequestDto);
int page = 1;
int size = 10;

// expected
mockMvc.perform(get("/agenda/admin/team/list")
.header("Authorization", "Bearer " + accessToken)
.param("agenda_key", UUID.randomUUID().toString())
.contentType(MediaType.APPLICATION_JSON)
.content(request))
.param("page", String.valueOf(page))
.param("size", String.valueOf(size)))
.andExpect(status().isNotFound());
}
}
Expand All @@ -165,13 +162,11 @@ void getAgendaTeamDetailAdminSuccess() throws Exception {
List<AgendaProfile> profiles = agendaProfileFixture.createAgendaProfileList(5);
profiles.forEach(profile -> agendaTeamProfileFixture
.createAgendaTeamProfile(agenda, team, profile));
String request = objectMapper.writeValueAsString(new AgendaTeamKeyReqDto(team.getTeamKey()));

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

Expand Down Expand Up @@ -200,13 +195,10 @@ void getAgendaTeamDetailAdminFailedWithNoTeamKey() throws Exception {
@DisplayName("Admin AgendaTeam ์ƒ์„ธ ์กฐํšŒ ์‹คํŒจ - ์กด์žฌํ•˜์ง€ ์•Š๋Š” Team")
void getAgendaTeamDetailAdminFailedWithNotFoundTeam() throws Exception {
// given
String request = objectMapper.writeValueAsString(new AgendaTeamKeyReqDto(UUID.randomUUID()));

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

Expand All @@ -216,13 +208,11 @@ 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("/agenda/admin/team")
.header("Authorization", "Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON)
.content(request))
.param("team_key", team.getTeamKey().toString()))
.andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
AgendaTeamDetailResDto result = objectMapper.readValue(response, AgendaTeamDetailResDto.class);

Expand Down

0 comments on commit 2fd2968

Please sign in to comment.