Added MRC for Ignored Servers (formerly server blacklist)
This commit is contained in:
parent
da118b40d3
commit
12ca9bd38c
@ -0,0 +1,66 @@
|
|||||||
|
package io.salmonllama.fashionscapeapi.controller;
|
||||||
|
|
||||||
|
import io.salmonllama.fashionscapeapi.exception.ResourceNotFoundException;
|
||||||
|
import io.salmonllama.fashionscapeapi.model.IgnoredServer;
|
||||||
|
import io.salmonllama.fashionscapeapi.repository.IgnoredServerRepository;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/v1/ignoredserver")
|
||||||
|
public class IgnoredServerController {
|
||||||
|
@Autowired
|
||||||
|
private IgnoredServerRepository ignoredServerRepository;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public ResponseEntity<List<IgnoredServer>> getIgnoredServers() {
|
||||||
|
List<IgnoredServer> servers = ignoredServerRepository.findAll();
|
||||||
|
|
||||||
|
return ResponseEntity.ok(servers);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResponseEntity<IgnoredServer> getIgnoredServerById(@PathVariable(value = "id") String serverId) throws ResourceNotFoundException {
|
||||||
|
IgnoredServer server = ignoredServerRepository.findById(serverId).orElseThrow(() -> new ResourceNotFoundException("Ignored Server not found for id :: " + serverId));
|
||||||
|
|
||||||
|
return ResponseEntity.ok(server);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping()
|
||||||
|
public ResponseEntity<IgnoredServer> createIgnoredServer(@Valid @RequestBody IgnoredServer server) {
|
||||||
|
IgnoredServer createdServer = ignoredServerRepository.save(server);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(createdServer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public ResponseEntity<IgnoredServer> updateIgnoredServer(@PathVariable(value = "id") String serverId, @Valid @RequestBody IgnoredServer serverDetails) throws ResourceNotFoundException {
|
||||||
|
IgnoredServer server = ignoredServerRepository.findById(serverId).orElseThrow(() -> new ResourceNotFoundException("Ignored Server not found for id :: " + serverId));
|
||||||
|
|
||||||
|
server
|
||||||
|
.setName(serverDetails.getName())
|
||||||
|
.setOwnerId(serverDetails.getOwnerId())
|
||||||
|
.setReason(serverDetails.getReason())
|
||||||
|
;
|
||||||
|
|
||||||
|
final IgnoredServer updatedServer = ignoredServerRepository.save(server);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(updatedServer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ResponseEntity<Map<String, Boolean>> deleteIgnoredServer(@PathVariable(value = "id") String serverId) throws ResourceNotFoundException {
|
||||||
|
IgnoredServer server = ignoredServerRepository.findById(serverId).orElseThrow(() -> new ResourceNotFoundException("Ignored Server not found for id :: " + serverId));
|
||||||
|
|
||||||
|
ignoredServerRepository.delete(server);
|
||||||
|
Map<String, Boolean> response = new HashMap<>();
|
||||||
|
response.put("deleted", Boolean.TRUE);
|
||||||
|
return ResponseEntity.ok(response);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
package io.salmonllama.fashionscapeapi.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "ignored_server")
|
||||||
|
public class IgnoredServer {
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String ownerId;
|
||||||
|
private String reason;
|
||||||
|
private Timestamp added;
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@Column(name = "id")
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IgnoredServer setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Column(name = "name", nullable = false)
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IgnoredServer setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Column(name = "owner_id", nullable = false)
|
||||||
|
public String getOwnerId() {
|
||||||
|
return ownerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IgnoredServer setOwnerId(String ownerId) {
|
||||||
|
this.ownerId = ownerId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Column(name = "reason", nullable = false)
|
||||||
|
public String getReason() {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IgnoredServer setReason(String reason) {
|
||||||
|
this.reason = reason;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Column(name = "added", nullable = false)
|
||||||
|
public Timestamp getAdded() {
|
||||||
|
return added;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IgnoredServer setAdded(Timestamp added) {
|
||||||
|
this.added = added;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package io.salmonllama.fashionscapeapi.repository;
|
||||||
|
|
||||||
|
import io.salmonllama.fashionscapeapi.model.IgnoredServer;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface IgnoredServerRepository extends JpaRepository<IgnoredServer, String> {
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user