Skip to content

Commit

Permalink
added support for updating basic user notification options and favori…
Browse files Browse the repository at this point in the history
…te tags via API
  • Loading branch information
albogdano committed Oct 22, 2023
1 parent 997e86c commit b5dd976
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/java/com/erudika/scoold/api/ApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ public Map<String, Object> getUser(@PathVariable String id, HttpServletRequest r
}

@PatchMapping("/users/{id}")
@SuppressWarnings("unchecked")
public Profile updateUser(@PathVariable String id, HttpServletRequest req, HttpServletResponse res) {
Map<String, Object> entity = readEntity(req);
if (entity.isEmpty()) {
Expand All @@ -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<String>) 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<String>) entity.get("favtags"));
update = true;
}
if (update) {
pc.update(profile);
}
if (!StringUtils.isBlank(password)) {
Expand Down

0 comments on commit b5dd976

Please sign in to comment.