From 8c5c7d4c547b013d65f87f38145b9a310207bf56 Mon Sep 17 00:00:00 2001 From: Geoffrey Kwan Date: Thu, 4 Apr 2024 18:04:21 -0400 Subject: [PATCH] feat(Tag): Sort tags when requested --- .../presentation/web/controllers/tag/UserTagController.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/wise/portal/presentation/web/controllers/tag/UserTagController.java b/src/main/java/org/wise/portal/presentation/web/controllers/tag/UserTagController.java index 47c19b4db..ee204e5bb 100644 --- a/src/main/java/org/wise/portal/presentation/web/controllers/tag/UserTagController.java +++ b/src/main/java/org/wise/portal/presentation/web/controllers/tag/UserTagController.java @@ -1,5 +1,6 @@ package org.wise.portal.presentation.web.controllers.tag; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -43,7 +44,10 @@ protected ResponseEntity> createTag(Authentication auth, @GetMapping("/user/tags") protected ResponseEntity>> getTags(Authentication auth) { User user = userService.retrieveUserByUsername(auth.getName()); - List> tags = userTagsService.getTags(user).stream().map(tag -> { + List userTags = userTagsService.getTags(user); + Collections.sort(userTags, + (tag1, tag2) -> tag1.getText().toLowerCase().compareTo(tag2.getText().toLowerCase())); + List> tags = userTags.stream().map(tag -> { return tag.toMap(); }).collect(Collectors.toList()); return ResponseEntityGenerator.createSuccess(tags);