|
|
|
@ -77,10 +77,14 @@ public class NoteModule extends BaseHandler implements NoteService { |
|
|
|
var user = users.refreshSession(ex); |
|
|
|
var user = users.refreshSession(ex); |
|
|
|
if (user.isEmpty()) return unauthorized(ex); |
|
|
|
if (user.isEmpty()) return unauthorized(ex); |
|
|
|
var module = path.pop(); |
|
|
|
var module = path.pop(); |
|
|
|
if (module == null) throw unprocessable("Module missing in path."); |
|
|
|
Map<Long,Note> notes = null; |
|
|
|
var head = path.pop(); |
|
|
|
if (module == null) { |
|
|
|
long entityId = Long.parseLong(head); |
|
|
|
notes = notesDb.list(user.get().id()); |
|
|
|
var notes = getNotes(module,entityId); |
|
|
|
} else { |
|
|
|
|
|
|
|
var head = path.pop(); |
|
|
|
|
|
|
|
long entityId = Long.parseLong(head); |
|
|
|
|
|
|
|
notes = getNotes(module, entityId); |
|
|
|
|
|
|
|
} |
|
|
|
var authors = notes.values().stream().map(Note::authorId).distinct().map(users::loadUser).collect(Collectors.toMap(UmbrellaUser::id,UmbrellaUser::toMap)); |
|
|
|
var authors = notes.values().stream().map(Note::authorId).distinct().map(users::loadUser).collect(Collectors.toMap(UmbrellaUser::id,UmbrellaUser::toMap)); |
|
|
|
return sendContent(ex, Map.of("notes",mapValues(notes),"authors",authors)); |
|
|
|
return sendContent(ex, Map.of("notes",mapValues(notes),"authors",authors)); |
|
|
|
} catch (NumberFormatException e){ |
|
|
|
} catch (NumberFormatException e){ |
|
|
|
@ -108,6 +112,7 @@ public class NoteModule extends BaseHandler implements NoteService { |
|
|
|
String text = body(ex); |
|
|
|
String text = body(ex); |
|
|
|
if (text.isBlank()) throw missingFieldException("Note text"); |
|
|
|
if (text.isBlank()) throw missingFieldException("Note text"); |
|
|
|
var note = notesDb.load(noteId); |
|
|
|
var note = notesDb.load(noteId); |
|
|
|
|
|
|
|
if (note.authorId() != user.get().id()) throw forbidden("You are not allowed to edit notes of another user!"); |
|
|
|
note = new Note(note.id(),note.module(),note.entityId(),note.authorId(),text,LocalDateTime.now()); |
|
|
|
note = new Note(note.id(),note.module(),note.entityId(),note.authorId(),text,LocalDateTime.now()); |
|
|
|
note = save(note); |
|
|
|
note = save(note); |
|
|
|
return sendContent(ex,note); |
|
|
|
return sendContent(ex,note); |
|
|
|
|