Permalink
Browse files

Polish with blog-domain 4.3.3

  • Loading branch information...
making committed Jan 11, 2018
1 parent 69e84a8 commit 994271c893265b5ee3e4d24c24cca743b4020b7c
View
@@ -28,7 +28,7 @@
<dependency>
<groupId>am.ik.blog</groupId>
<artifactId>blog-domain</artifactId>
<version>4.3.1</version>
<version>4.3.3</version>
</dependency>
<dependency>
<groupId>am.ik.github</groupId>
@@ -2,12 +2,11 @@
import am.ik.blog.entry.*;
import com.example.blog.entry.EntryRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import java.util.Arrays;
@Component
@Profile("default")
public class DemoInserter implements CommandLineRunner {
@@ -25,14 +24,14 @@ public void run(String... args) throws Exception {
public static Entry entry(EntryId entryId) {
EventTime now = EventTime.now();
Categories categories = new Categories(Arrays.asList(new Category("foo"),
new Category("bar"), new Category("hoge")));
Tags tags = new Tags(Arrays.asList(new Tag("a"), new Tag("b"), new Tag("c")));
Categories categories = new Categories(new Category("foo"), new Category("bar"),
new Category("hoge"));
Tags tags = new Tags(new Tag("a"), new Tag("b"), new Tag("c"));
return Entry.builder() //
.entryId(entryId) //
.content(new Content("Hello " + entryId)) //
.frontMatter(new FrontMatter(new Title("Hello " + entryId), categories,
tags, now, now, PremiumPoint.UNSET)) //
tags, now, now)) //
.created(new Author(new Name("demo"), now)) //
.updated(new Author(new Name("demo"), now)) //
.build();
@@ -1,19 +1,19 @@
package com.example.blog.entry;
import am.ik.blog.entry.*;
import am.ik.blog.entry.Entry.EntryBuilder;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.util.StringUtils;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import am.ik.blog.entry.*;
import am.ik.blog.entry.Entry.EntryBuilder;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.util.StringUtils;
class EntryExtractors {
static ResultSetExtractor<Optional<Entry>> forEntry() {
return rs -> {
@@ -54,7 +54,7 @@
}
while (rs.next());
if (builder != null) {
// for last loop
// for last loop
entries.add(builder.build());
}
}
@@ -72,8 +72,8 @@ private static EntryBuilder builder(ResultSet rs, List<Category> categories)
.entryId(new EntryId(rs.getLong("entry_id"))) //
.content(new Content(rs.getString("content"))) //
.frontMatter(new FrontMatter(new Title(rs.getString("title")),
new Categories(categories), new Tags(Collections.emptyList()),
createdDate, lastModifiedDate, null)) //
new Categories(categories), new Tags(), createdDate,
lastModifiedDate)) //
.created(new Author(new Name(rs.getString("created_by")), createdDate)) //
.updated(new Author(new Name(rs.getString("last_modified_by")),
lastModifiedDate));
@@ -1,18 +1,19 @@
package com.example.blog.entry;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import am.ik.blog.entry.*;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import static java.util.stream.Collectors.*;
@@ -39,9 +40,8 @@ public EntryRepository(NamedParameterJdbcTemplate jdbcTemplate) {
"SELECT tag_name FROM entry_tag WHERE entry_id = :entry_id",
source, (rs, i) -> new Tag(rs.getString("tag_name")));
FrontMatter fm = e.getFrontMatter();
return e.copy()
.frontMatter(new FrontMatter(fm.title(), fm.categories(),
new Tags(tags), fm.date(), fm.updated(), fm.point()))
return e.copy().frontMatter(new FrontMatter(fm.title(),
fm.categories(), new Tags(tags), fm.date(), fm.updated()))
.build();
});
}
@@ -65,8 +65,7 @@ public EntryRepository(NamedParameterJdbcTemplate jdbcTemplate) {
FrontMatter fm = e.getFrontMatter();
return e.copy()
.frontMatter(new FrontMatter(fm.title(), fm.categories(),
tagsMap.get(e.getEntryId()), fm.date(), fm.updated(),
fm.point()))
tagsMap.get(e.getEntryId()), fm.date(), fm.updated()))
.build();
}) //
.collect(toList());
@@ -1,20 +1,21 @@
package com.example.blog.webhook;
import java.nio.file.Paths;
import java.util.Optional;
import am.ik.blog.entry.*;
import am.ik.blog.entry.Entry.EntryBuilder;
import am.ik.blog.entry.factory.EntryFactory;
import am.ik.github.GitHubClient;
import am.ik.github.core.Committer;
import am.ik.github.repositories.commits.CommitsResponse.Commit;
import am.ik.github.repositories.contents.ContentsResponse.File;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;
import java.nio.file.Paths;
import java.util.Optional;
import org.springframework.stereotype.Component;
@Component
public class EntryFetcher {
@@ -25,7 +26,7 @@ public EntryFetcher(GitHubClient gitHubClient) {
}
public Mono<Entry> fetch(String owner, String repo, String path) {
EntryId entryId = EntryId.fromFileName(Paths.get(path).getFileName().toString());
EntryId entryId = EntryId.fromFilePath(Paths.get(path));
Mono<File> file = this.gitHubClient.file(owner, repo, path).get();
Flux<Commit> commits = this.gitHubClient.commits(owner, repo)
.get(p -> p.path(path));
@@ -1,5 +1,12 @@
package com.example.blog.webhook;
import java.nio.file.Paths;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import am.ik.blog.entry.Entry;
import am.ik.blog.entry.EntryId;
import com.example.blog.BlogProperties;
@@ -8,21 +15,15 @@
import com.example.blog.entry.event.EntryUpdateEvent;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.core.task.TaskExecutor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;
import java.nio.file.Paths;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@RestController
public class WebhookController {
@@ -65,8 +66,7 @@ public WebhookController(BlogProperties props, EntryFetcher entryFetcher,
.doOnNext(e -> this.publisher.publishEvent(new EntryUpdateEvent(e))) //
.map(Entry::entryId);
Flux<EntryId> removed = this.paths(commit.get("removed")) //
.map(path -> EntryId
.fromFileName(Paths.get(path).getFileName().toString())) //
.map(path -> EntryId.fromFilePath(Paths.get(path))) //
.publishOn(Schedulers.fromExecutor(this.taskExecutor)) //
.doOnNext(entryId -> this.publisher
.publishEvent(new EntryDeleteEvent(entryId)));

This file was deleted.

Oops, something went wrong.
@@ -2,20 +2,18 @@
import am.ik.blog.entry.*;
import java.util.Arrays;
public class Fixtures {
public static Entry entry(EntryId entryId) {
EventTime now = EventTime.now();
Categories categories = new Categories(Arrays.asList(new Category("foo"),
new Category("bar"), new Category("hoge")));
Tags tags = new Tags(Arrays.asList(new Tag("a"), new Tag("b"), new Tag("c")));
Categories categories = new Categories(new Category("foo"), new Category("bar"),
new Category("hoge"));
Tags tags = new Tags(new Tag("a"), new Tag("b"), new Tag("c"));
return Entry.builder() //
.entryId(entryId) //
.content(new Content("Hello")) //
.frontMatter(new FrontMatter(new Title("Hello"), categories, tags, now,
now, PremiumPoint.UNSET)) //
.frontMatter(
new FrontMatter(new Title("Hello"), categories, tags, now, now)) //
.created(new Author(new Name("demo"), now)) //
.updated(new Author(new Name("demo"), now)) //
.build();

0 comments on commit 994271c

Please sign in to comment.