load tester beta

This commit is contained in:
현성필
2024-02-19 12:59:05 +09:00
parent 7424e0d072
commit 1d64cab399
63 changed files with 5600 additions and 1944 deletions
@@ -0,0 +1,43 @@
package com.eactive.testmaster.server.controller;
import com.eactive.testmaster.server.dto.ServerDTO;
import com.eactive.testmaster.server.dto.ServerSearch;
import com.eactive.testmaster.server.entity.Server;
import com.eactive.testmaster.server.mapper.ServerMapper;
import com.eactive.testmaster.server.service.ServerMgmtService;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/mgmt/servers")
public class ServerRestController {
private final ServerMgmtService serverMgmtService;
private final ServerMapper serverMapper;
public ServerRestController(ServerMgmtService serverMgmtService, ServerMapper serverMapper) {
this.serverMgmtService = serverMgmtService;
this.serverMapper = serverMapper;
}
@GetMapping("/list.do")
public ResponseEntity<List<ServerDTO>> listView(@ModelAttribute("serverSearch") ServerSearch serverSearch, ModelMap model, Pageable pageable) {
Page<Server> page = serverMgmtService.findAll(serverSearch.buildSpecification(), pageable);
HttpHeaders headers = new HttpHeaders();
headers.add("X-Total-Count", String.valueOf(page.getTotalElements()));
headers.add("X-Total-Pages", String.valueOf(page.getTotalPages()));
headers.add("X-Current-Page", String.valueOf(page.getNumber()));
headers.add("X-Page-Size", String.valueOf(page.getSize()));
return new ResponseEntity<>(serverMapper.map(page.getContent()), headers, HttpStatus.OK);
}
}
@@ -5,13 +5,15 @@ import com.eactive.testmaster.common.exception.NotFoundException;
import com.eactive.testmaster.server.dto.ServerDTO;
import com.eactive.testmaster.server.entity.Server;
import com.eactive.testmaster.server.entity.ServerRepository;
import java.util.List;
import java.util.stream.Collectors;
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)
unmappedTargetPolicy = ReportingPolicy.IGNORE)
@Component
public class ServerMapper {
@@ -19,17 +21,23 @@ public class ServerMapper {
ServerRepository serverRepository;
public Server mapById(Long id) {
if (id == null || id == 0) return null;
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;
if (server == null) {
return null;
}
return server.getId();
}
public ServerDTO map(Server server) {
if (server == null) return null;
if (server == null) {
return null;
}
ServerDTO dto = new ServerDTO();
dto.setId(server.getId());
@@ -45,7 +53,9 @@ public class ServerMapper {
public Server map(ServerDTO dto) {
if (dto == null) return null;
if (dto == null) {
return null;
}
Server server = new Server();
@@ -59,4 +69,8 @@ public class ServerMapper {
return server;
}
public List<ServerDTO> map(List<Server> servers) {
return servers.stream().map(this::map).collect(Collectors.toList());
}
}