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 create(@RequestBody @Valid NewServerDTO createDTO) { return ResponseEntity.ok().body(serversService.create(createDTO)); } @GetMapping("/{id}") public ResponseEntity getById(@PathVariable String id) { return ResponseEntity.ok().body(serversService.getById(id)); } @GetMapping("/name/{name}") public ResponseEntity getByName(@PathVariable String name) { return ResponseEntity.ok().body(serversService.getByName(name)); } @GetMapping("/type/{type}") public ResponseEntity> getByType(@PathVariable ServersType type) { return ResponseEntity.ok().body(serversService.getByType(type)); } @GetMapping("/application/{application}") public ResponseEntity> getByApplication(@PathVariable Applications application) { return ResponseEntity.ok().body(serversService.getByApplication(application)); } @GetMapping public ResponseEntity> getAll() { return ResponseEntity.ok().body(serversService.getAll()); } @PutMapping("/{id}") public ResponseEntity update(@PathVariable String id, @RequestBody @Valid NewServerDTO updateDTO) { return ResponseEntity.ok().body(serversService.update(id, updateDTO)); } @DeleteMapping("/{id}") public ResponseEntity delete(@PathVariable String id) { serversService.delete(id); return ResponseEntity.noContent().build(); } }