From 935274d23b576c185468d4c925e9492101074634 Mon Sep 17 00:00:00 2001 From: Florent Mariotti Date: Wed, 11 Dec 2024 16:25:56 +0100 Subject: [PATCH] now back is working, need front --- .../magneto/controller/BoardController.java | 15 +++++++++++---- .../fr/cgi/magneto/core/constants/Field.java | 1 + .../fr/cgi/magneto/service/BoardService.java | 7 +++++++ .../service/impl/DefaultBoardService.java | 19 ++++++++----------- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/backend/src/main/java/fr/cgi/magneto/controller/BoardController.java b/backend/src/main/java/fr/cgi/magneto/controller/BoardController.java index 16461ed9..13359595 100644 --- a/backend/src/main/java/fr/cgi/magneto/controller/BoardController.java +++ b/backend/src/main/java/fr/cgi/magneto/controller/BoardController.java @@ -313,11 +313,18 @@ public void notifyBoardUsers(HttpServerRequest request) { UserUtils.getUserInfos(eb, request, user -> { String boardId = request.getParam(Field.BOARDID); boardService.getBoardSharedUsers(boardId) - .onSuccess(usersIdsList -> { + .onSuccess(board -> { JsonObject params = new JsonObject(); - params.put(Field.BOARDURL, "/magneto#/board/view/") - .put(Field.BOARDNAME, ); - timelineHelper.notifyTimeline(request, "magneto.notify_board", user, usersIdsList, params); + params.put(Field.BOARDURL, "/magneto#/board/" + boardId + "/view/") + .put(Field.BOARDNAME, board.getString(Field.TITLE)); + + List userIdsList = board.getJsonArray(Field.SHARED).stream() + .filter(JsonObject.class::isInstance) + .map(obj -> ((JsonObject) obj).getString(Field.USERID)) + .distinct() + .collect(Collectors.toList()); + + notification.notifyTimeline(request, "magneto.notify_board", user, userIdsList, params); }) .onFailure(fail -> { String message = String.format("[Magneto@%s::notifyBoardUsers] Failed to notify users of board : %s", diff --git a/backend/src/main/java/fr/cgi/magneto/core/constants/Field.java b/backend/src/main/java/fr/cgi/magneto/core/constants/Field.java index 622bfc27..591ca3fd 100644 --- a/backend/src/main/java/fr/cgi/magneto/core/constants/Field.java +++ b/backend/src/main/java/fr/cgi/magneto/core/constants/Field.java @@ -232,4 +232,5 @@ public class Field { //notification Folder public static final String FOLDERTITLE = "folderTitle"; public static final String FOLDERURL = "folderUrl"; + public static final String BOARDNAME = "boardName"; } diff --git a/backend/src/main/java/fr/cgi/magneto/service/BoardService.java b/backend/src/main/java/fr/cgi/magneto/service/BoardService.java index 242d5dca..bb0af5af 100644 --- a/backend/src/main/java/fr/cgi/magneto/service/BoardService.java +++ b/backend/src/main/java/fr/cgi/magneto/service/BoardService.java @@ -64,6 +64,13 @@ public interface BoardService { */ Future> getBoards(List boardIds); + /** + * Get board title ans shared array by id + * + * @param boardId Board id to get data + * @return Future {@link Future } containing the board title and its list of shared users and rights + */ + Future getBoardSharedUsers(String boardId); /** * Get all boards diff --git a/backend/src/main/java/fr/cgi/magneto/service/impl/DefaultBoardService.java b/backend/src/main/java/fr/cgi/magneto/service/impl/DefaultBoardService.java index adb51a1c..542287b1 100644 --- a/backend/src/main/java/fr/cgi/magneto/service/impl/DefaultBoardService.java +++ b/backend/src/main/java/fr/cgi/magneto/service/impl/DefaultBoardService.java @@ -419,8 +419,8 @@ public Future> getBoards(List boardIds) { } @Override - public Future> getBoardSharedUsers(string boardId){ - Promise> promise = Promise.promise(); + public Future getBoardSharedUsers(String boardId){ + Promise promise = Promise.promise(); JsonObject query = this.getBoardById(boardId); mongoDb.command(query.toString(), MongoDbResult.validResultHandler(either -> { if (either.isLeft()) { @@ -428,15 +428,11 @@ public Future> getBoardSharedUsers(string boardId){ either.left().getValue()); promise.fail(either.left().getValue()); } else { - JsonArray shared = either.right().getValue() - .getJsonArray(Field.SHARED, new JsonArray()); - - List userIdsList = shared.stream() - .filter(JsonObject.class::isInstance) - .map(obj -> ((JsonObject) obj).getJsonObject("userId")) - .distinct() - .collect(Collectors.toList()); - promise.complete(); + JsonArray result = either.right().getValue() + .getJsonObject(Field.CURSOR, new JsonObject()) + .getJsonArray(Field.FIRSTBATCH, new JsonArray()); + + promise.complete(result.getJsonObject(0)); } })); return promise.future(); @@ -776,6 +772,7 @@ private JsonObject getBoardById(String boardId) { .put(Field._ID, new JsonObject().put(Mongo.IN, new JsonArray().add(boardId)))) .project(new JsonObject() .put(Field._ID, 1) + .put(Field.TITLE, 1) .put(Field.SHARED, 1)); return query.getAggregate(); }