SlideShare a Scribd company logo
Creating a Facebook Clone - Part XXIV
@Service
public class PostService {
private static final int DAY = 24 * 60 * 60000;
@Autowired
private UserRepository users;
@Autowired
private PostRepository posts;
@Autowired
private NewsfeedRepository news;
@Autowired
private CommentRepository comments;
@Autowired
private NotificationService notifications;
public List<PostDAO> postsOf(String authToken, String userId,
int fromPage, int pageSize) {
PostService
@Service
public class PostService {
private static final int DAY = 24 * 60 * 60000;
@Autowired
private UserRepository users;
@Autowired
private PostRepository posts;
@Autowired
private NewsfeedRepository news;
@Autowired
private CommentRepository comments;
@Autowired
private NotificationService notifications;
public List<PostDAO> postsOf(String authToken, String userId,
int fromPage, int pageSize) {
PostService
@Autowired
private NotificationService notifications;
public List<PostDAO> postsOf(String authToken, String userId,
int fromPage, int pageSize) {
User u = users.findByAuthtoken(authToken).get(0);
Page<Post> postPage;
if(u.getId().equals(userId) || u.isFriendById(userId)) {
postPage = posts.findAllPostsByUser(
userId, PageRequest.of(fromPage, pageSize,
Sort.by(Sort.Direction.DESC, "date")));
} else {
postPage = posts.findPostsByUser(
userId, VisibilityConstants.PUBLIC.asString(),
PageRequest.of(fromPage, pageSize,
Sort.by(Sort.Direction.DESC, "date")));
}
List<PostDAO> response = new ArrayList<>();
for(Post p : postPage) {
response.add(p.getDAO());
}
return response;
}
PostService
@Autowired
private NotificationService notifications;
public List<PostDAO> postsOf(String authToken, String userId,
int fromPage, int pageSize) {
User u = users.findByAuthtoken(authToken).get(0);
Page<Post> postPage;
if(u.getId().equals(userId) || u.isFriendById(userId)) {
postPage = posts.findAllPostsByUser(
userId, PageRequest.of(fromPage, pageSize,
Sort.by(Sort.Direction.DESC, "date")));
} else {
postPage = posts.findPostsByUser(
userId, VisibilityConstants.PUBLIC.asString(),
PageRequest.of(fromPage, pageSize,
Sort.by(Sort.Direction.DESC, "date")));
}
List<PostDAO> response = new ArrayList<>();
for(Post p : postPage) {
response.add(p.getDAO());
}
return response;
}
PostService
@Autowired
private NotificationService notifications;
public List<PostDAO> postsOf(String authToken, String userId,
int fromPage, int pageSize) {
User u = users.findByAuthtoken(authToken).get(0);
Page<Post> postPage;
if(u.getId().equals(userId) || u.isFriendById(userId)) {
postPage = posts.findAllPostsByUser(
userId, PageRequest.of(fromPage, pageSize,
Sort.by(Sort.Direction.DESC, "date")));
} else {
postPage = posts.findPostsByUser(
userId, VisibilityConstants.PUBLIC.asString(),
PageRequest.of(fromPage, pageSize,
Sort.by(Sort.Direction.DESC, "date")));
}
List<PostDAO> response = new ArrayList<>();
for(Post p : postPage) {
response.add(p.getDAO());
}
return response;
}
PostService
@Autowired
private NotificationService notifications;
public List<PostDAO> postsOf(String authToken, String userId,
int fromPage, int pageSize) {
User u = users.findByAuthtoken(authToken).get(0);
Page<Post> postPage;
if(u.getId().equals(userId) || u.isFriendById(userId)) {
postPage = posts.findAllPostsByUser(
userId, PageRequest.of(fromPage, pageSize,
Sort.by(Sort.Direction.DESC, "date")));
} else {
postPage = posts.findPostsByUser(
userId, VisibilityConstants.PUBLIC.asString(),
PageRequest.of(fromPage, pageSize,
Sort.by(Sort.Direction.DESC, "date")));
}
List<PostDAO> response = new ArrayList<>();
for(Post p : postPage) {
response.add(p.getDAO());
}
return response;
}
PostService
@Autowired
private NotificationService notifications;
public List<PostDAO> postsOf(String authToken, String userId,
int fromPage, int pageSize) {
User u = users.findByAuthtoken(authToken).get(0);
Page<Post> postPage;
if(u.getId().equals(userId) || u.isFriendById(userId)) {
postPage = posts.findAllPostsByUser(
userId, PageRequest.of(fromPage, pageSize,
Sort.by(Sort.Direction.DESC, "date")));
} else {
postPage = posts.findPostsByUser(
userId, VisibilityConstants.PUBLIC.asString(),
PageRequest.of(fromPage, pageSize,
Sort.by(Sort.Direction.DESC, "date")));
}
List<PostDAO> response = new ArrayList<>();
for(Post p : postPage) {
response.add(p.getDAO());
}
return response;
}
PostService
for(Post p : postPage) {
response.add(p.getDAO());
}
return response;
}
public List<PostDAO> newsfeed(String authToken, int fromPage,
int pageSize) {
Page<Newsfeed> n = news.findNewsfeedForUser(authToken,
PageRequest.of(fromPage, pageSize,
Sort.by(Sort.Order.desc("postDay"),
Sort.Order.asc("rank"),
Sort.Order.desc("postTimestamp"))));
List<PostDAO> response = new ArrayList<>();
for(Newsfeed c : n) {
response.add(c.getEntry().getDAO());
}
return response;
}
public String post(String authToken, PostDAO pd) {
User u = users.findByAuthtoken(authToken).get(0);
Post p = new Post();
p.setContent(pd.getContent());
PostService
for(Post p : postPage) {
response.add(p.getDAO());
}
return response;
}
public List<PostDAO> newsfeed(String authToken, int fromPage,
int pageSize) {
Page<Newsfeed> n = news.findNewsfeedForUser(authToken,
PageRequest.of(fromPage, pageSize,
Sort.by(Sort.Order.desc("postDay"),
Sort.Order.asc("rank"),
Sort.Order.desc("postTimestamp"))));
List<PostDAO> response = new ArrayList<>();
for(Newsfeed c : n) {
response.add(c.getEntry().getDAO());
}
return response;
}
public String post(String authToken, PostDAO pd) {
User u = users.findByAuthtoken(authToken).get(0);
Post p = new Post();
p.setContent(pd.getContent());
PostService
for(Post p : postPage) {
response.add(p.getDAO());
}
return response;
}
public List<PostDAO> newsfeed(String authToken, int fromPage,
int pageSize) {
Page<Newsfeed> n = news.findNewsfeedForUser(authToken,
PageRequest.of(fromPage, pageSize,
Sort.by(Sort.Order.desc("postDay"),
Sort.Order.asc("rank"),
Sort.Order.desc("postTimestamp"))));
List<PostDAO> response = new ArrayList<>();
for(Newsfeed c : n) {
response.add(c.getEntry().getDAO());
}
return response;
}
public String post(String authToken, PostDAO pd) {
User u = users.findByAuthtoken(authToken).get(0);
Post p = new Post();
p.setContent(pd.getContent());
PostService
response.add(c.getEntry().getDAO());
}
return response;
}
public String post(String authToken, PostDAO pd) {
User u = users.findByAuthtoken(authToken).get(0);
Post p = new Post();
p.setContent(pd.getContent());
p.setDate(System.currentTimeMillis());
p.setStyling(pd.getStyling());
p.setTitle(pd.getTitle());
p.setUser(u);
p.setVisibility(pd.getVisibility());
posts.save(p);
addPostToNewsfeed(u, p);
if(u.getFriends() != null) {
for(User c : u.getFriends()) {
addPostToNewsfeed(c, p);
}
}
return p.getId();
}
PostService
response.add(c.getEntry().getDAO());
}
return response;
}
public String post(String authToken, PostDAO pd) {
User u = users.findByAuthtoken(authToken).get(0);
Post p = new Post();
p.setContent(pd.getContent());
p.setDate(System.currentTimeMillis());
p.setStyling(pd.getStyling());
p.setTitle(pd.getTitle());
p.setUser(u);
p.setVisibility(pd.getVisibility());
posts.save(p);
addPostToNewsfeed(u, p);
if(u.getFriends() != null) {
for(User c : u.getFriends()) {
addPostToNewsfeed(c, p);
}
}
return p.getId();
}
PostService
response.add(c.getEntry().getDAO());
}
return response;
}
public String post(String authToken, PostDAO pd) {
User u = users.findByAuthtoken(authToken).get(0);
Post p = new Post();
p.setContent(pd.getContent());
p.setDate(System.currentTimeMillis());
p.setStyling(pd.getStyling());
p.setTitle(pd.getTitle());
p.setUser(u);
p.setVisibility(pd.getVisibility());
posts.save(p);
addPostToNewsfeed(u, p);
if(u.getFriends() != null) {
for(User c : u.getFriends()) {
addPostToNewsfeed(c, p);
}
}
return p.getId();
}
PostService
response.add(c.getEntry().getDAO());
}
return response;
}
public String post(String authToken, PostDAO pd) {
User u = users.findByAuthtoken(authToken).get(0);
Post p = new Post();
p.setContent(pd.getContent());
p.setDate(System.currentTimeMillis());
p.setStyling(pd.getStyling());
p.setTitle(pd.getTitle());
p.setUser(u);
p.setVisibility(pd.getVisibility());
posts.save(p);
addPostToNewsfeed(u, p);
if(u.getFriends() != null) {
for(User c : u.getFriends()) {
addPostToNewsfeed(c, p);
}
}
return p.getId();
}
PostService
response.add(c.getEntry().getDAO());
}
return response;
}
public String post(String authToken, PostDAO pd) {
User u = users.findByAuthtoken(authToken).get(0);
Post p = new Post();
p.setContent(pd.getContent());
p.setDate(System.currentTimeMillis());
p.setStyling(pd.getStyling());
p.setTitle(pd.getTitle());
p.setUser(u);
p.setVisibility(pd.getVisibility());
posts.save(p);
addPostToNewsfeed(u, p);
if(u.getFriends() != null) {
for(User c : u.getFriends()) {
addPostToNewsfeed(c, p);
}
}
return p.getId();
}
PostService
for(User c : u.getFriends()) {
addPostToNewsfeed(c, p);
}
}
return p.getId();
}
private void addPostToNewsfeed(User u, Post p) {
Newsfeed n = new Newsfeed();
n.setEntry(p);
n.setParent(u);
n.setPostDay(System.currentTimeMillis() / DAY);
n.setPostTimestamp(System.currentTimeMillis());
news.save(n);
}
public String comment(String authToken, String postId, CommentDAO cd)
throws PermissionException {
User u = users.findByAuthtoken(authToken).get(0);
Post p = posts.findById(postId).get();
if(!VisibilityConstants.isPublic(p.getVisibility())) {
if(!u.getId().equals(p.getUser().getId())) {
if(!p.getUser().isFriendById(u.getId())) {
throw new
PostService
for(User c : u.getFriends()) {
addPostToNewsfeed(c, p);
}
}
return p.getId();
}
private void addPostToNewsfeed(User u, Post p) {
Newsfeed n = new Newsfeed();
n.setEntry(p);
n.setParent(u);
n.setPostDay(System.currentTimeMillis() / DAY);
n.setPostTimestamp(System.currentTimeMillis());
news.save(n);
}
public String comment(String authToken, String postId, CommentDAO cd)
throws PermissionException {
User u = users.findByAuthtoken(authToken).get(0);
Post p = posts.findById(postId).get();
if(!VisibilityConstants.isPublic(p.getVisibility())) {
if(!u.getId().equals(p.getUser().getId())) {
if(!p.getUser().isFriendById(u.getId())) {
throw new
PostService
news.save(n);
}
public String comment(String authToken, String postId, CommentDAO cd)
throws PermissionException {
User u = users.findByAuthtoken(authToken).get(0);
Post p = posts.findById(postId).get();
if(!VisibilityConstants.isPublic(p.getVisibility())) {
if(!u.getId().equals(p.getUser().getId())) {
if(!p.getUser().isFriendById(u.getId())) {
throw new
PermissionException("This is a private post!");
}
}
}
Comment c = new Comment();
c.setDate(System.currentTimeMillis());
if(cd.getParentComment() != null) {
c.setParentComment(comments.findById(cd.getParentComment()).
get());
}
c.setText(cd.getText());
c.setUser(u);
comments.save(c);
PostService
news.save(n);
}
public String comment(String authToken, String postId, CommentDAO cd)
throws PermissionException {
User u = users.findByAuthtoken(authToken).get(0);
Post p = posts.findById(postId).get();
if(!VisibilityConstants.isPublic(p.getVisibility())) {
if(!u.getId().equals(p.getUser().getId())) {
if(!p.getUser().isFriendById(u.getId())) {
throw new
PermissionException("This is a private post!");
}
}
}
Comment c = new Comment();
c.setDate(System.currentTimeMillis());
if(cd.getParentComment() != null) {
c.setParentComment(comments.findById(cd.getParentComment()).
get());
}
c.setText(cd.getText());
c.setUser(u);
comments.save(c);
PostService
if(!p.getUser().isFriendById(u.getId())) {
throw new
PermissionException("This is a private post!");
}
}
}
Comment c = new Comment();
c.setDate(System.currentTimeMillis());
if(cd.getParentComment() != null) {
c.setParentComment(comments.findById(cd.getParentComment()).
get());
}
c.setText(cd.getText());
c.setUser(u);
comments.save(c);
p.getComments().add(c);
posts.save(p);
notifications.sendNotification(u,
new NotificationDAO(null, u.getDAO(),
"commented on your post", "uE0B7",
0x00A400, 0, false,
postId, cd.getId()));
return c.getId();
}
PostService
if(!p.getUser().isFriendById(u.getId())) {
throw new
PermissionException("This is a private post!");
}
}
}
Comment c = new Comment();
c.setDate(System.currentTimeMillis());
if(cd.getParentComment() != null) {
c.setParentComment(comments.findById(cd.getParentComment()).
get());
}
c.setText(cd.getText());
c.setUser(u);
comments.save(c);
p.getComments().add(c);
posts.save(p);
notifications.sendNotification(u,
new NotificationDAO(null, u.getDAO(),
"commented on your post", "uE0B7",
0x00A400, 0, false,
postId, cd.getId()));
return c.getId();
}
PostService
p.getComments().add(c);
posts.save(p);
notifications.sendNotification(u,
new NotificationDAO(null, u.getDAO(),
"commented on your post", "uE0B7",
0x00A400, 0, false,
postId, cd.getId()));
return c.getId();
}
public void like(String authToken, String postId) {
User u = users.findByAuthtoken(authToken).get(0);
Post p = posts.findById(postId).get();
if(!p.getLikes().contains(u)) {
p.getLikes().add(u);
posts.save(p);
notifications.sendNotification(u,
new NotificationDAO(null, u.getDAO(),
"liked your post", "uE8DC",
0x587EBE, 0, false,
postId, null));
}
}
}
PostService
p.getComments().add(c);
posts.save(p);
notifications.sendNotification(u,
new NotificationDAO(null, u.getDAO(),
"commented on your post", "uE0B7",
0x00A400, 0, false,
postId, cd.getId()));
return c.getId();
}
public void like(String authToken, String postId) {
User u = users.findByAuthtoken(authToken).get(0);
Post p = posts.findById(postId).get();
if(!p.getLikes().contains(u)) {
p.getLikes().add(u);
posts.save(p);
notifications.sendNotification(u,
new NotificationDAO(null, u.getDAO(),
"liked your post", "uE8DC",
0x587EBE, 0, false,
postId, null));
}
}
}
PostService
p.getComments().add(c);
posts.save(p);
notifications.sendNotification(u,
new NotificationDAO(null, u.getDAO(),
"commented on your post", "uE0B7",
0x00A400, 0, false,
postId, cd.getId()));
return c.getId();
}
public void like(String authToken, String postId) {
User u = users.findByAuthtoken(authToken).get(0);
Post p = posts.findById(postId).get();
if(!p.getLikes().contains(u)) {
p.getLikes().add(u);
posts.save(p);
notifications.sendNotification(u,
new NotificationDAO(null, u.getDAO(),
"liked your post", "uE8DC",
0x587EBE, 0, false,
postId, null));
}
}
}
PostService

