Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
Expand Up @@ -5,13 +5,15 @@
import com.bamdoliro.maru.domain.form.domain.type.FormType;
import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository;
import com.bamdoliro.maru.presentation.form.dto.response.FormSimpleResponse;
import com.bamdoliro.maru.presentation.form.dto.response.PageResult;
import com.bamdoliro.maru.shared.annotation.UseCase;
import lombok.RequiredArgsConstructor;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
Comment thread
somonox marked this conversation as resolved.
Outdated

@RequiredArgsConstructor
@UseCase
Expand Down Expand Up @@ -41,4 +43,20 @@ public List<FormSimpleResponse> execute(FormStatus status, FormType type, String
.map(FormSimpleResponse::new)
.toList();
}

// 하위 호환성을 유지해야하므로 execute 함수를 오버로드
public PageResult<FormSimpleResponse> execute(FormStatus status, FormType type, String sort, int page, int size) {
Comment thread
somonox marked this conversation as resolved.
Outdated
List<FormSimpleResponse> allForms = this.execute(status, type, sort);

long totalCount = allForms.size();
long totalPages = (long) Math.ceil((double) totalCount / size);

int skip = (page - 1) * size;
List<FormSimpleResponse> pagedData = allForms.stream()
.skip(skip)
.limit(size)
.toList();

return new PageResult<>(pagedData, totalCount, totalPages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.bamdoliro.maru.presentation.form.dto.response.AdmissionAndPledgeUrlResponse;
import com.bamdoliro.maru.presentation.form.dto.response.FormSimpleResponse;
import com.bamdoliro.maru.presentation.form.dto.response.FormUrlResponse;
import com.bamdoliro.maru.presentation.form.dto.response.PageResult;
import com.bamdoliro.maru.shared.auth.AuthenticationPrincipal;
import com.bamdoliro.maru.shared.auth.Authority;
import com.bamdoliro.maru.shared.response.CommonResponse;
Expand Down Expand Up @@ -87,15 +88,29 @@
}

@GetMapping
public ListCommonResponse<FormSimpleResponse> getFormList(
public ResponseEntity<ListCommonResponse<FormSimpleResponse>> getFormList(
Comment thread
somonox marked this conversation as resolved.
Outdated
@AuthenticationPrincipal(authority = Authority.ADMIN) User user,
@RequestParam(name = "status", required = false) FormStatus status,
@RequestParam(name = "type", required = false) FormType type,
@RequestParam(name = "sort", required = false) String sort
@RequestParam(name = "sort", required = false) String sort,
Comment thread
somonox marked this conversation as resolved.
@RequestParam(name = "page", required = false) Integer page,
@RequestParam(name = "size", required = false) Integer size
Comment thread
somonox marked this conversation as resolved.
) {
return ListCommonResponse.ok(
queryAllFormUseCase.execute(status, type, sort)
);
if (page == null && size == null) {
return ResponseEntity.ok(
ListCommonResponse.ok(queryAllFormUseCase.execute(status, type, sort))

Check failure on line 101 in src/main/java/com/bamdoliro/maru/presentation/form/AdminFormController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use static access with "com.bamdoliro.maru.shared.response.CommonResponse" for "ok".

See more on https://sonarcloud.io/project/issues?id=Bamdoliro_marubase&issues=AZ38FruFKvkQ6ozvZvJr&open=AZ38FruFKvkQ6ozvZvJr&pullRequest=390
);
}

int pageNumber = (page != null) ? page : 1;
Comment thread
somonox marked this conversation as resolved.
Outdated
int pageSize = (size != null) ? size : 10;

PageResult<FormSimpleResponse> result = queryAllFormUseCase.execute(status, type, sort, pageNumber, pageSize);

return ResponseEntity.ok()
.header("X-Total-Count", String.valueOf(result.getTotalCount()))
.header("X-Total-Pages", String.valueOf(result.getTotalPages()))
.body(ListCommonResponse.ok(result.getData()));

Check failure on line 113 in src/main/java/com/bamdoliro/maru/presentation/form/AdminFormController.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use static access with "com.bamdoliro.maru.shared.response.CommonResponse" for "ok".

See more on https://sonarcloud.io/project/issues?id=Bamdoliro_marubase&issues=AZ38FruFKvkQ6ozvZvJs&open=AZ38FruFKvkQ6ozvZvJs&pullRequest=390
}

@GetMapping("/admission-tickets")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.bamdoliro.maru.presentation.form.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;

@Getter
@AllArgsConstructor
public class PageResult<T> {
List<T> data;
long totalCount;
long totalPages;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.bamdoliro.maru.domain.form.domain.type.FormType;
import com.bamdoliro.maru.infrastructure.persistence.form.FormRepository;
import com.bamdoliro.maru.presentation.form.dto.response.FormSimpleResponse;
import com.bamdoliro.maru.presentation.form.dto.response.PageResult;
import com.bamdoliro.maru.shared.fixture.FormFixture;
import com.bamdoliro.maru.shared.util.RandomUtil;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -53,6 +54,31 @@ class QueryAllFormUseCaseTest {
verify(formRepository, times(1)).findByStatus(null);
}

@Test
void 일부_원서만_조회한다() {
// given
List<Form> formList = List.of(
FormFixture.createForm(FormType.REGULAR),
FormFixture.createForm(FormType.SPECIAL_ADMISSION),
FormFixture.createForm(FormType.MEISTER_TALENT),
FormFixture.createForm(FormType.MULTI_CHILDREN)
);

formList.forEach(form -> form.assignExaminationNumber(1001L));

given(formRepository.findByStatus(null)).willReturn(formList);

// when
PageResult<FormSimpleResponse> returnedFormList = queryAllFormUseCase.execute(null, null,null, 1, 2);

// then
assertEquals(2, returnedFormList.getTotalPages());
assertEquals(2, returnedFormList.getData().size());
assertEquals(FormType.REGULAR, returnedFormList.getData().get(0).getType());

verify(formRepository, times(1)).findByStatus(null);
}

@Test
void 특별전형_원서만_조회한다() {
// given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.bamdoliro.maru.domain.user.domain.User;
import com.bamdoliro.maru.presentation.form.dto.request.PassOrFailFormListRequest;
import com.bamdoliro.maru.presentation.form.dto.request.PassOrFailFormRequest;
import com.bamdoliro.maru.presentation.form.dto.response.FormSimpleResponse;
import com.bamdoliro.maru.presentation.form.dto.response.PageResult;
import com.bamdoliro.maru.shared.fixture.AuthFixture;
import com.bamdoliro.maru.shared.fixture.FormFixture;
import com.bamdoliro.maru.shared.fixture.UserFixture;
Expand All @@ -27,10 +29,13 @@
import static org.mockito.BDDMockito.*;
import static org.springframework.restdocs.cookies.CookieDocumentation.cookieWithName;
import static org.springframework.restdocs.cookies.CookieDocumentation.requestCookies;
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
import static org.springframework.restdocs.headers.HeaderDocumentation.responseHeaders;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.restdocs.request.RequestDocumentation.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

class AdminFormControllerTest extends RestDocsTestSupport {
Expand Down Expand Up @@ -247,6 +252,56 @@ class AdminFormControllerTest extends RestDocsTestSupport {
verify(queryAllFormUseCase, times(1)).execute(FormStatus.SUBMITTED, FormType.REGULAR, null);
}

@Test
void 원서를_일부만_조회한다() throws Exception {
User user = UserFixture.createAdminUser();

given(authenticationArgumentResolver.supportsParameter(any(MethodParameter.class))).willReturn(true);
given(authenticationArgumentResolver.resolveArgument(any(), any(), any(), any())).willReturn(user);

given(queryAllFormUseCase.execute(FormStatus.SUBMITTED, FormType.REGULAR, null, 1, 2))
.willReturn(new PageResult<>(
List.of(
FormFixture.createFormSimpleResponse(FormStatus.SUBMITTED),
FormFixture.createFormSimpleResponse(FormStatus.SUBMITTED)
),
5L,
3L
));

mockMvc.perform(get("/admin/forms")
.param("status", FormStatus.SUBMITTED.name())
.param("type", FormType.REGULAR.name())
.param("page", "1")
.param("size", "2")
.cookie(AuthFixture.createAuthCookie())
.accept(MediaType.APPLICATION_JSON)
)
.andExpect(status().isOk())
.andExpect(header().exists("X-Total-Count"))
.andExpect(header().exists("X-Total-Pages"))
.andDo(restDocs.document(
responseHeaders(
headerWithName("X-Total-Count").description("필터링된 전체 원서의 개수"),
headerWithName("X-Total-Pages").description("전체 페이지 수")
),
requestCookies(
cookieWithName("accessToken")
.description("이것은.액세스.토큰")
),
queryParameters(
parameterWithName("status").description("<<form-status,원서 상태 (null인 경우 전체 조회)>>").optional(),
parameterWithName("type").description("<<form-category,원서 카테고리 (null인 경우 전체 조회)>>").optional(),
parameterWithName("sort").description("정렬 기준").optional(),
parameterWithName("page").description("조회할 페이지 번호 (size, page둘다 null인 경우 전체 조회, size가 null 아니라면 1)").optional(),
parameterWithName("size").description("페이지당 데이터 개수 (size, page둘다 null인 경우 전체 조회, page가 null 아니라면 10)").optional()
)
));

// 오버로딩된 페이징 메서드가 정확히 호출되었는지 검증합니다.
verify(queryAllFormUseCase, times(1)).execute(FormStatus.SUBMITTED, FormType.REGULAR, null, 1, 2);
}

@Test
void 수험표_전체를_발급받는다() throws Exception {
User user = UserFixture.createAdminUser();
Expand Down
Loading