implemented deleting of notes

This commit is contained in:
2025-07-30 20:37:08 +02:00
parent e08bcf17a5
commit 3dab95691b
7 changed files with 43 additions and 13 deletions

View File

@@ -4,8 +4,7 @@ package de.srsoftware.umbrella.notes;
import static de.srsoftware.umbrella.core.ConnectionProvider.connect;
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE;
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.unprocessable;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*;
import static de.srsoftware.umbrella.notes.Constants.CONFIG_DATABASE;
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);
var user = users.loadUser(token);
if (user.isEmpty()) return unauthorized(ex);
var module = path.pop();
if (module == null) throw unprocessable("Module missing in path.");
var head = path.pop();
long noteId = Long.parseLong(head);
noteId = notesDb.delete(noteId,user.get().id());
return sendContent(ex, noteId);
if (head == null) throw unprocessable("Module missing in path.");
// try {
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){
return sendContent(ex,HTTP_UNPROCESSABLE,"Entity id missing in path.");
} catch (UmbrellaException e){

View File

@@ -6,7 +6,7 @@ import de.srsoftware.umbrella.core.model.Note;
import java.util.Map;
public interface NotesDb {
long delete(long noteId, long userId);
long delete(long noteId);
void deleteEntity(String module, long entityId);

View File

@@ -85,8 +85,7 @@ CREATE TABLE IF NOT EXISTS "{0}" (
}
@Override
public long delete(long noteId, long userId) {
LOG.log(WARNING,"Not checking whether deleted not belongs to user!");
public long delete(long noteId) {
try {
Query.delete().from(TABLE_NOTES)
.where(ID,equal(noteId))