More Related Content

Similar to Creating a Facebook Clone - Part XXIV.pdf

Creating a Facebook Clone - Part XX - Transcript.pdf
Creating a Facebook Clone - Part XX - Transcript.pdfCreating a Facebook Clone - Part XX - Transcript.pdf
Creating a Facebook Clone - Part XX - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part XIII.pdf
Creating a Whatsapp Clone - Part XIII.pdfCreating a Whatsapp Clone - Part XIII.pdf
Creating a Whatsapp Clone - Part XIII.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XIX.pdf
Creating a Facebook Clone - Part XIX.pdfCreating a Facebook Clone - Part XIX.pdf
Creating a Facebook Clone - Part XIX.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XXXI.pdf
Creating a Facebook Clone - Part XXXI.pdfCreating a Facebook Clone - Part XXXI.pdf
Creating a Facebook Clone - Part XXXI.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdfCreating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdf
ShaiAlmog1
 
Creating a Facebook Clone - Part XXXVIII - Transcript.pdf
Creating a Facebook Clone - Part XXXVIII - Transcript.pdfCreating a Facebook Clone - Part XXXVIII - Transcript.pdf
Creating a Facebook Clone - Part XXXVIII - Transcript.pdf
ShaiAlmog1
 
Testdrevet javautvikling på objektorienterte skinner
Testdrevet javautvikling på objektorienterte skinnerTestdrevet javautvikling på objektorienterte skinner
Testdrevet javautvikling på objektorienterte skinner
Truls Jørgensen
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
ShaiAlmog1
 
