aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/juick/User.java7
-rw-r--r--src/main/java/com/juick/server/api/Users.java3
-rw-r--r--src/test/java/com/juick/server/tests/ServerTests.java18
3 files changed, 28 insertions, 0 deletions
diff --git a/src/main/java/com/juick/User.java b/src/main/java/com/juick/User.java
index 5407fa95..8c0e68bc 100644
--- a/src/main/java/com/juick/User.java
+++ b/src/main/java/com/juick/User.java
@@ -18,6 +18,7 @@ package com.juick;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.juick.model.TagStats;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
@@ -57,9 +58,11 @@ public class User implements Serializable {
private String country;
private String url;
private String description;
+ private List<TagStats> tagStats;
public User() {
tokens = new ArrayList<>();
+ tagStats = new ArrayList<>();
uri = URI.create(StringUtils.EMPTY);
}
@@ -263,4 +266,8 @@ public class User implements Serializable {
public void setDescription(String description) {
this.description = description;
}
+
+ public List<TagStats> getTagStats() {
+ return tagStats;
+ }
}
diff --git a/src/main/java/com/juick/server/api/Users.java b/src/main/java/com/juick/server/api/Users.java
index 1a046ad8..0db710c9 100644
--- a/src/main/java/com/juick/server/api/Users.java
+++ b/src/main/java/com/juick/server/api/Users.java
@@ -55,6 +55,8 @@ public class Users {
@Inject
private EmailService emailService;
@Inject
+ private TagService tagService;
+ @Inject
private WebApp webApp;
@Inject
private ImagesService imagesService;
@@ -101,6 +103,7 @@ public class Users {
me.setRead(userService.getUserFriends(visitor.getUid()));
me.setReaders(userService.getUserReaders(visitor.getUid()));
me.setAvatar(webApp.getAvatarUrl(visitor));
+ me.getTagStats().addAll(tagService.getUserTagStats(me.getUid()));
return (SecureUser)userService.getUserInfo(me);
}
@PostMapping("/api/me/upload")
diff --git a/src/test/java/com/juick/server/tests/ServerTests.java b/src/test/java/com/juick/server/tests/ServerTests.java
index 9b905319..4c72913e 100644
--- a/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/src/test/java/com/juick/server/tests/ServerTests.java
@@ -2103,4 +2103,22 @@ public class ServerTests {
TopEvent receivedEvent = topEventCaptor.getValue();
assertThat(receivedEvent.getMessage().getUser(), is(ugnich));
}
+ @Test
+ public void tagStatsSpec() throws Exception {
+ String newUserName = "tagger";
+ String newUserSecret = "secret";
+ User newUser = userService.createUser(newUserName, newUserSecret)
+ .orElseThrow(IllegalStateException::new);
+ commandsManager.processCommand(newUser, "*test yo", emptyUri);
+ commandsManager.processCommand(newUser, "*test yo2", emptyUri);
+ commandsManager.processCommand(newUser, "*rare yo3", emptyUri);
+ MvcResult userResponse = mockMvc.perform(get("/api/me").with(httpBasic(newUserName, newUserSecret)))
+ .andExpect(status().isOk()).andReturn();
+ User userData = jsonMapper.readValue(userResponse.getResponse().getContentAsString(), User.class);
+ List<TagStats> userTags = userData.getTagStats();
+ assertThat(userTags.size(), is(2));
+ TagStats rareTagStats = userTags.stream().filter(tagStats -> tagStats.getTag().getName().equals("rare"))
+ .findFirst().orElseThrow(IllegalStateException::new);
+ assertThat(rareTagStats.getUsageCount(), is(1));
+ }
}