diff --git a/docker-compose.yaml b/docker-compose.yaml index 7f36e2f..6d37f18 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -6,6 +6,8 @@ services: web: build: . + ports: + - 3000:3000 environment: JDBC_DATABASE_URL: "jdbc:postgresql://db:5432/postgres" JDBC_DATABASE_USERNAME: postgres diff --git a/src/main/java/se/datasektionen/calypso/controllers/api/FeedController.java b/src/main/java/se/datasektionen/calypso/controllers/api/FeedController.java index 6ec1f08..fb3dcf5 100644 --- a/src/main/java/se/datasektionen/calypso/controllers/api/FeedController.java +++ b/src/main/java/se/datasektionen/calypso/controllers/api/FeedController.java @@ -1,9 +1,11 @@ package se.datasektionen.calypso.controllers.api; +import java.util.Optional; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import se.datasektionen.calypso.feeds.IcalFeed; import se.datasektionen.calypso.feeds.rss.RssFeeds; @@ -30,13 +32,13 @@ public String eventFeed() { } @RequestMapping(produces = "application/rss+xml", method = RequestMethod.GET, value = "/rss") - public RssView rssFeedSwedish() { - return rssFeeds.swedishFeed(); + public RssView rssFeedSwedish(@RequestParam Optional important) { + return rssFeeds.swedishFeed(important.orElse(false)); } @RequestMapping(produces = "application/rss+xml", method = RequestMethod.GET, value = "/rss_en") - public RssView rssFeedEnglish() { - return rssFeeds.englishFeed(); + public RssView rssFeedEnglish(@RequestParam Optional important) { + return rssFeeds.englishFeed(important.orElse(false)); } } diff --git a/src/main/java/se/datasektionen/calypso/feeds/rss/RssFeeds.java b/src/main/java/se/datasektionen/calypso/feeds/rss/RssFeeds.java index aaa3874..f0eb4fa 100644 --- a/src/main/java/se/datasektionen/calypso/feeds/rss/RssFeeds.java +++ b/src/main/java/se/datasektionen/calypso/feeds/rss/RssFeeds.java @@ -22,49 +22,54 @@ public class RssFeeds { private final Darkmode darkmode; private final Config config; - public RssView swedishFeed() { - return new RssView(fetchAndConvertSwedishItems(), + public RssView swedishFeed(boolean important) { + return new RssView(fetchAndConvertSwedishItems(important), config.getBaseUrl() + RssConstants.Swedish.FEED_URL, RssConstants.Swedish.TITLE, RssConstants.Swedish.DESCRIPTION); } - public RssView englishFeed() { - return new RssView(fetchAndConvertEnglishItems(), + public RssView englishFeed(boolean important) { + return new RssView(fetchAndConvertEnglishItems(important), config.getBaseUrl() + RssConstants.English.FEED_URL, RssConstants.English.TITLE, RssConstants.English.DESCRIPTION); } - private List fetchAndConvertSwedishItems() { - return fetchAndConvertItems(Item::getTitleSwedish, + private List fetchAndConvertSwedishItems(boolean important) { + return fetchAndConvertItems(important, + Item::getTitleSwedish, Item::getAuthorDisplay, Item::getContentSwedishProcessed, i -> RssConstants.Swedish.LINKER.apply(i.getId())); } - private List fetchAndConvertEnglishItems() { - return fetchAndConvertItems(Item::getTitleEnglish, + private List fetchAndConvertEnglishItems(boolean important) { + return fetchAndConvertItems(important, + Item::getTitleEnglish, Item::getAuthorDisplay, Item::getContentEnglishProcessed, i -> RssConstants.English.LINKER.apply(i.getId())); } - private List fetchAndConvertItems(Function titleMapper, + private List fetchAndConvertItems(boolean important, + Function titleMapper, Function authorMapper, Function contentMapper, Function linkMapper) { - - Stream sensitive = apiRepository - .findAllPublished(PageRequest.of(0, 100, Sort.by(Sort.Direction.DESC, "publishDate"))) - .getContent() - .stream() - .filter(i -> !i.isSensitive()); - Stream all = apiRepository + Stream items = apiRepository .findAllPublished(PageRequest.of(0, 100, Sort.by(Sort.Direction.DESC, "publishDate"))) .getContent() .stream(); - return (darkmode.getCurrent() ? sensitive : all) + + if (darkmode.getCurrent()) { + items = items.filter(i -> !i.isSensitive()); + } + if (important) { + items = items.filter(Item::isSticky); + } + + return items .map(i -> RssConverter.toRssItem(i, titleMapper, authorMapper, contentMapper, linkMapper)) .collect(Collectors.toList()); }