Add MRC for IgnoredUsers (formerly UserBlacklist)
This commit is contained in:
parent
99bff99f07
commit
c91f8e38ed
@ -0,0 +1,64 @@
|
||||
package io.salmonllama.fashionscapeapi.controller;
|
||||
|
||||
import io.salmonllama.fashionscapeapi.exception.ResourceNotFoundException;
|
||||
import io.salmonllama.fashionscapeapi.model.IgnoredUser;
|
||||
import io.salmonllama.fashionscapeapi.repository.IgnoredUserRepository;
|
||||
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/ignoreduser")
|
||||
public class IgnoredUserController {
|
||||
@Autowired
|
||||
private IgnoredUserRepository ignoredUserRepository;
|
||||
|
||||
@GetMapping()
|
||||
public ResponseEntity<List<IgnoredUser>> getIgnoredUsers() {
|
||||
List<IgnoredUser> users = ignoredUserRepository.findAll();
|
||||
|
||||
return ResponseEntity.ok(users);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public ResponseEntity<IgnoredUser> getIgnoredUserById(@PathVariable(value = "id") String userId) throws ResourceNotFoundException {
|
||||
IgnoredUser user = ignoredUserRepository.findById(userId).orElseThrow(() -> new ResourceNotFoundException("Ignored User not found for id :: " + userId));
|
||||
|
||||
return ResponseEntity.ok(user);
|
||||
}
|
||||
|
||||
@PostMapping()
|
||||
public ResponseEntity<IgnoredUser> createIgnoredUser(@Valid @RequestBody IgnoredUser user) {
|
||||
IgnoredUser createdUser = ignoredUserRepository.save(user);
|
||||
|
||||
return ResponseEntity.ok(createdUser);
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<IgnoredUser> updateIgnoredGallery(@PathVariable(value = "id") String userId, @Valid @RequestBody IgnoredUser userDetails) throws ResourceNotFoundException {
|
||||
IgnoredUser user = ignoredUserRepository.findById(userId).orElseThrow(() -> new ResourceNotFoundException("Ignored User not found for id :: " + userId));
|
||||
|
||||
user
|
||||
.setReason(userDetails.getReason())
|
||||
;
|
||||
|
||||
final IgnoredUser updatedUser = ignoredUserRepository.save(user);
|
||||
|
||||
return ResponseEntity.ok(updatedUser);
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<Map<String, Boolean>> deleteIgnoredUser(@PathVariable(value = "id") String userId) throws ResourceNotFoundException {
|
||||
IgnoredUser user = ignoredUserRepository.findById(userId).orElseThrow(() -> new ResourceNotFoundException("Ignored User not found for id :: " + userId));
|
||||
|
||||
ignoredUserRepository.delete(user);
|
||||
Map<String, Boolean> response = new HashMap<>();
|
||||
response.put("deleted", Boolean.TRUE);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
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_user")
|
||||
public class IgnoredUser {
|
||||
private String id;
|
||||
private String reason;
|
||||
private Timestamp added;
|
||||
|
||||
public IgnoredUser() {}
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public IgnoredUser setId(String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Column(name = "reason")
|
||||
public String getReason() {
|
||||
return reason;
|
||||
}
|
||||
public IgnoredUser setReason(String reason) {
|
||||
this.reason = reason;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Column(name = "added")
|
||||
public Timestamp getAdded() {
|
||||
return added;
|
||||
}
|
||||
public IgnoredUser setAdded(Timestamp added) {
|
||||
this.added = added;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package io.salmonllama.fashionscapeapi.repository;
|
||||
|
||||
import io.salmonllama.fashionscapeapi.model.IgnoredUser;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface IgnoredUserRepository extends JpaRepository<IgnoredUser, String> {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user