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 @@ -9,6 +9,7 @@
import server.yakssok.domain.friend.domain.entity.Friend;
import server.yakssok.domain.friend.domain.repository.FriendRepository;
import server.yakssok.domain.friend.presentation.dto.request.FollowFriendRequest;
import server.yakssok.domain.friend.presentation.dto.response.FollowFriendResponse;
import server.yakssok.domain.friend.presentation.dto.response.FollowerInfoGroupResponse;
import server.yakssok.domain.friend.presentation.dto.response.FollowerInfoResponse;
import server.yakssok.domain.friend.presentation.dto.response.FollowingInfoGroupResponse;
Expand All @@ -33,6 +34,16 @@ public void followFriendByInviteCode(Long userId, FollowFriendRequest followFrie
followEachOther(followFriendRequest, user, following);
}

@Transactional
public FollowFriendResponse followFriendByInviteCodeV2(Long userId, FollowFriendRequest followFriendRequest) {
String inviteCode = followFriendRequest.inviteCode();
User following = userService.getUserIdByInviteCode(inviteCode);
User user = userService.getActiveUser(userId);
relationshipService.validateCanFollow(user.getId(), following.getId());
followEachOther(followFriendRequest, user, following);
return FollowFriendResponse.of(following);
}

private void followEachOther(FollowFriendRequest followFriendRequest, User user, User following) {
Friend userToFollowing = followFriendRequest.toFriend(user, following);
Friend followingToUser = followFriendRequest.toFriend(following, user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -25,7 +24,7 @@
import server.yakssok.global.common.swagger.ApiErrorResponses;
import server.yakssok.global.exception.ErrorCode;

@Tag(name = "Friend", description = "지인 API")
@Tag(name = "Friend", description = "친구 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/friends")
Expand All @@ -34,7 +33,6 @@ public class FriendController {
private final FriendService friendService;
private final FollowingMedicationStatusService followingMedicationStatusService;


@Operation(summary = "지인 팔로우")
@ApiErrorResponses(value = {
@ApiErrorResponse(ErrorCode.ALREADY_FRIEND),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package server.yakssok.domain.friend.presentation.controller;

import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import server.yakssok.domain.friend.application.service.FriendService;
import server.yakssok.domain.friend.presentation.dto.request.FollowFriendRequest;
import server.yakssok.domain.friend.presentation.dto.response.FollowFriendResponse;
import server.yakssok.global.common.reponse.ApiResponse;
import server.yakssok.global.common.security.YakssokUserDetails;
import server.yakssok.global.common.swagger.ApiErrorResponse;
import server.yakssok.global.common.swagger.ApiErrorResponses;
import server.yakssok.global.exception.ErrorCode;

@Tag(name = "Friend", description = "친구 API V2")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v2/friends")
public class FriendControllerV2 {
private final FriendService friendService;

@Operation(summary = "지인 팔로우")
@ApiErrorResponses(value = {
@ApiErrorResponse(ErrorCode.ALREADY_FRIEND),
@ApiErrorResponse(ErrorCode.INVALID_INVITE_CODE),
})
@PostMapping
public ApiResponse<FollowFriendResponse> followByInviteCode(
@RequestBody @Valid FollowFriendRequest followRequest,
@AuthenticationPrincipal YakssokUserDetails userDetails
) {
Long userId = userDetails.getUserId();
FollowFriendResponse followFriendResponse = friendService.followFriendByInviteCodeV2(userId, followRequest);
return ApiResponse.success(followFriendResponse);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package server.yakssok.domain.friend.presentation.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import server.yakssok.domain.user.domain.entity.User;

public record FollowFriendResponse(
@Schema(description = "닉네임", example = "노을")
String nickname,
@Schema(description = "프로필 이미지 URL", example = "https://example.com/profile.jpg")
String profileImageUrl
) {

public static FollowFriendResponse of(User following) {
return new FollowFriendResponse(following.getNickName(), following.getProfileImageUrl());
}
}