|
@@ -1,18 +1,53 @@
|
|
package es.uv.garcosda.controllers;
|
|
package es.uv.garcosda.controllers;
|
|
|
|
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
+import es.uv.garcosda.domain.Document;
|
|
|
|
+import es.uv.garcosda.services.DocumentService;
|
|
|
|
+
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/api/v1/documents")
|
|
@RequestMapping("/api/v1/documents")
|
|
public class FraudController {
|
|
public class FraudController {
|
|
|
|
+
|
|
|
|
+ @Autowired()
|
|
|
|
+ DocumentService ds;
|
|
|
|
|
|
@GetMapping("")
|
|
@GetMapping("")
|
|
public ResponseEntity<?> documents(){
|
|
public ResponseEntity<?> documents(){
|
|
- return new ResponseEntity<String>("", HttpStatus.OK);
|
|
|
|
|
|
+ return new ResponseEntity<List<Document>>(this.ds.findAll(), HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping("{owner}")
|
|
|
|
+ public ResponseEntity<?> documents(@PathVariable("owner") String owner){
|
|
|
|
+ List<Document> documents = this.ds.findByOwner(owner);
|
|
|
|
+ if(documents.size() > 0) {
|
|
|
|
+ return new ResponseEntity<List<Document>>(documents, HttpStatus.OK);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return new ResponseEntity<String>("No documents found for owner "+owner, HttpStatus.NOT_FOUND);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @PostMapping("")
|
|
|
|
+ public ResponseEntity<?> documents(@RequestBody Document document){
|
|
|
|
+ if(this.ds.add(document)) {
|
|
|
|
+ return new ResponseEntity<String>("Document added to collection", HttpStatus.CREATED);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ return new ResponseEntity<String>("Document cannot be added to collection", HttpStatus.CONFLICT);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|