Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,19 @@ public List<Link> getAllLinks(LinkFilter filter, int skip, int first) {
return allLinks;
}

public void saveLink(Link link) {
public Link saveLink(Link link) {
Document doc = new Document();
doc.append("url", link.getUrl());
doc.append("description", link.getDescription());
doc.append("postedBy", link.getUserId());
links.insertOne(doc);

return new Link(
doc.get("_id").toString(),
link.getUrl(),
link.getDescription(),
link.getUserId()
);
}

private Bson buildFilter(LinkFilter filter) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/howtographql/hackernews/Mutation.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public Mutation(LinkRepository linkRepository, UserRepository userRepository, Vo
public Link createLink(String url, String description, DataFetchingEnvironment env) {
AuthContext context = env.getContext();
Link newLink = new Link(url, description, context.getUser().getId());
linkRepository.saveLink(newLink);
return newLink;
return linkRepository.saveLink(newLink);
}

public User createUser(String name, AuthData auth) {
Expand Down