package 이동 반영

This commit is contained in:
현성필
2023-05-16 21:39:12 +09:00
parent 41d405ace4
commit 22250ef62a
4 changed files with 6 additions and 6 deletions
@@ -1,6 +1,6 @@
package com.eactive.httpmockserver.server.controller;
import com.eactive.httpmockserver.client.mapper.ServerMapper;
import com.eactive.httpmockserver.server.mapper.ServerMapper;
import com.eactive.httpmockserver.server.dto.ServerDTO;
import com.eactive.httpmockserver.server.dto.ServerSearch;
import com.eactive.httpmockserver.server.entity.Server;
@@ -0,0 +1,60 @@
package com.eactive.httpmockserver.server.mapper;
import com.eactive.httpmockserver.client.repository.ServerRepository;
import com.eactive.httpmockserver.common.exception.NotFoundException;
import com.eactive.httpmockserver.server.dto.ServerDTO;
import com.eactive.httpmockserver.server.entity.Server;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Mapper(componentModel = "spring",
unmappedTargetPolicy = ReportingPolicy.IGNORE)
@Component
public class ServerMapper {
@Autowired
ServerRepository serverRepository;
public Server mapById(Long id) {
if (id == null || id == 0) return null;
return serverRepository.findById(id).orElseThrow(() -> new NotFoundException("Server[" + id + "] not found"));
}
public Long mapById(Server server) {
if (server == null) return null;
return server.getId();
}
public ServerDTO map(Server server) {
if (server == null) return null;
ServerDTO dto = new ServerDTO();
dto.setId(server.getId());
dto.setName(server.getName());
dto.setHostname(server.getHostname());
dto.setPort(server.getPort());
dto.setScheme(server.getScheme());
dto.setBasePath(server.getBasePath());
return dto;
}
public Server map(ServerDTO dto) {
if (dto == null) return null;
Server server = new Server();
server.setId(dto.getId());
server.setName(dto.getName());
server.setHostname(dto.getHostname());
server.setPort(dto.getPort());
server.setScheme(dto.getScheme());
server.setBasePath(dto.getBasePath());
return server;
}
}