Skip to content
Merged
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 @@ -109,11 +109,11 @@ public ResponseEntity<String> followNewUser(@PathVariable("id") Long followerId,
return resultResponse(result);
}

@DeleteMapping("/{id}/follow/{user}")
public ResponseEntity<String> unfollowUser(@PathVariable("id") Long followerId,
@DeleteMapping("/{currentUser}/follow/{user}")
public ResponseEntity<String> unfollowUser(@PathVariable("currentUser") String currentUser,
@PathVariable("user") String username,
@RequestHeader("Authorization") String token) {
UserEnum result = userService.unfollowUser(followerId, username, token.substring(7));
UserEnum result = userService.unfollowUser(currentUser, username, token.substring(7));
return resultResponse(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ public AppUser updateAppUser(AppUser appUser, String token){
* @param username Take in a following id. AKA who the person that is being unfollowed.
* @return {@code UserEnum} is return depending on the status of the service.
*/
public UserEnum unfollowUser(Long followerId, String username, String token){
Optional<AppUser> optionalFollower = userRepo.findById(followerId);
public UserEnum unfollowUser(String currentUser, String username, String token){
Optional<AppUser> optionalFollower = userRepo.findAppUserByUsername(currentUser);
Optional<AppUser> optionalFollowing = userRepo.findAppUserByUsername(username);
if(optionalFollower.isEmpty() || optionalFollowing.isEmpty()){
return UserEnum.UNKNOWN;
Expand All @@ -304,7 +304,7 @@ public UserEnum unfollowUser(Long followerId, String username, String token){
return UserEnum.UNKNOWN;
}

boolean isValid = isValidToken(token, followerId);
boolean isValid = isValidToken(token, follower.getId());
if(!isValid){
return UserEnum.UNAUTHORIZED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export const UserProfileProvider = ({ children }) => {
throw e;
}
};
const removeFollow = async (follower_id, username) => {
const removeFollow = async (currentUser, username) => {
const token = Cookies.get("jwt");
try {
const response = await projectApi.delete(
`/user/${follower_id}/follow/${username}`,
`/user/${currentUser}/follow/${username}`,
{
headers: {
Authorization: `Bearer ${token}`,
Expand Down
4 changes: 2 additions & 2 deletions project2-front/src/component/UserProfile/ProfileButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ const ProfileButton = ({ user, update}) => {
const [isFollowed, setIsFollowed] = useState();

useEffect(() => {
const x = checkFollow(Cookies.get("user_id"), user.username);
const x = checkFollow(Cookies.get("username"), user.username);
x.then((value) => {
setIsFollowed(value);
});
}, [user]);

const handleFollow = async () => {
isFollowed
? removeFollow(Cookies.get("user_id"), user.username)
? removeFollow(Cookies.get("username"), user.username)
: setFollow(Cookies.get("user_id"), user.username);
setIsFollowed(!isFollowed);
update()
Expand Down
Loading