Skip to content
Snippets Groups Projects
Commit b8f30cfe authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

added delete collection

parent bbdd9290
No related branches found
No related tags found
No related merge requests found
......@@ -15,9 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
......@@ -59,14 +59,16 @@ public class CollectionsController {
}
// delete collection by id
@DeleteMapping(value = "/collections")
@DeleteMapping(value = "/collections/{collectionId}")
public ResponseEntity<String> deleteCollection(
@RequestParam("id") Long id, User principal) {
@PathVariable("collectionId") Long id, User principal) {
LOG.debug("delete collection called with id {} for user {}",
id, principal.getName());
collectionsService.deleteCollectionById(id, principal.getName());
// TODO: manage case collection not found or request by someone who isn't
// the owner
return ResponseEntity.ok("Collection deleted");
}
......
......@@ -52,8 +52,9 @@ public class CollectionsService {
public void deleteCollectionById(Long collectionId, String userId) {
if(isUserAuthenticated(userId))
{
// TODO: Implement delete
throw new UnsupportedOperationException("delete collection");
collectionsDAO.deleteCollection(collectionId, userId);
// TODO: throw exceptions if collection not found or deletion requested
// by someone who is not the owner
} else {
throw new PermissionDeniedException("Authentication required");
}
......
......@@ -83,11 +83,10 @@ public class CollectionsDAO {
return nc;
}
public void deleteCollection(Long collectionId) {
// TODO: this is just a stub for development.
String sql = "DELETE FROM collections WHERE collection_id = ?";
public void deleteCollection(Long collectionId, String userId) {
String sql = "DELETE FROM collections WHERE collection_id = ? AND owner_id = ?";
jdbcTemplate.update(sql, collectionId);
jdbcTemplate.update(sql, collectionId, userId);
}
private NodeCollection getNodeCollectionFromResultset(ResultSet rs)
......
......@@ -52,7 +52,7 @@ public class CollectionsDAOTest {
for(NodeCollection nc : ncl) {
collectionsDAO.deleteCollection(
nc.getId()
nc.getId(), "pippo"
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment