Skip to content

Commit

Permalink
fix: fix the sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
JIUNG9 committed Jan 18, 2024
1 parent be31357 commit c54e6c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import com.bit.lotte.flower.user.admin.dto.StoreManagerApplicationData;
import com.bit.lotte.flower.user.admin.dto.response.StoreManagerApplicationFormResponse;
import com.bit.lotte.flower.user.store.entity.StoreManager;
import com.bit.lotte.flower.user.store.repository.StoreManagerJpaRepository;
import com.bit.lotte.flower.user.store.service.FindStoreMangerService;
import java.util.ArrayList;
import java.util.List;
import javax.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;

Expand All @@ -18,6 +21,7 @@ public class GetStoreManagerApplicationService {

private final FindStoreMangerService findStoreMangerService;


@Transactional
public StoreManagerApplicationFormResponse getApplications(List<Long> storeManagerIdList,
Pageable pageable) {
Expand All @@ -27,10 +31,21 @@ public StoreManagerApplicationFormResponse getApplications(List<Long> storeManag
for (Long id : storeManagerIdList) {
storeManagerListByStatus.add(findStoreMangerService.findByLongId(id));
}
List < StoreManagerApplicationData > data = mapToData(storeManagerListByStatus);
List<StoreManagerApplicationData> data = mapToData(storeManagerListByStatus);
Page<StoreManagerApplicationData> dataByPage = getPageOfData(data, pageable);
return StoreManagerApplicationFormResponse.builder()
.data(dataByPage.getContent()).totalCnt(data.size()).build();
}

return StoreManagerApplicationFormResponse.builder().data(data).totalCnt(data.size()).build();
private Page<StoreManagerApplicationData> getPageOfData(List<StoreManagerApplicationData> data,
Pageable pageable) {
int pageSize = pageable.getPageSize();
int pageNumber = pageable.getPageNumber();
int fromIndex = pageNumber * pageSize;
int toIndex = Math.min(fromIndex + pageSize, data.size());

List<StoreManagerApplicationData> pageData = data.subList(fromIndex, toIndex);
return new PageImpl<>(pageData, pageable, data.size());
}

public List<StoreManagerApplicationData> mapToData(List<StoreManager> managerList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class FindStoreMangerService {

private final StoreManagerJpaRepository repository;


public StoreManager findByLongId(Long id) {
return repository.findById(id).orElseThrow(() -> {
throw new StoreUserDomainException("존재하지 않는 스토어 매니저입니다.");
Expand Down

0 comments on commit c54e6c8

Please sign in to comment.