diff options
Diffstat (limited to 'juick-api/src/main')
-rw-r--r-- | juick-api/src/main/java/com/juick/api/TopManager.java | 41 | ||||
-rw-r--r-- | juick-api/src/main/java/com/juick/api/controllers/Messages.java | 21 |
2 files changed, 41 insertions, 21 deletions
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 <http://www.gnu.org/licenses/>. + */ + +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<Integer> 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(); - } } |