Skip to content

Commit

Permalink
Feat : AccessService 구현(존재하는 Academy인지 확인 쿼리 및 교육비 조회 쿼리)
Browse files Browse the repository at this point in the history
  • Loading branch information
byeolhaha committed Nov 8, 2023
1 parent 4eb99f4 commit 8ee1dd9
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.guzzing.studayserver.domain.academy.repository;

public interface AcademyFee {

Long getMaxEducationFee();

String getAcademyName();


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.persistence.EntityNotFoundException;
import org.guzzing.studayserver.domain.academy.model.Academy;
import org.guzzing.studayserver.domain.academy.repository.AcademiesByName;
import org.guzzing.studayserver.domain.academy.repository.AcademyFee;
import org.guzzing.studayserver.global.error.response.ErrorCode;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
Expand All @@ -26,4 +27,11 @@ default Academy getById(Long academyId) {
nativeQuery = true)
Slice<AcademiesByName> findAcademiesByName(@Param("academyName") String academyName, Pageable pageable);


@Query("SELECT a.maxEducationFee, a.academyInfo.academyName FROM Academy AS a WHERE a.id = :academyId")
AcademyFee findAcademyFeeInfo(@Param("academyId") Long academyId);

@Query("SELECT CASE WHEN EXISTS (SELECT 1 FROM Academy a WHERE a.id = :academyId) THEN true ELSE false END")
boolean existsByAcademyId(@Param("academyId") Long academyId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import java.util.List;
import org.guzzing.studayserver.domain.academy.model.Academy;
import org.guzzing.studayserver.domain.academy.repository.AcademiesByLocation;
import org.guzzing.studayserver.domain.academy.repository.AcademiesByName;
import org.guzzing.studayserver.domain.academy.repository.AcademyByFiltering;
import org.guzzing.studayserver.domain.academy.repository.AcademyFilterCondition;
import org.guzzing.studayserver.domain.academy.repository.*;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
Expand All @@ -22,4 +20,8 @@ public interface AcademyRepository extends AcademyJpaRepository, AcademyQueryRep
List<AcademiesByLocation> findAcademiesByLocation(String pointFormat);

List<AcademyByFiltering> filterAcademies(AcademyFilterCondition academyFilterCondition);

AcademyFee findAcademyFeeInfo(Long academyId);

boolean existsByAcademyId(Long academyId);
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package org.guzzing.studayserver.domain.academy.service;

import org.guzzing.studayserver.domain.academy.repository.academy.AcademyRepository;
import org.guzzing.studayserver.domain.like.service.dto.response.AcademyFeeInfo;
import org.springframework.stereotype.Service;

@Service
public class AcademyAccessServiceImpl implements
AcademyAccessService {

private final AcademyRepository academyRepository;

public AcademyAccessServiceImpl(AcademyRepository academyRepository) {
this.academyRepository = academyRepository;
}

@Override
public AcademyFeeInfo findAcademyFeeInfo(Long academyId) {
return null;
return AcademyFeeInfo.to(academyRepository.findAcademyFeeInfo(academyId));
}

@Override
public boolean existsAcademy(Long academyId) {
return false;
return academyRepository.existsByAcademyId(academyId);
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package org.guzzing.studayserver.domain.like.service.dto.response;

import org.guzzing.studayserver.domain.academy.repository.AcademyFee;

public record AcademyFeeInfo(
String academyName,
long expectedFee
) {

public static AcademyFeeInfo to(AcademyFee academyFee) {
return new AcademyFeeInfo(
academyFee.getAcademyName(),
academyFee.getMaxEducationFee()
);
}

}

0 comments on commit 8ee1dd9

Please sign in to comment.