Include- Modularity using design patterns- Fault tolerance and Compone.pdf
Include- Modularity using design patterns- Fault tolerance and Compone.pdfInclude- Modularity using design patterns- Fault tolerance and Compone.pdf
Include- Modularity using design patterns- Fault tolerance and Compone.pdf
RyanF2PLeev
 
Creating a Facebook Clone - Part XXXIII.pdf
Creating a Facebook Clone - Part XXXIII.pdfCreating a Facebook Clone - Part XXXIII.pdf
Creating a Facebook Clone - Part XXXIII.pdf
ShaiAlmog1
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
.NET Conf UY
 
Creating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdfCreating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part XI.pdf
Creating a Whatsapp Clone - Part XI.pdfCreating a Whatsapp Clone - Part XI.pdf
Creating a Whatsapp Clone - Part XI.pdf
ShaiAlmog1
 
Creating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdfCreating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdf
ShaiAlmog1
 
Server Side Swift with Swag
Server Side Swift with SwagServer Side Swift with Swag
Server Side Swift with Swag
Jens Ravens
 
Golang slidesaudrey
Golang slidesaudreyGolang slidesaudrey
Golang slidesaudrey
Audrey Lim
 
Spca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_serviceSpca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_service
NCCOMMS
 
Creating a Facebook Clone - Part XXXI - Transcript.pdf
Creating a Facebook Clone - Part XXXI - Transcript.pdfCreating a Facebook Clone - Part XXXI - Transcript.pdf
Creating a Facebook Clone - Part XXXI - Transcript.pdf
ShaiAlmog1
 
