55import com .moplus .moplus_server .global .error .exception .ErrorCode ;
66import com .moplus .moplus_server .global .error .exception .NotFoundException ;
77import java .util .Optional ;
8+ import org .slf4j .Logger ;
9+ import org .slf4j .LoggerFactory ;
810import org .springframework .data .jpa .repository .JpaRepository ;
911import org .springframework .data .jpa .repository .Query ;
1012import org .springframework .data .repository .query .Param ;
1113
1214public interface ProblemRepository extends JpaRepository <Problem , Long > {
1315
16+ Logger log = LoggerFactory .getLogger (ProblemRepository .class );
17+
1418 boolean existsByProblemCustomId (ProblemCustomId problemCustomId );
1519
1620 default void existsByIdElseThrow (Long id ) {
@@ -25,11 +29,18 @@ default void existsByIdElseThrow(Long id) {
2529 Optional <Problem > findByIdWithFetchJoin (@ Param ("id" ) Long id );
2630
2731 default Problem findByIdElseThrow (Long id ) {
32+
2833 return findById (id ).orElseThrow (
29- () -> new NotFoundException (ErrorCode .PROBLEM_NOT_FOUND , id + "번 문제가 존재하지 않습니다." ));
34+ () -> {
35+ log .atError ().log ("id " + id + "번 문항이 존재하지 않습니다." );
36+ throw new NotFoundException (ErrorCode .PROBLEM_NOT_FOUND );
37+ });
3038 }
3139
3240 default Problem findByIdWithFetchJoinElseThrow (Long id ) {
33- return findByIdWithFetchJoin (id ).orElseThrow (() -> new NotFoundException (ErrorCode .PROBLEM_NOT_FOUND ));
41+ return findByIdWithFetchJoin (id ).orElseThrow (() -> {
42+ log .atError ().log ("id " + id + "번 문항이 존재하지 않습니다." );
43+ throw new NotFoundException (ErrorCode .PROBLEM_NOT_FOUND );
44+ });
3445 }
3546}
0 commit comments