-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BE] feat: 회원의 학생 인증 정보 조회 API 구현 (#496) #531
Changes from 2 commits
09e1995
4e3b78e
e5a18c7
3534aa7
8ddcdf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,23 @@ | ||||||||||||||||||||||||
package com.festago.student.dto; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
import com.festago.school.domain.School; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
public record StudentResponse( | ||||||||||||||||||||||||
boolean isVerified, | ||||||||||||||||||||||||
StudentSchoolResponse school | ||||||||||||||||||||||||
) { | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
public static StudentResponse verified(School school) { | ||||||||||||||||||||||||
return new StudentResponse( | ||||||||||||||||||||||||
true, | ||||||||||||||||||||||||
StudentSchoolResponse.from(school) | ||||||||||||||||||||||||
); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
public static StudentResponse notVerified() { | ||||||||||||||||||||||||
return new StudentResponse( | ||||||||||||||||||||||||
false, | ||||||||||||||||||||||||
null | ||||||||||||||||||||||||
); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 인증이 되지 않은 사용자는 해당 정적 메서드를 호출하여 응답을 반환하는군요!
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 글렌이 제안해주신 방법이 캐싱뿐만 아니라 상수 형식으로 빼놓기에 전 '가독성 측면에서도 더 좋을 수 있겠다' 라는 생각도 드네요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오, 가독성과 캐싱 두가지 이점을 모두 챙길 수 있겠군요! 반영하겠습니다 |
||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.festago.student.dto; | ||
|
||
import com.festago.school.domain.School; | ||
|
||
public record StudentSchoolResponse( | ||
Long id, | ||
String schoolName, | ||
String domain | ||
) { | ||
|
||
public static StudentSchoolResponse from(School school) { | ||
return new StudentSchoolResponse( | ||
school.getId(), | ||
school.getName(), | ||
school.getDomain() | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,7 +2,10 @@ | |||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
import com.festago.member.domain.Member; | ||||||||||||||||||||||||||||||
import com.festago.student.domain.Student; | ||||||||||||||||||||||||||||||
import java.util.Optional; | ||||||||||||||||||||||||||||||
import org.springframework.data.jpa.repository.JpaRepository; | ||||||||||||||||||||||||||||||
import org.springframework.data.jpa.repository.Query; | ||||||||||||||||||||||||||||||
import org.springframework.data.repository.query.Param; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
public interface StudentRepository extends JpaRepository<Student, Long> { | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
@@ -11,4 +14,12 @@ public interface StudentRepository extends JpaRepository<Student, Long> { | |||||||||||||||||||||||||||||
boolean existsByUsernameAndSchoolId(String username, Long id); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
boolean existsByMemberId(Long id); | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
@Query(""" | ||||||||||||||||||||||||||||||
SELECT st | ||||||||||||||||||||||||||||||
FROM Student st | ||||||||||||||||||||||||||||||
LEFT JOIN FETCH st.school sc | ||||||||||||||||||||||||||||||
WHERE st.member.id = :memberId | ||||||||||||||||||||||||||||||
""") | ||||||||||||||||||||||||||||||
Optional<Student> findByMemberIdWithFetch(@Param("memberId") Long memberId); | ||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🦅👀
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 또한 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inner join 좋은 아이디어인 것 같아요!! |
||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.festago.student.repository; | ||
|
||
import static org.assertj.core.api.SoftAssertions.assertSoftly; | ||
|
||
import com.festago.member.domain.Member; | ||
import com.festago.member.repository.MemberRepository; | ||
import com.festago.school.domain.School; | ||
import com.festago.school.repository.SchoolRepository; | ||
import com.festago.student.domain.Student; | ||
import com.festago.support.MemberFixture; | ||
import com.festago.support.SchoolFixture; | ||
import com.festago.support.StudentFixture; | ||
import java.util.Optional; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
|
||
@DisplayNameGeneration(ReplaceUnderscores.class) | ||
@SuppressWarnings("NonAsciiCharacters") | ||
@DataJpaTest | ||
class StudentRepositoryTest { | ||
|
||
@Autowired | ||
StudentRepository studentRepository; | ||
|
||
@Autowired | ||
SchoolRepository schoolRepository; | ||
|
||
@Autowired | ||
MemberRepository memberRepository; | ||
|
||
@Test | ||
void 멤버id로_조회() { | ||
// given | ||
Member member = memberRepository.save(MemberFixture.member().build()); | ||
School school = schoolRepository.save(SchoolFixture.school().build()); | ||
Student student = studentRepository.save(StudentFixture.student().school(school).member(member).build()); | ||
|
||
// when | ||
Optional<Student> actual = studentRepository.findByMemberIdWithFetch(member.getId()); | ||
|
||
// then | ||
assertSoftly(softly -> { | ||
softly.assertThat(actual).isNotEmpty(); | ||
softly.assertThat(actual.get().getId()).isEqualTo(student.getId()); | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.festago.support; | ||
|
||
import com.festago.member.domain.Member; | ||
import com.festago.school.domain.School; | ||
import com.festago.student.domain.Student; | ||
|
||
public class StudentFixture { | ||
|
||
private Long id; | ||
private Member member = MemberFixture.member().build(); | ||
private School school = SchoolFixture.school().build(); | ||
private String username = "xxeol2"; | ||
|
||
private StudentFixture() { | ||
} | ||
|
||
public static StudentFixture student() { | ||
return new StudentFixture(); | ||
} | ||
|
||
public StudentFixture id(Long id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public StudentFixture member(Member member) { | ||
this.member = member; | ||
return this; | ||
} | ||
|
||
public StudentFixture school(School school) { | ||
this.school = school; | ||
return this; | ||
} | ||
|
||
public StudentFixture username(String username) { | ||
this.username = username; | ||
return this; | ||
} | ||
|
||
public Student build() { | ||
return new Student(id, member, school, username); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다음과 같이 라인 수를 줄일 수 있을 것 같네요!
물론 선택입니다. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
또한 지금
StudentService
클래스의 필드 수를 보고 있는데 의존하고 있는 객체가 어마무시하네요.이 부분에 대해서는 추후 서비스를 작은 서비스로 분리시켜도 좋을 것 같아요!