Entity Framework Core: tips and tricks
Entity Framework Core: tips and tricksEntity Framework Core: tips and tricks
Entity Framework Core: tips and tricks
ArturDr
 

Similar to Creating a Facebook Clone - Part XXIV.pdf (20)

Creating a Facebook Clone - Part XX - Transcript.pdf
Creating a Facebook Clone - Part XX - Transcript.pdfCreating a Facebook Clone - Part XX - Transcript.pdf
Creating a Facebook Clone - Part XX - Transcript.pdf
 
Creating a Whatsapp Clone - Part XIII.pdf
Creating a Whatsapp Clone - Part XIII.pdfCreating a Whatsapp Clone - Part XIII.pdf
Creating a Whatsapp Clone - Part XIII.pdf
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdf
 
Creating a Facebook Clone - Part XIX.pdf
Creating a Facebook Clone - Part XIX.pdfCreating a Facebook Clone - Part XIX.pdf
Creating a Facebook Clone - Part XIX.pdf
 
Creating a Facebook Clone - Part XXXI.pdf
Creating a Facebook Clone - Part XXXI.pdfCreating a Facebook Clone - Part XXXI.pdf
Creating a Facebook Clone - Part XXXI.pdf
 
Creating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdfCreating a Facebook Clone - Part XX.pdf
Creating a Facebook Clone - Part XX.pdf
 
