Commit b8f30cfe authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

added delete collection

parent bbdd9290
Loading
Loading
Loading
Loading
+5 −3
Original line number Original line Diff line number Diff line
@@ -15,9 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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.PutMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestController;


/**
/**
@@ -59,14 +59,16 @@ public class CollectionsController {
    }
    }


    // delete collection by id
    // delete collection by id
    @DeleteMapping(value = "/collections")
    @DeleteMapping(value = "/collections/{collectionId}")
    public ResponseEntity<String> deleteCollection(
    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 {}", 
        LOG.debug("delete collection called with id {} for user {}", 
                id, principal.getName());
                id, principal.getName());
        
        
        collectionsService.deleteCollectionById(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");
        return ResponseEntity.ok("Collection deleted");
                
                
    }
    }
+3 −2
Original line number Original line Diff line number Diff line
@@ -52,8 +52,9 @@ public class CollectionsService {
    public void deleteCollectionById(Long collectionId, String userId) {
    public void deleteCollectionById(Long collectionId, String userId) {
        if(isUserAuthenticated(userId))
        if(isUserAuthenticated(userId))
        {
        {
            // TODO: Implement delete
            collectionsDAO.deleteCollection(collectionId, userId);
            throw new UnsupportedOperationException("delete collection");
            // TODO: throw exceptions if collection not found or deletion requested
            // by someone who is not the owner
        } else {
        } else {
            throw new PermissionDeniedException("Authentication required");
            throw new PermissionDeniedException("Authentication required");
        }
        }
+3 −4
Original line number Original line Diff line number Diff line
@@ -83,11 +83,10 @@ public class CollectionsDAO {
        return nc;
        return nc;
    }
    }
    
    
    public void deleteCollection(Long collectionId) {
    public void deleteCollection(Long collectionId, String userId) {       
        // TODO: this is just a stub for development.
        String sql  = "DELETE FROM collections WHERE collection_id = ? AND owner_id = ?";
        String sql  = "DELETE FROM collections WHERE collection_id = ?";
        
        
        jdbcTemplate.update(sql, collectionId);
        jdbcTemplate.update(sql, collectionId, userId);
    }
    }


    private NodeCollection getNodeCollectionFromResultset(ResultSet rs)
    private NodeCollection getNodeCollectionFromResultset(ResultSet rs)
+1 −1
Original line number Original line Diff line number Diff line
@@ -52,7 +52,7 @@ public class CollectionsDAOTest {
        
        
        for(NodeCollection nc : ncl) {
        for(NodeCollection nc : ncl) {
            collectionsDAO.deleteCollection(
            collectionsDAO.deleteCollection(
                    nc.getId()
                    nc.getId(), "pippo"
            );            
            );            
        }
        }