|
|
|
@ -4,8 +4,7 @@ package de.srsoftware.umbrella.notes; |
|
|
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect; |
|
|
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect; |
|
|
|
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE; |
|
|
|
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE; |
|
|
|
import static de.srsoftware.umbrella.core.Util.mapValues; |
|
|
|
import static de.srsoftware.umbrella.core.Util.mapValues; |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException; |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*; |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.unprocessable; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.notes.Constants.CONFIG_DATABASE; |
|
|
|
import static de.srsoftware.umbrella.notes.Constants.CONFIG_DATABASE; |
|
|
|
import static java.net.HttpURLConnection.HTTP_OK; |
|
|
|
import static java.net.HttpURLConnection.HTTP_OK; |
|
|
|
|
|
|
|
|
|
|
|
@ -50,12 +49,20 @@ public class NoteModule extends BaseHandler implements NoteService { |
|
|
|
Optional<Token> token = SessionToken.from(ex).map(Token::of); |
|
|
|
Optional<Token> token = SessionToken.from(ex).map(Token::of); |
|
|
|
var user = users.loadUser(token); |
|
|
|
var user = users.loadUser(token); |
|
|
|
if (user.isEmpty()) return unauthorized(ex); |
|
|
|
if (user.isEmpty()) return unauthorized(ex); |
|
|
|
var module = path.pop(); |
|
|
|
|
|
|
|
if (module == null) throw unprocessable("Module missing in path."); |
|
|
|
|
|
|
|
var head = path.pop(); |
|
|
|
var head = path.pop(); |
|
|
|
long noteId = Long.parseLong(head); |
|
|
|
if (head == null) throw unprocessable("Module missing in path."); |
|
|
|
noteId = notesDb.delete(noteId,user.get().id()); |
|
|
|
// try {
|
|
|
|
return sendContent(ex, noteId); |
|
|
|
var noteId = Long.parseLong(head); |
|
|
|
|
|
|
|
var note = notesDb.load(noteId); |
|
|
|
|
|
|
|
if (note.authorId() != user.get().id()) throw forbidden("You are not allowed to delete notes of another user"); |
|
|
|
|
|
|
|
return sendContent(ex, notesDb.delete(noteId)); |
|
|
|
|
|
|
|
/* } catch (NumberFormatException ignored) { |
|
|
|
|
|
|
|
var module = head; |
|
|
|
|
|
|
|
head = path.pop(); |
|
|
|
|
|
|
|
long entityId = Long.parseLong(head); |
|
|
|
|
|
|
|
notesDb.deleteEntity(module,entityId); |
|
|
|
|
|
|
|
return sendContent(ex, entityId); |
|
|
|
|
|
|
|
}*/ |
|
|
|
} catch (NumberFormatException e){ |
|
|
|
} catch (NumberFormatException e){ |
|
|
|
return sendContent(ex,HTTP_UNPROCESSABLE,"Entity id missing in path."); |
|
|
|
return sendContent(ex,HTTP_UNPROCESSABLE,"Entity id missing in path."); |
|
|
|
} catch (UmbrellaException e){ |
|
|
|
} catch (UmbrellaException e){ |
|
|
|
|