Skip to content

Commit

Permalink
feat: Followers rest method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr4ll committed Mar 21, 2023
1 parent 3a7943c commit f9587c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,22 @@ public ResponseEntity<User> banUser(Authentication authentication, @PathVariable
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

//TODO: upvotes, followers
//TODO: followers
@PutMapping("/{username}/follow")
public ResponseEntity<User> follow(Authentication authentication, @PathVariable String username){
User userProfile = (User) userService.loadUserByUsername(username);
User userSession = (User) authentication;
userSession.follow(userProfile);
userService.saveUser(userSession);
return new ResponseEntity<>(HttpStatus.OK);
}

@PutMapping("/{username}/unfollow")
public ResponseEntity<User> unfollow(Authentication authentication, @PathVariable String username){
User userProfile = (User) userService.loadUserByUsername(username);
User userSession = (User) authentication;
userSession.unFollow(userProfile);
userService.saveUser(userSession);
return new ResponseEntity<>(HttpStatus.OK);
}
}
2 changes: 1 addition & 1 deletion back/src/main/java/net/daw/alist/models/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class Post {
@OneToMany (orphanRemoval = true)
private List<PostItem> items = new ArrayList<>();

@JsonIgnore

@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
private List<Comment> comments = new ArrayList<>();

Expand Down

0 comments on commit f9587c2

Please sign in to comment.