Skip to content

Commit

Permalink
feat: 팔로우 해제 API 구현 (#78)
Browse files Browse the repository at this point in the history
* feat: 팔로우 해제 API 구현 (#67)

* refactor: 변수명 변경 및 AccessToken default 값 설정 (#67)
  • Loading branch information
kdkdhoho authored Feb 8, 2024
1 parent 1cfaa5b commit 5491a23
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,13 @@ public FollowingsResponse getFollowings(String accessToken) {
.toList();
return FollowingsResponse.of(followingUsers);
}

public void unfollow(Long followingUserId, String accessToken) {
User followingUser = userRepository.getById(followingUserId);

Long loginUserId = jwtManager.read(accessToken);
User followerUser = userRepository.getById(loginUserId);

followRepository.deleteByFollowingUserAndFollowerUser(followingUser, followerUser);
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/listywave/user/presentation/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.listywave.user.application.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestHeader;
Expand Down Expand Up @@ -54,4 +55,13 @@ ResponseEntity<FollowingsResponse> getFollowings(@RequestHeader(value = AUTHORIZ
FollowingsResponse response = userService.getFollowings(accessToken);
return ResponseEntity.ok(response);
}

@DeleteMapping("/follow/{userId}")
ResponseEntity<Void> unfollow(
@PathVariable(value = "userId") Long followingUserId,
@RequestHeader(value = AUTHORIZATION, defaultValue = "") String accessToken
) {
userService.unfollow(followingUserId, accessToken);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
public interface FollowRepository extends JpaRepository<Follow, Long> {

List<Follow> getAllByFollowerUser(User user);

void deleteByFollowingUserAndFollowerUser(User following, User follower);
}

0 comments on commit 5491a23

Please sign in to comment.