Last active
July 27, 2021 13:57
-
-
Save babjo/003aa8388e110e3e720f156ad6a76b78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FakeBlogRepository implements BlogRepository { | |
private Map<String, List<Post>> data = new HashMap<>(); | |
private long lastPostId = 0L; | |
public long save(long userId, Post post) { | |
lastPostId++; | |
post.setId(lastPostId); | |
List<Post> posts = data.get(userId); | |
if (posts == null) { | |
posts = new ArrayList<>(); | |
} | |
posts.add(post); | |
return lastPostId; | |
} | |
public findByUserId(long userId) { | |
List<Post> posts = data.get(userId); | |
if (posts == null) { | |
throw new IllegalStateException("Not found"); | |
} | |
return posts; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment