api 수정
This commit is contained in:
@@ -6,6 +6,7 @@ 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 javax.validation.Valid;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -13,10 +14,13 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.annotation.Secured;
|
||||
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.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@@ -45,4 +49,41 @@ public class ServerRestController {
|
||||
headers.add("X-Page-Size", String.valueOf(page.getSize()));
|
||||
return new ResponseEntity<>(serverMapper.map(page.getContent()), headers, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@Secured({"ROLE_MANAGE_SERVER", "ROLE_API_TESTER"})
|
||||
public ResponseEntity<Page<ServerDTO>> listServers(
|
||||
@ModelAttribute ServerSearch serverSearch,
|
||||
@RequestParam(defaultValue = "0") int page,
|
||||
@RequestParam(defaultValue = "10") int size
|
||||
) {
|
||||
Pageable pageable = PageRequest.of(page, size);
|
||||
Page<Server> servers = serverMgmtService.findAll(serverSearch.buildSpecification(), pageable);
|
||||
|
||||
return ResponseEntity.ok(servers.map(serverMapper::map));
|
||||
}
|
||||
|
||||
|
||||
@PostMapping
|
||||
@Secured("ROLE_MANAGE_SERVER")
|
||||
public ResponseEntity<ServerDTO> createServer(@RequestBody @Valid ServerDTO server) {
|
||||
Server created = serverMgmtService.create(serverMapper.map(server));
|
||||
return ResponseEntity.ok(serverMapper.map(created));
|
||||
}
|
||||
|
||||
@PostMapping("/update/{id}")
|
||||
@Secured("ROLE_MANAGE_SERVER")
|
||||
public ResponseEntity<ServerDTO> updateServer(@PathVariable Long id, @RequestBody @Valid ServerDTO server) {
|
||||
Server updated = serverMgmtService.update(id, serverMapper.map(server));
|
||||
return ResponseEntity.ok(serverMapper.map(updated));
|
||||
}
|
||||
|
||||
@PostMapping("/delete")
|
||||
@Secured("ROLE_MANAGE_SERVER")
|
||||
public ResponseEntity<Void> deleteServers(@RequestBody List<Long> ids) {
|
||||
for (Long id : ids) {
|
||||
serverMgmtService.delete(id);
|
||||
}
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user