poc completed
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package zw.qantra.tm.domain.controllers;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kaczmarzyk.spring.data.jpa.domain.Equal;
|
||||
import net.kaczmarzyk.spring.data.jpa.domain.Like;
|
||||
import net.kaczmarzyk.spring.data.jpa.web.annotation.Spec;
|
||||
import net.kaczmarzyk.spring.data.jpa.web.annotation.Or;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import zw.qantra.tm.domain.models.Recipient;
|
||||
import zw.qantra.tm.domain.services.RecipientService;
|
||||
import net.kaczmarzyk.spring.data.jpa.web.annotation.And;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/recipients")
|
||||
@RequiredArgsConstructor
|
||||
public class RecipientController {
|
||||
|
||||
private final RecipientService recipientService;
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Recipient>> getAllRecipients() {
|
||||
return ResponseEntity.ok(recipientService.getAllRecipients());
|
||||
}
|
||||
|
||||
@GetMapping("/{account}/user/{userId}")
|
||||
public ResponseEntity<Recipient> getRecipient(@PathVariable String account, @PathVariable String userId) {
|
||||
List<Recipient> recipients = recipientService.getRecipient(account, userId);
|
||||
if(recipients.size() > 0){
|
||||
return ResponseEntity.ok(recipients.get(0));
|
||||
}
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<Recipient> createRecipient(@RequestBody Recipient recipient) {
|
||||
return ResponseEntity.ok(recipientService.save(recipient));
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public ResponseEntity<Recipient> updateRecipient(@PathVariable UUID id, @RequestBody Recipient recipient) {
|
||||
Recipient updatedRecipient = recipientService.updateRecipient(id, recipient);
|
||||
if (updatedRecipient != null) {
|
||||
return ResponseEntity.ok(updatedRecipient);
|
||||
}
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseEntity<String> deleteRecipient(@PathVariable UUID id) {
|
||||
if (recipientService.deleteRecipient(id)) {
|
||||
return ResponseEntity.ok("Recipient deleted successfully");
|
||||
}
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
@GetMapping("/search")
|
||||
public ResponseEntity<List<Recipient>> searchRecipients(
|
||||
@And({
|
||||
@Spec(path = "name", spec = Equal.class),
|
||||
@Spec(path = "email", spec = Equal.class),
|
||||
@Spec(path = "phoneNumber", spec = Equal.class),
|
||||
@Spec(path = "account", spec = Equal.class),
|
||||
@Spec(path = "latestProviderLabel", spec = Equal.class),
|
||||
@Spec(path = "userId", spec = Equal.class)
|
||||
}) Specification<Recipient> specification) {
|
||||
return ResponseEntity.ok(recipientService.searchRecipients(specification));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user