Search in sources :

Example 1 with Delete

use of net.codestory.http.annotations.Delete in project datashare by ICIJ.

the class ProjectResource method deleteProject.

/**
 * Delete the project from database and elasticsearch indices.
 *
 * It returns 204 (no content) when something has been removed (index and/or database), or
 * 404 if nothing has been removed (i.e. index and database don't exist).
 *
 * If the project id is not the current user project (local-datashare in local mode),
 * then it will return 401 (unauthorized)
 *
 * @param id
 * @return 204 (no content) or 404
 *
 * Example :
 * $(curl -I -XDELETE -H 'Content-Type:application/json' localhost:8080/api/project/unknown-project)
 */
@Delete("/:id")
public Payload deleteProject(String id, Context context) throws Exception {
    if (!context.currentUser().isInRole("local")) {
        return new Payload(401);
    }
    boolean isDeleted = this.repository.deleteAll(id);
    boolean indexDeleted = this.indexer.deleteAll(id);
    return isDeleted || indexDeleted ? new Payload(204) : new Payload(404);
}
Also used : Payload(net.codestory.http.payload.Payload) Delete(net.codestory.http.annotations.Delete)

Aggregations

Delete (net.codestory.http.annotations.Delete)1 Payload (net.codestory.http.payload.Payload)1