Skip to content

Commit

Permalink
feat: 친구 수락하기 API
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Aug 20, 2024
1 parent 18bb3bc commit 6342aaa
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
import com.foodgo.coremodule.user.service.UserQueryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class FriendFindUseCase {

private final UserQueryService userQueryService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package com.foodgo.apimodule.community.application;

import com.foodgo.coremodule.community.domain.Friendship;
import com.foodgo.coremodule.community.service.FriendQueryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional
public class FriendSaveUseCase {

private final FriendQueryService friendQueryService;

public void acceptFriendRequest(Long userId, Long friendId) {

Friendship friendship = friendQueryService.findByUserIdAndFriendId(userId, friendId);
friendship.markAsMutual();
friendQueryService.save(friendship);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

Expand Down Expand Up @@ -96,5 +93,24 @@ public ApplicationResponse<List<FriendRequestList>> findFriendRequestList(
}

// 친구 수락하기
@PatchMapping("/friend/accept/{friendId}")
@ApiResponses(
value = {
@ApiResponse(
responseCode = "200",
description = "친구 수락하기",
useReturnTypeSchema = true
)
}
)
@Operation(summary = "친구 수락 API", description = "친구 수락 API 입니다.")
public ApplicationResponse<String> acceptFriend(
@UserResolver User user,
@PathVariable Long friendId
) {

friendSaveUseCase.acceptFriendRequest(user.getId(), friendId);
return ApplicationResponse.onSuccess("친구 수락하였습니다.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ public List<User> findFriendRequestList(Long userId) {
return friendShipRepository.findFriendshipsByUserId(userId)
.stream().map(Friendship::getFriend).toList();
}

public void save(Friendship friendship) {
friendShipRepository.save(friendship);
}
}

0 comments on commit 6342aaa

Please sign in to comment.