hit-server-manager/backend/src/main/java/com/hitcommunications/servermanager/controllers/ServersController.java

64 lines
2.2 KiB
Java

package com.hitcommunications.servermanager.controllers;
import com.hitcommunications.servermanager.model.dtos.NewServerDTO;
import com.hitcommunications.servermanager.model.dtos.ServerDTO;
import com.hitcommunications.servermanager.model.enums.Applications;
import com.hitcommunications.servermanager.model.enums.ServersType;
import com.hitcommunications.servermanager.services.ServersService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/servers")
@RequiredArgsConstructor
public class ServersController {
private final ServersService serversService;
@PostMapping
public ResponseEntity<ServerDTO> create(@RequestBody @Valid NewServerDTO createDTO) {
return ResponseEntity.ok().body(serversService.create(createDTO));
}
@GetMapping("/{id}")
public ResponseEntity<ServerDTO> getById(@PathVariable String id) {
return ResponseEntity.ok().body(serversService.getById(id));
}
@GetMapping("/name/{name}")
public ResponseEntity<ServerDTO> getByName(@PathVariable String name) {
return ResponseEntity.ok().body(serversService.getByName(name));
}
@GetMapping("/type/{type}")
public ResponseEntity<List<ServerDTO>> getByType(@PathVariable ServersType type) {
return ResponseEntity.ok().body(serversService.getByType(type));
}
@GetMapping("/application/{application}")
public ResponseEntity<List<ServerDTO>> getByApplication(@PathVariable Applications application) {
return ResponseEntity.ok().body(serversService.getByApplication(application));
}
@GetMapping
public ResponseEntity<List<ServerDTO>> getAll() {
return ResponseEntity.ok().body(serversService.getAll());
}
@PutMapping("/{id}")
public ResponseEntity<ServerDTO> update(@PathVariable String id, @RequestBody @Valid NewServerDTO updateDTO) {
return ResponseEntity.ok().body(serversService.update(id, updateDTO));
}
@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(@PathVariable String id) {
serversService.delete(id);
return ResponseEntity.noContent().build();
}
}