From b5dd976fc95dfd2db58437f4a5b79d655c4a0dc6 Mon Sep 17 00:00:00 2001 From: Alex Bogdanovski Date: Sun, 22 Oct 2023 20:39:29 +0300 Subject: [PATCH] added support for updating basic user notification options and favorite tags via API --- .../com/erudika/scoold/api/ApiController.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/com/erudika/scoold/api/ApiController.java b/src/main/java/com/erudika/scoold/api/ApiController.java index 7b086fd2..3d2f8041 100644 --- a/src/main/java/com/erudika/scoold/api/ApiController.java +++ b/src/main/java/com/erudika/scoold/api/ApiController.java @@ -502,6 +502,7 @@ public Map getUser(@PathVariable String id, HttpServletRequest r } @PatchMapping("/users/{id}") + @SuppressWarnings("unchecked") public Profile updateUser(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) { Map entity = readEntity(req); if (entity.isEmpty()) { @@ -524,9 +525,29 @@ public Profile updateUser(@PathVariable String id, HttpServletRequest req, HttpS res.setStatus(HttpStatus.NOT_FOUND.value()); return null; } + boolean update = false; if (entity.containsKey("spaces")) { profile.setSpaces(new HashSet<>(readSpaces(((List) entity.getOrDefault("spaces", Collections.emptyList())).toArray(new String[0])))); + update = true; + } + if (entity.containsKey("replyEmailsEnabled")) { + profile.setReplyEmailsEnabled((Boolean) entity.get("replyEmailsEnabled")); + update = true; + } + if (entity.containsKey("commentEmailsEnabled")) { + profile.setCommentEmailsEnabled((Boolean) entity.get("commentEmailsEnabled")); + update = true; + } + if (entity.containsKey("favtagsEmailsEnabled")) { + profile.setFavtagsEmailsEnabled((Boolean) entity.get("favtagsEmailsEnabled")); + update = true; + } + if (entity.containsKey("favtags") && entity.get("favtags") instanceof List) { + profile.setFavtags((List) entity.get("favtags")); + update = true; + } + if (update) { pc.update(profile); } if (!StringUtils.isBlank(password)) {