Skip to content

Commit

Permalink
fix image name and allow mongo uri elements to be overriden
Browse files Browse the repository at this point in the history
  • Loading branch information
rkamradt committed May 3, 2020
1 parent 899db62 commit e126d76
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<version>2.2.0</version>
<configuration>
<to>
<image>docker.io/rlkamradt/readnew</image>
<image>docker.io/rlkamradt/readnews</image>
</to>
</configuration>
</plugin>
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/net/kamradtfamily/readnews/Inserts.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@
*/
@Data
public class Inserts {
@Id String id;
String status;
Integer totalResults;
List<Articles> articles;
private @Id String id;
private String status;
private Integer totalResults;
private List<Articles> articles;
@Data
public static class Articles {
Source source;
String author;
String title;
String description;
String url;
String urlToImage;
String publishedAt;
String content;
private Source source;
private String author;
private String title;
private String description;
private String url;
private String urlToImage;
private String publishedAt;
private String content;
}
@Data
public static class Source {
String id;
String name;
private String id;
private String name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
*/
package net.kamradtfamily.readnews;

import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.Instant;
import java.time.LocalDate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -42,13 +40,11 @@
@RequestMapping("/v1/headlines")
public class ReadHeadlinesControllerV1 {
private static final int MAX_LIMIT = 1000;

private final InsertsReactiveRepository newsReactiveRepository;
private final ObjectMapper objectMapper;
ReadHeadlinesControllerV1(final InsertsReactiveRepository newsReactiveRepository,
ObjectMapper objectMapper) {

ReadHeadlinesControllerV1(final InsertsReactiveRepository newsReactiveRepository) {
this.newsReactiveRepository = newsReactiveRepository;
this.objectMapper = objectMapper;
}

@GetMapping(path="", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
Expand All @@ -58,18 +54,18 @@ Flux<Inserts.Articles> getFromMongo(final Instant from, final Instant to, final
: limit;
return newsReactiveRepository
.findAll()
.flatMap(r -> Flux.fromIterable(r.articles))
.flatMap(r -> Flux.fromIterable(r.getArticles()))
.filter(r -> filterByDate(r, from, to))
.limitRequest(actualLimit);
}

private boolean filterByDate(final Inserts.Articles record, final Instant from, Instant to) {
if(record == null || record.publishedAt == null) {
if(record == null || record.getPublishedAt() == null) {
return false;
}
Instant theDate;
try {
theDate = Instant.parse(record.publishedAt);
theDate = Instant.parse(record.getPublishedAt());
} catch(Exception ex) {
return false;
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
spring.data.mongodb.uri: mongodb\://admin\:admin@localhost\:27017/news?authSource=admin
mongo.host: localhost
mongo.user: admin
mongo.pass: admin
mongo.port: 27017

spring.data.mongodb.uri: mongodb\://${mongo.user}\:${mongo.pass}@${mongo.host}\:${mongo.port}/news?authSource=admin

0 comments on commit e126d76

Please sign in to comment.