From 59d08c3fe59077238e7f7774be359a7966ed522c Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Fri, 12 Jan 2018 10:36:36 +0300
Subject: api: merge top component
---
.../src/main/java/com/juick/api/TopManager.java | 41 ++++++++++++++++++++++
.../java/com/juick/api/controllers/Messages.java | 21 -----------
2 files changed, 41 insertions(+), 21 deletions(-)
create mode 100644 juick-api/src/main/java/com/juick/api/TopManager.java
(limited to 'juick-api/src/main/java/com')
diff --git a/juick-api/src/main/java/com/juick/api/TopManager.java b/juick-api/src/main/java/com/juick/api/TopManager.java
new file mode 100644
index 00000000..c762aa83
--- /dev/null
+++ b/juick-api/src/main/java/com/juick/api/TopManager.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2008-2017, Juick
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package com.juick.api;
+
+import com.juick.service.MessagesService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import javax.inject.Inject;
+
+@Component
+public class TopManager {
+ private static Logger logger = LoggerFactory.getLogger(TopManager.class);
+ @Inject
+ private MessagesService messagesService;
+
+ @Scheduled(fixedRate = 120000)
+ public void updateTop() {
+ messagesService.getPopularCandidates().forEach(m -> {
+ logger.info("added {} to popular", m);
+ messagesService.setMessagePopular(m, 1);
+ });
+ }
+}
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Messages.java b/juick-api/src/main/java/com/juick/api/controllers/Messages.java
index 5f00ee68..e16e46d5 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Messages.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/Messages.java
@@ -178,25 +178,4 @@ public class Messages {
}
throw new HttpForbiddenException();
}
- @ApiIgnore
- @RequestMapping("/messages/top_candidates")
- public List topCandidates() {
- User visitor = UserUtils.getCurrentUser();
- if ((visitor.getUid() == 0) || !(visitor.getName().equals("juick"))) {
- throw new HttpForbiddenException();
- }
- return messagesService.getPopularCandidates();
- }
-
- @ApiIgnore
- @RequestMapping("/messages/set_popular")
- public Status doSetPopular(
- @RequestParam(defaultValue = "0") int mid,
- @RequestParam(defaultValue = "0") int popular) {
- if (mid > 0) {
- messagesService.setMessagePopular(mid, popular);
- return Status.OK;
- }
- throw new HttpBadRequestException();
- }
}
--
cgit v1.2.3