Skip to content

Commit

Permalink
feat: friend search core-module
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongh00 committed Aug 20, 2024
1 parent 45b6fea commit fbedd6c
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.foodgo.coremodule.community.service;

import com.foodgo.coremodule.community.domain.Challenge;
import com.foodgo.coremodule.community.repository.ChallengeDetailRepository;
import com.foodgo.coremodule.community.repository.ChallengeRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ChallengeQueryService {

private final ChallengeRepository challengeRepository;
private final ChallengeDetailRepository challengeDetailRepository;

public Challenge findRecentChallenge(Long userId) {
return challengeRepository.findTopByFriendshipUserIdOrderByCreatedAtDesc(userId);
}

public Boolean checkChallengeYn(Long friendshipId) {
return challengeRepository.existsChallengeByFriendshipId(friendshipId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.foodgo.coremodule.community.service;

import com.foodgo.coremodule.community.domain.Friendship;
import com.foodgo.coremodule.community.repository.FriendShipRepository;
import com.foodgo.coremodule.user.domain.User;
import com.foodgo.coremodule.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class FriendQueryService {

private final FriendShipRepository friendShipRepository;
private final UserRepository userRepository;

public List<User> findFriendWithNickname(String nickname) {
return userRepository.findAllByNicknameContaining(nickname);
}

public Boolean checkFriendShipYn(Long userId, Long friendId) {
return friendShipRepository.existsFriendshipByUserIdAndFriendId(userId, friendId);
}

public Friendship findByUserIdAndFriendId(Long userId, Long friendId) {
return friendShipRepository.findFriendshipByUserIdAndFriendId(userId, friendId);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.foodgo.coremodule.user.repository;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -15,4 +16,6 @@ public interface UserRepository extends JpaRepository<User, Long>, UserRepositor
Boolean existsByNickname(String nickname);

User save(User user);

List<User> findAllByNicknameContaining(String nickname);
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
package com.foodgo.coremodule.user.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.foodgo.commonmodule.user.exception.UserErrorCode;
import com.foodgo.commonmodule.user.exception.UserExceptionHandler;
import com.foodgo.coremodule.user.domain.User;
import com.foodgo.coremodule.user.repository.UserRepository;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

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

private final UserRepository userRepository;
private final UserRepository userRepository;

public Boolean checkUsername(String username) {
return userRepository.existsByUsername(username);
}

public Boolean checkUsername(String username) {
return userRepository.existsByUsername(username);
}
public Boolean checkNickname(String nickname) {
return userRepository.existsByNickname(nickname);
}

public Boolean checkNickname(String nickname) {
return userRepository.existsByNickname(nickname);
}
public User findByUserName(String username) {
return userRepository.findByUsername(username)
.orElseThrow(() -> new UserExceptionHandler(UserErrorCode.USER_NOT_FOUND));
}

public User findByUserName(String username) {
return userRepository.findByUsername(username)
.orElseThrow(() -> new UserExceptionHandler(UserErrorCode.USER_NOT_FOUND));
}
public List<User> findAllUsers() {
return userRepository.findAll();
}
}

0 comments on commit fbedd6c

Please sign in to comment.