Creating a Facebook Clone - Part XXXVIII - Transcript.pdf
Creating a Facebook Clone - Part XXXVIII - Transcript.pdfCreating a Facebook Clone - Part XXXVIII - Transcript.pdf
Creating a Facebook Clone - Part XXXVIII - Transcript.pdf
 
Testdrevet javautvikling på objektorienterte skinner
Testdrevet javautvikling på objektorienterte skinnerTestdrevet javautvikling på objektorienterte skinner
Testdrevet javautvikling på objektorienterte skinner
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Include- Modularity using design patterns- Fault tolerance and Compone.pdf
Include- Modularity using design patterns- Fault tolerance and Compone.pdfInclude- Modularity using design patterns- Fault tolerance and Compone.pdf
Include- Modularity using design patterns- Fault tolerance and Compone.pdf
 
Creating a Facebook Clone - Part XXXIII.pdf
Creating a Facebook Clone - Part XXXIII.pdfCreating a Facebook Clone - Part XXXIII.pdf
Creating a Facebook Clone - Part XXXIII.pdf
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
 
Creating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdfCreating a Facebook Clone - Part XXVIII.pdf
Creating a Facebook Clone - Part XXVIII.pdf
 
Creating a Whatsapp Clone - Part XI.pdf
Creating a Whatsapp Clone - Part XI.pdfCreating a Whatsapp Clone - Part XI.pdf
Creating a Whatsapp Clone - Part XI.pdf
 
Creating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdfCreating an Uber Clone - Part XXXX.pdf
Creating an Uber Clone - Part XXXX.pdf
 
Server Side Swift with Swag
Server Side Swift with SwagServer Side Swift with Swag
Server Side Swift with Swag
 
Golang slidesaudrey
Golang slidesaudreyGolang slidesaudrey
Golang slidesaudrey
 
Spca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_serviceSpca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_service
 
Creating a Facebook Clone - Part XXXI - Transcript.pdf
Creating a Facebook Clone - Part XXXI - Transcript.pdfCreating a Facebook Clone - Part XXXI - Transcript.pdf
Creating a Facebook Clone - Part XXXI - Transcript.pdf
 
Entity Framework Core: tips and tricks
Entity Framework Core: tips and tricksEntity Framework Core: tips and tricks
Entity Framework Core: tips and tricks
 

More from ShaiAlmog1

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
ShaiAlmog1
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
ShaiAlmog1
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
ShaiAlmog1
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
ShaiAlmog1
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
ShaiAlmog1
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
ShaiAlmog1
 
Creating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdfCreating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdf
ShaiAlmog1
 

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 
Creating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdfCreating a Whatsapp Clone - Part IX.pdf
Creating a Whatsapp Clone - Part IX.pdf
 

Recently uploaded

Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 

Recently uploaded (20)

Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 

