-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor: 메서드 네이밍 수정 (verifiacte -> verify) * feat: 학생 인증 정보 조회 기능 구현 * refactor: findByMemberIdWithFetch INNER JOIN으로 수정 * refactor: inner line return 으로 수정 * refactor: 캐싱된 Response 반환
- Loading branch information
1 parent
33e26fa
commit cb887dd
Showing
9 changed files
with
259 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
backend/src/main/java/com/festago/student/dto/StudentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.festago.student.dto; | ||
|
||
import com.festago.school.domain.School; | ||
|
||
public record StudentResponse( | ||
boolean isVerified, | ||
StudentSchoolResponse school | ||
) { | ||
|
||
private static final StudentResponse NOT_VERIFIED = new StudentResponse(false, null); | ||
|
||
public static StudentResponse verified(School school) { | ||
return new StudentResponse( | ||
true, | ||
StudentSchoolResponse.from(school) | ||
); | ||
} | ||
|
||
public static StudentResponse notVerified() { | ||
return NOT_VERIFIED; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/com/festago/student/dto/StudentSchoolResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
backend/src/test/java/com/festago/student/repository/StudentRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
}); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
backend/src/test/java/com/festago/support/StudentFixture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |