기본 골격
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package com.eactive.httpmockserver.api.mapper;
|
||||
|
||||
import com.eactive.httpmockserver.api.dto.MockHeaderDTO;
|
||||
import com.eactive.httpmockserver.api.dto.MockResponseDTO;
|
||||
import com.eactive.httpmockserver.api.dto.MockRouteDTO;
|
||||
import com.eactive.httpmockserver.api.entity.MockResponse;
|
||||
import com.eactive.httpmockserver.api.entity.MockRoute;
|
||||
import com.eactive.httpmockserver.common.mapper.CommonMapper;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mapping;
|
||||
import org.mapstruct.Named;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper(componentModel = "spring",
|
||||
uses = {CommonMapper.class},
|
||||
unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
@Component
|
||||
public abstract class MockRouteMapper {
|
||||
public abstract MockRoute map(MockRouteDTO dto);
|
||||
|
||||
public abstract MockRouteDTO map(MockRoute entity);
|
||||
|
||||
@Mapping(target = "headers", source = "headers", qualifiedByName = "mapHeadersToMap")
|
||||
public abstract MockResponse map(MockResponseDTO dto);
|
||||
|
||||
@Mapping(target = "headers", source = "headers", qualifiedByName = "mapHeadersToList")
|
||||
public abstract MockResponseDTO map(MockResponse entity);
|
||||
|
||||
@Named("mapHeadersToList")
|
||||
public List<MockHeaderDTO> mapHeadersToList(Map<String, String> headers) {
|
||||
List<MockHeaderDTO> list = new ArrayList<>();
|
||||
if (headers != null) {
|
||||
headers.forEach((key, value) -> {
|
||||
MockHeaderDTO header = new MockHeaderDTO();
|
||||
header.setKey(key);
|
||||
header.setValue(value);
|
||||
list.add(header);
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Named("mapHeadersToMap")
|
||||
public Map<String, String> mapHeadersToMap(List<MockHeaderDTO> headers) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (headers != null) {
|
||||
headers.forEach(header -> {
|
||||
map.put(header.getKey(), header.getValue());
|
||||
});
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user