Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Mutation.createLink() #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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