Creating a Facebook Clone - Part XXIV.pdf

  • 1. Creating a Facebook Clone - Part XXIV
  • 2. @Service public class PostService { private static final int DAY = 24 * 60 * 60000; @Autowired private UserRepository users; @Autowired private PostRepository posts; @Autowired private NewsfeedRepository news; @Autowired private CommentRepository comments; @Autowired private NotificationService notifications; public List<PostDAO> postsOf(String authToken, String userId, int fromPage, int pageSize) { PostService
  • 3. @Service public class PostService { private static final int DAY = 24 * 60 * 60000; @Autowired private UserRepository users; @Autowired private PostRepository posts; @Autowired private NewsfeedRepository news; @Autowired private CommentRepository comments; @Autowired private NotificationService notifications; public List<PostDAO> postsOf(String authToken, String userId, int fromPage, int pageSize) { PostService
  • 4. @Autowired private NotificationService notifications; public List<PostDAO> postsOf(String authToken, String userId, int fromPage, int pageSize) { User u = users.findByAuthtoken(authToken).get(0); Page<Post> postPage; if(u.getId().equals(userId) || u.isFriendById(userId)) { postPage = posts.findAllPostsByUser( userId, PageRequest.of(fromPage, pageSize, Sort.by(Sort.Direction.DESC, "date"))); } else { postPage = posts.findPostsByUser( userId, VisibilityConstants.PUBLIC.asString(), PageRequest.of(fromPage, pageSize, Sort.by(Sort.Direction.DESC, "date"))); } List<PostDAO> response = new ArrayList<>(); for(Post p : postPage) { response.add(p.getDAO()); } return response; } PostService
  • 5. @Autowired private NotificationService notifications; public List<PostDAO> postsOf(String authToken, String userId, int fromPage, int pageSize) { User u = users.findByAuthtoken(authToken).get(0); Page<Post> postPage; if(u.getId().equals(userId) || u.isFriendById(userId)) { postPage = posts.findAllPostsByUser( userId, PageRequest.of(fromPage, pageSize, Sort.by(Sort.Direction.DESC, "date"))); } else { postPage = posts.findPostsByUser( userId, VisibilityConstants.PUBLIC.asString(), PageRequest.of(fromPage, pageSize, Sort.by(Sort.Direction.DESC, "date"))); } List<PostDAO> response = new ArrayList<>(); for(Post p : postPage) { response.add(p.getDAO()); } return response; } PostService
  • 6. @Autowired private NotificationService notifications; public List<PostDAO> postsOf(String authToken, String userId, int fromPage, int pageSize) { User u = users.findByAuthtoken(authToken).get(0); Page<Post> postPage; if(u.getId().equals(userId) || u.isFriendById(userId)) { postPage = posts.findAllPostsByUser( userId, PageRequest.of(fromPage, pageSize, Sort.by(Sort.Direction.DESC, "date"))); } else { postPage = posts.findPostsByUser( userId, VisibilityConstants.PUBLIC.asString(), PageRequest.of(fromPage, pageSize, Sort.by(Sort.Direction.DESC, "date"))); } List<PostDAO> response = new ArrayList<>(); for(Post p : postPage) { response.add(p.getDAO()); } return response; } PostService
  • 7. @Autowired private NotificationService notifications; public List<PostDAO> postsOf(String authToken, String userId, int fromPage, int pageSize) { User u = users.findByAuthtoken(authToken).get(0); Page<Post> postPage; if(u.getId().equals(userId) || u.isFriendById(userId)) { postPage = posts.findAllPostsByUser( userId, PageRequest.of(fromPage, pageSize, Sort.by(Sort.Direction.DESC, "date"))); } else { postPage = posts.findPostsByUser( userId, VisibilityConstants.PUBLIC.asString(), PageRequest.of(fromPage, pageSize, Sort.by(Sort.Direction.DESC, "date"))); } List<PostDAO> response = new ArrayList<>(); for(Post p : postPage) { response.add(p.getDAO()); } return response; } PostService
  • 8. @Autowired private NotificationService notifications; public List<PostDAO> postsOf(String authToken, String userId, int fromPage, int pageSize) { User u = users.findByAuthtoken(authToken).get(0); Page<Post> postPage; if(u.getId().equals(userId) || u.isFriendById(userId)) { postPage = posts.findAllPostsByUser( userId, PageRequest.of(fromPage, pageSize, Sort.by(Sort.Direction.DESC, "date"))); } else { postPage = posts.findPostsByUser( userId, VisibilityConstants.PUBLIC.asString(), PageRequest.of(fromPage, pageSize, Sort.by(Sort.Direction.DESC, "date"))); } List<PostDAO> response = new ArrayList<>(); for(Post p : postPage) { response.add(p.getDAO()); } return response; } PostService
  • 9. for(Post p : postPage) { response.add(p.getDAO()); } return response; } public List<PostDAO> newsfeed(String authToken, int fromPage, int pageSize) { Page<Newsfeed> n = news.findNewsfeedForUser(authToken, PageRequest.of(fromPage, pageSize, Sort.by(Sort.Order.desc("postDay"), Sort.Order.asc("rank"), Sort.Order.desc("postTimestamp")))); List<PostDAO> response = new ArrayList<>(); for(Newsfeed c : n) { response.add(c.getEntry().getDAO()); } return response; } public String post(String authToken, PostDAO pd) { User u = users.findByAuthtoken(authToken).get(0); Post p = new Post(); p.setContent(pd.getContent()); PostService
  • 10. for(Post p : postPage) { response.add(p.getDAO()); } return response; } public List<PostDAO> newsfeed(String authToken, int fromPage, int pageSize) { Page<Newsfeed> n = news.findNewsfeedForUser(authToken, PageRequest.of(fromPage, pageSize, Sort.by(Sort.Order.desc("postDay"), Sort.Order.asc("rank"), Sort.Order.desc("postTimestamp")))); List<PostDAO> response = new ArrayList<>(); for(Newsfeed c : n) { response.add(c.getEntry().getDAO()); } return response; } public String post(String authToken, PostDAO pd) { User u = users.findByAuthtoken(authToken).get(0); Post p = new Post(); p.setContent(pd.getContent()); PostService
  • 11. for(Post p : postPage) { response.add(p.getDAO()); } return response; } public List<PostDAO> newsfeed(String authToken, int fromPage, int pageSize) { Page<Newsfeed> n = news.findNewsfeedForUser(authToken, PageRequest.of(fromPage, pageSize, Sort.by(Sort.Order.desc("postDay"), Sort.Order.asc("rank"), Sort.Order.desc("postTimestamp")))); List<PostDAO> response = new ArrayList<>(); for(Newsfeed c : n) { response.add(c.getEntry().getDAO()); } return response; } public String post(String authToken, PostDAO pd) { User u = users.findByAuthtoken(authToken).get(0); Post p = new Post(); p.setContent(pd.getContent()); PostService
  • 12. response.add(c.getEntry().getDAO()); } return response; } public String post(String authToken, PostDAO pd) { User u = users.findByAuthtoken(authToken).get(0); Post p = new Post(); p.setContent(pd.getContent()); p.setDate(System.currentTimeMillis()); p.setStyling(pd.getStyling()); p.setTitle(pd.getTitle()); p.setUser(u); p.setVisibility(pd.getVisibility()); posts.save(p); addPostToNewsfeed(u, p); if(u.getFriends() != null) { for(User c : u.getFriends()) { addPostToNewsfeed(c, p); } } return p.getId(); } PostService
  • 13. response.add(c.getEntry().getDAO()); } return response; } public String post(String authToken, PostDAO pd) { User u = users.findByAuthtoken(authToken).get(0); Post p = new Post(); p.setContent(pd.getContent()); p.setDate(System.currentTimeMillis()); p.setStyling(pd.getStyling()); p.setTitle(pd.getTitle()); p.setUser(u); p.setVisibility(pd.getVisibility()); posts.save(p); addPostToNewsfeed(u, p); if(u.getFriends() != null) { for(User c : u.getFriends()) { addPostToNewsfeed(c, p); } } return p.getId(); } PostService
  • 14. response.add(c.getEntry().getDAO()); } return response; } public String post(String authToken, PostDAO pd) { User u = users.findByAuthtoken(authToken).get(0); Post p = new Post(); p.setContent(pd.getContent()); p.setDate(System.currentTimeMillis()); p.setStyling(pd.getStyling()); p.setTitle(pd.getTitle()); p.setUser(u); p.setVisibility(pd.getVisibility()); posts.save(p); addPostToNewsfeed(u, p); if(u.getFriends() != null) { for(User c : u.getFriends()) { addPostToNewsfeed(c, p); } } return p.getId(); } PostService
  • 15. response.add(c.getEntry().getDAO()); } return response; } public String post(String authToken, PostDAO pd) { User u = users.findByAuthtoken(authToken).get(0); Post p = new Post(); p.setContent(pd.getContent()); p.setDate(System.currentTimeMillis()); p.setStyling(pd.getStyling()); p.setTitle(pd.getTitle()); p.setUser(u); p.setVisibility(pd.getVisibility()); posts.save(p); addPostToNewsfeed(u, p); if(u.getFriends() != null) { for(User c : u.getFriends()) { addPostToNewsfeed(c, p); } } return p.getId(); } PostService
  • 16. response.add(c.getEntry().getDAO()); } return response; } public String post(String authToken, PostDAO pd) { User u = users.findByAuthtoken(authToken).get(0); Post p = new Post(); p.setContent(pd.getContent()); p.setDate(System.currentTimeMillis()); p.setStyling(pd.getStyling()); p.setTitle(pd.getTitle()); p.setUser(u); p.setVisibility(pd.getVisibility()); posts.save(p); addPostToNewsfeed(u, p); if(u.getFriends() != null) { for(User c : u.getFriends()) { addPostToNewsfeed(c, p); } } return p.getId(); } PostService
  • 17. for(User c : u.getFriends()) { addPostToNewsfeed(c, p); } } return p.getId(); } private void addPostToNewsfeed(User u, Post p) { Newsfeed n = new Newsfeed(); n.setEntry(p); n.setParent(u); n.setPostDay(System.currentTimeMillis() / DAY); n.setPostTimestamp(System.currentTimeMillis()); news.save(n); } public String comment(String authToken, String postId, CommentDAO cd) throws PermissionException { User u = users.findByAuthtoken(authToken).get(0); Post p = posts.findById(postId).get(); if(!VisibilityConstants.isPublic(p.getVisibility())) { if(!u.getId().equals(p.getUser().getId())) { if(!p.getUser().isFriendById(u.getId())) { throw new PostService
  • 18. for(User c : u.getFriends()) { addPostToNewsfeed(c, p); } } return p.getId(); } private void addPostToNewsfeed(User u, Post p) { Newsfeed n = new Newsfeed(); n.setEntry(p); n.setParent(u); n.setPostDay(System.currentTimeMillis() / DAY); n.setPostTimestamp(System.currentTimeMillis()); news.save(n); } public String comment(String authToken, String postId, CommentDAO cd) throws PermissionException { User u = users.findByAuthtoken(authToken).get(0); Post p = posts.findById(postId).get(); if(!VisibilityConstants.isPublic(p.getVisibility())) { if(!u.getId().equals(p.getUser().getId())) { if(!p.getUser().isFriendById(u.getId())) { throw new PostService
  • 19. news.save(n); } public String comment(String authToken, String postId, CommentDAO cd) throws PermissionException { User u = users.findByAuthtoken(authToken).get(0); Post p = posts.findById(postId).get(); if(!VisibilityConstants.isPublic(p.getVisibility())) { if(!u.getId().equals(p.getUser().getId())) { if(!p.getUser().isFriendById(u.getId())) { throw new PermissionException("This is a private post!"); } } } Comment c = new Comment(); c.setDate(System.currentTimeMillis()); if(cd.getParentComment() != null) { c.setParentComment(comments.findById(cd.getParentComment()). get()); } c.setText(cd.getText()); c.setUser(u); comments.save(c); PostService
  • 20. news.save(n); } public String comment(String authToken, String postId, CommentDAO cd) throws PermissionException { User u = users.findByAuthtoken(authToken).get(0); Post p = posts.findById(postId).get(); if(!VisibilityConstants.isPublic(p.getVisibility())) { if(!u.getId().equals(p.getUser().getId())) { if(!p.getUser().isFriendById(u.getId())) { throw new PermissionException("This is a private post!"); } } } Comment c = new Comment(); c.setDate(System.currentTimeMillis()); if(cd.getParentComment() != null) { c.setParentComment(comments.findById(cd.getParentComment()). get()); } c.setText(cd.getText()); c.setUser(u); comments.save(c); PostService
  • 21. if(!p.getUser().isFriendById(u.getId())) { throw new PermissionException("This is a private post!"); } } } Comment c = new Comment(); c.setDate(System.currentTimeMillis()); if(cd.getParentComment() != null) { c.setParentComment(comments.findById(cd.getParentComment()). get()); } c.setText(cd.getText()); c.setUser(u); comments.save(c); p.getComments().add(c); posts.save(p); notifications.sendNotification(u, new NotificationDAO(null, u.getDAO(), "commented on your post", "uE0B7", 0x00A400, 0, false, postId, cd.getId())); return c.getId(); } PostService
  • 22. if(!p.getUser().isFriendById(u.getId())) { throw new PermissionException("This is a private post!"); } } } Comment c = new Comment(); c.setDate(System.currentTimeMillis()); if(cd.getParentComment() != null) { c.setParentComment(comments.findById(cd.getParentComment()). get()); } c.setText(cd.getText()); c.setUser(u); comments.save(c); p.getComments().add(c); posts.save(p); notifications.sendNotification(u, new NotificationDAO(null, u.getDAO(), "commented on your post", "uE0B7", 0x00A400, 0, false, postId, cd.getId())); return c.getId(); } PostService
  • 23. p.getComments().add(c); posts.save(p); notifications.sendNotification(u, new NotificationDAO(null, u.getDAO(), "commented on your post", "uE0B7", 0x00A400, 0, false, postId, cd.getId())); return c.getId(); } public void like(String authToken, String postId) { User u = users.findByAuthtoken(authToken).get(0); Post p = posts.findById(postId).get(); if(!p.getLikes().contains(u)) { p.getLikes().add(u); posts.save(p); notifications.sendNotification(u, new NotificationDAO(null, u.getDAO(), "liked your post", "uE8DC", 0x587EBE, 0, false, postId, null)); } } } PostService
  • 24. p.getComments().add(c); posts.save(p); notifications.sendNotification(u, new NotificationDAO(null, u.getDAO(), "commented on your post", "uE0B7", 0x00A400, 0, false, postId, cd.getId())); return c.getId(); } public void like(String authToken, String postId) { User u = users.findByAuthtoken(authToken).get(0); Post p = posts.findById(postId).get(); if(!p.getLikes().contains(u)) { p.getLikes().add(u); posts.save(p); notifications.sendNotification(u, new NotificationDAO(null, u.getDAO(), "liked your post", "uE8DC", 0x587EBE, 0, false, postId, null)); } } } PostService
  • 25. p.getComments().add(c); posts.save(p); notifications.sendNotification(u, new NotificationDAO(null, u.getDAO(), "commented on your post", "uE0B7", 0x00A400, 0, false, postId, cd.getId())); return c.getId(); } public void like(String authToken, String postId) { User u = users.findByAuthtoken(authToken).get(0); Post p = posts.findById(postId).get(); if(!p.getLikes().contains(u)) { p.getLikes().add(u); posts.save(p); notifications.sendNotification(u, new NotificationDAO(null, u.getDAO(), "liked your post", "uE8DC", 0x587EBE, 0, false, postId, null)); } } } PostService