Skip to content

Commit

Permalink
#103 - adding pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Pieter Van Eeckhout committed Aug 29, 2023
1 parent fd1cfec commit 4ce3f74
Show file tree
Hide file tree
Showing 22 changed files with 416 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,75 @@
import io.edpn.backend.trade.adapter.persistence.filter.mapper.MybatisPersistenceFindCommodityFilterMapper;
import io.edpn.backend.trade.adapter.persistence.filter.mapper.MybatisPersistenceFindSystemFilterMapper;
import io.edpn.backend.trade.adapter.persistence.filter.mapper.MybatisPersistenceLocateCommodityFilterMapper;
import io.edpn.backend.trade.adapter.persistence.filter.mapper.MybatisPersistencePageFilterMapper;
import io.edpn.backend.trade.application.dto.persistence.filter.mapper.PersistencePageFilterMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration("TradeModuleEntityMapperConfig")
public class PersistenceEntityMapperConfig {

@Bean(name = "tradeValidatedCommodityEntityMapper")
public MybatisValidatedCommodityEntityMapper validatedCommodityEntityMapper() {
return new MybatisValidatedCommodityEntityMapper();
}

@Bean(name = "tradeFindCommodityEntityMapper")
public MybatisPersistenceFindCommodityFilterMapper findCommodityFilterMapper() {
return new MybatisPersistenceFindCommodityFilterMapper();
}

@Bean(name = "tradeLocateCommodityEntityMapper")
public MybatisPersistenceLocateCommodityFilterMapper locateCommodityFilterMapper() {
return new MybatisPersistenceLocateCommodityFilterMapper();
public MybatisPersistenceLocateCommodityFilterMapper locateCommodityFilterMapper(PersistencePageFilterMapper persistencePageFilterMapper) {
return new MybatisPersistenceLocateCommodityFilterMapper(persistencePageFilterMapper);
}

@Bean(name = "tradePersistencePageFilterMapper")
public MybatisPersistencePageFilterMapper persistencePageFilterMapper() {
return new MybatisPersistencePageFilterMapper();
}

@Bean(name = "tradePersistenceFindSystemFilterMapper")
public MybatisPersistenceFindSystemFilterMapper findSystemFilterMapper(){
public MybatisPersistenceFindSystemFilterMapper findSystemFilterMapper() {
return new MybatisPersistenceFindSystemFilterMapper();
}

@Bean(name = "tradeSystemEntityMapper")
public MybatisSystemEntityMapper systemEntityMapper() {
return new MybatisSystemEntityMapper();
}

@Bean(name = "tradeCommodityEntityMapper")
public MybatisCommodityEntityMapper commodityEntityMapper() {
return new MybatisCommodityEntityMapper();
}

@Bean(name = "tradeMarketDatumEntityMapper")
public MybatisMarketDatumEntityMapper marketDatumEntityMapper(
MybatisCommodityEntityMapper mybatisCommodityEntityMapper) {
return new MybatisMarketDatumEntityMapper(mybatisCommodityEntityMapper);
}

@Bean(name = "tradeStationEntityMapper")
public MybatisStationEntityMapper stationEntityMapper(
MybatisSystemEntityMapper mybatisSystemEntityMapper,
MybatisMarketDatumEntityMapper mybatisMarketDatumEntityMapper) {
return new MybatisStationEntityMapper(mybatisSystemEntityMapper, mybatisMarketDatumEntityMapper);
}

@Bean(name = "tradeLocateCommodityFilterMapper")
public MybatisLocateCommodityEntityMapper locateCommodityEntityMapper(
MybatisValidatedCommodityEntityMapper mybatisValidatedCommodityEntityMapper,
MybatisStationEntityMapper mybatisStationEntityMapper) {
return new MybatisLocateCommodityEntityMapper(mybatisValidatedCommodityEntityMapper, mybatisStationEntityMapper);
}

@Bean(name = "tradeCommodityMarketInfoEntityMapper")
public MybatisCommodityMarketInfoEntityMapper commodityMarketInfoEntityMapper(
MybatisValidatedCommodityEntityMapper mybatisValidatedCommodityEntityMapper,
MybatisStationEntityMapper mybatisStationEntityMapper ){
MybatisStationEntityMapper mybatisStationEntityMapper) {
return new MybatisCommodityMarketInfoEntityMapper(mybatisValidatedCommodityEntityMapper, mybatisStationEntityMapper);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import io.edpn.backend.trade.adapter.web.dto.filter.mapper.RestFindCommodityFilterDtoMapper;
import io.edpn.backend.trade.adapter.web.dto.filter.mapper.RestLocateCommodityFilterDtoMapper;
import io.edpn.backend.trade.adapter.web.dto.filter.mapper.RestPageFilterDtoMapper;
import io.edpn.backend.trade.adapter.web.dto.object.mapper.RestCommodityMarketInfoDtoMapper;
import io.edpn.backend.trade.adapter.web.dto.object.mapper.RestLocateCommodityDtoMapper;
import io.edpn.backend.trade.adapter.web.dto.object.mapper.RestStationDtoMapper;
import io.edpn.backend.trade.adapter.web.dto.object.mapper.RestSystemDtoMapper;
import io.edpn.backend.trade.adapter.web.dto.object.mapper.RestValidatedCommodityDtoMapper;
import io.edpn.backend.trade.application.dto.web.filter.mapper.FindCommodityFilterDtoMapper;
import io.edpn.backend.trade.application.dto.web.filter.mapper.LocateCommodityFilterDtoMapper;
import io.edpn.backend.trade.application.dto.web.filter.mapper.PageFilterDtoMapper;
import io.edpn.backend.trade.application.dto.web.object.mapper.CommodityMarketInfoDtoMapper;
import io.edpn.backend.trade.application.dto.web.object.mapper.LocateCommodityDtoMapper;
import io.edpn.backend.trade.application.dto.web.object.mapper.StationDtoMapper;
Expand All @@ -19,44 +21,49 @@

@Configuration("TradeWebDtoMapperConfig")
public class WebDtoMapperConfig {

@Bean(name = "tradeFindCommodityDTOMapper")
public FindCommodityFilterDtoMapper findCommodityDTOMapper() {
return new RestFindCommodityFilterDtoMapper();
}

@Bean(name = "tradeValidatedCommodityDTOMapper")
public ValidatedCommodityDtoMapper validatedCommodityDTOMapper() {
return new RestValidatedCommodityDtoMapper();
}

@Bean(name = "tradeSystemDtoMapper")
public SystemDtoMapper systemDtoMapper() {
return new RestSystemDtoMapper();
}

@Bean(name = "tradeStationDtoMapper")
public StationDtoMapper stationDtoMapper(
SystemDtoMapper systemDtoMapper){
SystemDtoMapper systemDtoMapper) {
return new RestStationDtoMapper(systemDtoMapper);
}

@Bean(name = "tradeLocateCommodityDtoMapper")
public LocateCommodityDtoMapper locateCommodityDtoMapper(
StationDtoMapper stationDtoMapper,
ValidatedCommodityDtoMapper validatedCommodityDtoMapper) {
return new RestLocateCommodityDtoMapper(stationDtoMapper, validatedCommodityDtoMapper);
}

@Bean(name = "tradeCommodityMarketInfoDtoMapper")
public CommodityMarketInfoDtoMapper commodityMarketInfoDtoMapper(
ValidatedCommodityDtoMapper validatedCommodityDtoMapper,
StationDtoMapper stationDtoMapper) {
return new RestCommodityMarketInfoDtoMapper(validatedCommodityDtoMapper, stationDtoMapper);
}

@Bean(name = "tradeLocateCommodityFilterDtoMapper")
public LocateCommodityFilterDtoMapper locateCommodityFilterDtoMapper() {
return new RestLocateCommodityFilterDtoMapper();
public LocateCommodityFilterDtoMapper locateCommodityFilterDtoMapper(PageFilterDtoMapper pageFilterDtoMapper) {
return new RestLocateCommodityFilterDtoMapper(pageFilterDtoMapper);
}

@Bean(name = "tradePageFilterDtoMapper")
public PageFilterDtoMapper pageFilterDtoMapper() {
return new RestPageFilterDtoMapper();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.edpn.backend.trade.adapter.persistence.filter;

import io.edpn.backend.trade.application.dto.persistence.filter.PersistenceLocateCommodityFilter;
import io.edpn.backend.trade.application.dto.persistence.filter.PersistencePageFilter;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -28,4 +29,5 @@ public class MybatisLocateCommodityFilter implements PersistenceLocateCommodityF
private String maxLandingPadSize;
private Long minSupply;
private Long minDemand;
private PersistencePageFilter page;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.edpn.backend.trade.adapter.persistence.filter;

import io.edpn.backend.trade.application.dto.persistence.filter.PersistencePageFilter;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode
public class MybatisPageFilter implements PersistencePageFilter {
private int size;
private int page;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
import io.edpn.backend.trade.adapter.persistence.filter.MybatisLocateCommodityFilter;
import io.edpn.backend.trade.application.domain.filter.LocateCommodityFilter;
import io.edpn.backend.trade.application.dto.persistence.filter.mapper.PersistenceLocateCommodityFilterMapper;
import io.edpn.backend.trade.application.dto.persistence.filter.mapper.PersistencePageFilterMapper;
import lombok.RequiredArgsConstructor;

import java.util.Optional;

@RequiredArgsConstructor
public class MybatisPersistenceLocateCommodityFilterMapper implements PersistenceLocateCommodityFilterMapper {

private final PersistencePageFilterMapper pageFilterMapper;

@Override
public MybatisLocateCommodityFilter map(LocateCommodityFilter locateCommodityFilter) {
return MybatisLocateCommodityFilter.builder()
Expand All @@ -19,6 +25,7 @@ public MybatisLocateCommodityFilter map(LocateCommodityFilter locateCommodityFil
.maxLandingPadSize(String.valueOf(locateCommodityFilter.getMaxLandingPadSize()))
.minSupply(locateCommodityFilter.getMinSupply())
.minDemand(locateCommodityFilter.getMinDemand())
.page(Optional.ofNullable(locateCommodityFilter.getPageFilter()).map(pageFilterMapper::map).orElse(null))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.edpn.backend.trade.adapter.persistence.filter.mapper;

import io.edpn.backend.trade.adapter.persistence.filter.MybatisPageFilter;
import io.edpn.backend.trade.application.domain.filter.PageFilter;
import io.edpn.backend.trade.application.dto.persistence.filter.PersistencePageFilter;
import io.edpn.backend.trade.application.dto.persistence.filter.mapper.PersistencePageFilterMapper;

public class MybatisPersistencePageFilterMapper implements PersistencePageFilterMapper {
@Override
public PersistencePageFilter map(PageFilter pageFilter) {
return MybatisPageFilter.builder()
.size(pageFilter.getSize())
.page(pageFilter.getPage())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public interface MybatisLocateCommodityRepository {
<if test='maxLandingPadSize == "LARGE"'>AND max_landing_pad_size = 'LARGE'</if>
<if test='maxLandingPadSize == "MEDIUM"'>AND max_landing_pad_size IN ('MEDIUM', 'LARGE')</if>
ORDER BY distance
<if test='page != null'>
LIMIT #{page.size}
OFFSET (#{page.size} * #{page.page})
</if>
</script>"""
)
@Results(id = "findCommodityResultMap", value = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.edpn.backend.trade.adapter.web.dto.filter;

import io.edpn.backend.trade.application.dto.web.filter.LocateCommodityFilterDto;
import io.edpn.backend.trade.application.dto.web.filter.PageFilterDto;
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(name = "LocateCommodityFilterDto")
Expand All @@ -14,5 +15,7 @@ public record RestLocateCommodityFilterDto(
Boolean includeFleetCarriers,
String maxLandingPadSize,
Long minSupply,
Long minDemand) implements LocateCommodityFilterDto {
Long minDemand,
PageFilterDto page
) implements LocateCommodityFilterDto {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.edpn.backend.trade.adapter.web.dto.filter;

import io.edpn.backend.trade.application.dto.web.filter.PageFilterDto;

public record RestPageFilterDto(
int size,
int page
) implements PageFilterDto {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
import io.edpn.backend.trade.application.domain.filter.LocateCommodityFilter;
import io.edpn.backend.trade.application.dto.web.filter.LocateCommodityFilterDto;
import io.edpn.backend.trade.application.dto.web.filter.mapper.LocateCommodityFilterDtoMapper;
import io.edpn.backend.trade.application.dto.web.filter.mapper.PageFilterDtoMapper;
import lombok.RequiredArgsConstructor;

import java.util.Optional;

@RequiredArgsConstructor
public class RestLocateCommodityFilterDtoMapper implements LocateCommodityFilterDtoMapper {
private final PageFilterDtoMapper pageFilterDtoMapper;

@Override
public LocateCommodityFilter map(LocateCommodityFilterDto locateCommodityFilterDto) {
return new LocateCommodityFilter(
Expand All @@ -18,7 +25,10 @@ public LocateCommodityFilter map(LocateCommodityFilterDto locateCommodityFilterD
locateCommodityFilterDto.includeFleetCarriers(),
LandingPadSize.valueOf(locateCommodityFilterDto.maxLandingPadSize()),
locateCommodityFilterDto.minSupply(),
locateCommodityFilterDto.minDemand()
locateCommodityFilterDto.minDemand(),
Optional.ofNullable(locateCommodityFilterDto.page())
.map(pageFilterDtoMapper::map)
.orElse(pageFilterDtoMapper.getDefaultFilter())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.edpn.backend.trade.adapter.web.dto.filter.mapper;

import io.edpn.backend.trade.application.domain.filter.PageFilter;
import io.edpn.backend.trade.application.dto.web.filter.PageFilterDto;
import io.edpn.backend.trade.application.dto.web.filter.mapper.PageFilterDtoMapper;

public class RestPageFilterDtoMapper implements PageFilterDtoMapper {
@Override
public PageFilter map(PageFilterDto pageFilterDto) {
PageFilter.PageFilterBuilder bulder = getDefaultFilterBuilder();
if (pageFilterDto.size() > 0) {
bulder.size(pageFilterDto.size());
}
if (pageFilterDto.page() >= 0) {
bulder.page(pageFilterDto.page());
}
return bulder.build();
}

@Override
public PageFilter getDefaultFilter() {
return getDefaultFilterBuilder()
.build();
}

private PageFilter.PageFilterBuilder getDefaultFilterBuilder() {
return PageFilter.builder()
.size(20) //TODO get from config
.page(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public class LocateCommodityFilter {
private LandingPadSize maxLandingPadSize;
private Long minSupply;
private Long minDemand;
private PageFilter pageFilter;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.edpn.backend.trade.application.domain.filter;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@AllArgsConstructor
@Builder
public class PageFilter {
private int size;

private int page;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.edpn.backend.trade.application.dto.persistence.filter;

public interface PersistencePageFilter {

int getSize();
int getPage();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.edpn.backend.trade.application.dto.persistence.filter.mapper;

import io.edpn.backend.trade.application.domain.filter.PageFilter;
import io.edpn.backend.trade.application.dto.persistence.filter.PersistencePageFilter;

public interface PersistencePageFilterMapper {

PersistencePageFilter map(PageFilter pageFilter);
}
Loading

0 comments on commit 4ce3f74

Please sign in to comment.