Skip to content

Commit

Permalink
fix: 조회 필터링 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
h-beeen committed Feb 6, 2024
1 parent 713e97e commit dbd5a3d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class UserInfoService {
private final JwtService jwtService;

public MyPageResponse getMyPageInfo(Long memberId) {
Member member = memberRepository.findById(memberId)
Member member = memberRepository.findByIdAndDeleted(memberId, false)
.orElseThrow(() -> BusinessException.of(MEMBER_NOT_FOUND));

if (member.isDeleted())
Expand All @@ -42,7 +42,7 @@ public MyPageResponse getMyPageInfo(Long memberId) {
}

public UserInfoResponse getUserInfo(Long memberId) {
Member member = memberRepository.findById(memberId)
Member member = memberRepository.findByIdAndDeleted(memberId, false)
.orElseThrow(() -> BusinessException.of(MEMBER_NOT_FOUND));

if (member.isDeleted())
Expand All @@ -57,7 +57,7 @@ public UserIdResponse getRandomUserInfo() {
}

public AppInitResponse initialize(Long memberId, AppInitRequest request) {
Member member = memberRepository.findById(memberId)
Member member = memberRepository.findByIdAndDeleted(memberId, false)
.orElseThrow(() -> BusinessException.of(MEMBER_NOT_FOUND));

if (member.isInitialized())
Expand All @@ -76,7 +76,7 @@ public AppInitResponse initialize(Long memberId, AppInitRequest request) {
}

public void delete(Long memberId) {
Member member = memberRepository.findById(memberId)
Member member = memberRepository.findByIdAndDeleted(memberId, false)
.orElseThrow(() -> BusinessException.of(MEMBER_NOT_FOUND));

member.delete();
Expand Down Expand Up @@ -115,7 +115,7 @@ public List<MemberResponse> getAllMembersByNickname(String nickname) {
}

public AppMyIngredientResponse getMyIngredients(Long id) {
Member member = memberRepository.findById(id)
Member member = memberRepository.findByIdAndDeleted(id, false)
.orElseThrow(() -> BusinessException.of(MEMBER_NOT_FOUND));

if (member.isDeleted())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package com.tteokguk.tteokguk.member.infra.persistence;

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

import com.tteokguk.tteokguk.member.domain.Member;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

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

@Transactional
public interface MemberRepository extends JpaRepository<Member, Long> {
boolean existsByNickname(String nickname);

// todo 성능 이슈를 고려한 리팩토링 필요
@Query(value = "SELECT m FROM Member m ORDER BY RAND() LIMIT 1")
@Query(value = "SELECT m FROM Member m WHERE m.deleted = false AND m.role = 'ROLE_USER' ORDER BY RAND() LIMIT 1")
Member findRandomUser();

@Query(value = "SELECT m FROM Member m WHERE m.deleted = :deleted AND m.role = 'ROLE_USER' AND m.id = :id")
Optional<Member> findByIdAndDeleted(Long id, boolean deleted);

Optional<Member> findByNickname(String nickname);

Page<Member> findByNicknameStartingWithAndDeleted(String nickname, Pageable pageable, boolean deleted);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.tteokguk.tteokguk.member.infra.persistence;

import java.util.Optional;

import com.tteokguk.tteokguk.member.domain.SimpleMember;
import org.springframework.data.jpa.repository.JpaRepository;

import com.tteokguk.tteokguk.member.domain.SimpleMember;
import java.util.Optional;

public interface SimpleMemberRepository extends JpaRepository<SimpleMember, Long> {
boolean existsByEmail(String email);
boolean existsByEmail(String email);

Optional<SimpleMember> findByIdAndDeleted(Long id, boolean deleted);

Optional<SimpleMember> findByEmail(String email);
Optional<SimpleMember> findByEmail(String email);

boolean existsByNickname(String nickname);
boolean existsByNickname(String nickname);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SupportResponse doSupport(
Long id,
SupportRequest request
) {
Member sender = memberRepository.findById(id)
Member sender = memberRepository.findByIdAndDeleted(id, false)
.orElseThrow(() -> BusinessException.of(MEMBER_NOT_FOUND));

Tteokguk supportedTteokguk = tteokgukRepository.findById(request.tteokgukId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public TteokgukResponse createTteokguk(
Long id,
CreateTteokgukRequest request
) {
Member member = memberRepository.findById(id)
Member member = memberRepository.findByIdAndDeleted(id, false)
.orElseThrow(() -> BusinessException.of(MEMBER_NOT_FOUND));

List<Ingredient> ingredients = Ingredient.toIngredients(request.ingredients());
Expand All @@ -59,7 +59,7 @@ public void deleteTteokguk(
Long id,
Long tteokgukId
) {
Member member = memberRepository.findById(id)
Member member = memberRepository.findByIdAndDeleted(id, false)
.orElseThrow(() -> BusinessException.of(MEMBER_NOT_FOUND));

Tteokguk tteokguk = member.getTteokguks().stream()
Expand All @@ -74,7 +74,7 @@ public TteokgukResponse useIngredients(
Long id,
IngredientRequest request
) {
Member member = memberRepository.findById(id)
Member member = memberRepository.findByIdAndDeleted(id, false)
.orElseThrow(() -> BusinessException.of(MEMBER_NOT_FOUND));

Tteokguk tteokguk = member.getTteokguks()
Expand Down Expand Up @@ -114,7 +114,7 @@ public Page<TteokgukResponse> findCompletionTteokguks(PageableRequest request) {
}

public TteokgukResponse getTteokguk(Long tteokgukId) {
Tteokguk tteokguk = tteokgukRepository.findById(tteokgukId)
Tteokguk tteokguk = tteokgukRepository.findByIdAndDeleted(tteokgukId, false)
.orElseThrow(() -> BusinessException.of(TTEOKGUK_NOT_FOUND));

if (!tteokguk.isAccess()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
import org.springframework.transaction.annotation.Transactional;

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

@Transactional
public interface TteokgukRepository extends JpaRepository<Tteokguk, Long> {

Optional<Tteokguk> findByIdAndDeleted(Long id, boolean deleted);

@Query("SELECT t FROM Tteokguk t WHERE t.access = true and t.member.deleted = false and t.completion = false ORDER BY t.id DESC")
List<Tteokguk> findNewTteokguks(Pageable pageable);

Expand Down

0 comments on commit dbd5a3d

Please sign in to comment.