-
Notifications
You must be signed in to change notification settings - Fork 14
[고희준] 1주차 과제 #14
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
Open
AJKHJ
wants to merge
1
commit into
doit-web-study:main
Choose a base branch
from
AJKHJ:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[고희준] 1주차 과제 #14
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,41 @@ | ||
package doit.jpastudy2.repository; | ||
|
||
|
||
import jakarta.persistence.*; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor | ||
@Getter | ||
public class Attendant { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
|
||
@Column(name = "n주차") | ||
private int id; | ||
|
||
@Column(name = "이름") | ||
private String name; | ||
|
||
@Column(name = "출석") | ||
private String attendance; | ||
|
||
@Column(name = "지각") | ||
private String late; | ||
|
||
@Column(name = "결석") | ||
private String absence; | ||
|
||
@Builder | ||
public Attendant(String name, String attendance, String late, String absence) { | ||
this.name = name; | ||
this.attendance = attendance; | ||
this.late = late; | ||
this.absence = absence; | ||
} | ||
|
||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/doit/jpastudy2/repository/AttendantRepository.java
This file contains hidden or 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,7 @@ | ||
package doit.jpastudy2.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface AttendantRepository extends JpaRepository<Attendant, Long> { | ||
Attendant findByName(String name); | ||
} |
This file contains hidden or 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,41 @@ | ||
package doit.jpastudy2.repository; | ||
|
||
|
||
import jakarta.persistence.*; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor | ||
@Getter | ||
public class Student { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
|
||
|
||
@Column(name = "학번") | ||
private int id; | ||
|
||
@Column(name = "이름") | ||
private String name; | ||
|
||
@Column(name = "학년") | ||
private int grade; | ||
|
||
@Column(name = "학과") | ||
private String major; | ||
|
||
@Column(name = "메일") | ||
private String email; | ||
|
||
@Builder | ||
public Student(String name, int grade, String major, String email) { | ||
this.name = name; | ||
this.grade = grade; | ||
this.major = major; | ||
this.email = email; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/doit/jpastudy2/repository/StudentRepository.java
This file contains hidden or 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,7 @@ | ||
package doit.jpastudy2.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface StudentRepository extends JpaRepository<Student, Long> { | ||
Student findByEmail(String email); | ||
} |
61 changes: 61 additions & 0 deletions
61
src/test/java/doit/jpastudy2/repository/AttendantRepositoryTest.java
This file contains hidden or 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,61 @@ | ||
package doit.jpastudy2.repository; | ||
|
||
import jakarta.transaction.Transactional; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.util.List; | ||
|
||
@Transactional | ||
@SpringBootTest | ||
class AttendantRepositoryTest { | ||
|
||
@Autowired | ||
private AttendantRepository attendantRepository; | ||
|
||
@DisplayName("save 테스트") | ||
@Test | ||
void test(){ | ||
Attendant atd1 = Attendant.builder() | ||
.attendance("O") | ||
.build(); | ||
|
||
Attendant atd2 = Attendant.builder() | ||
.absence("O") | ||
.build(); | ||
|
||
attendantRepository.save(atd1); | ||
attendantRepository.save(atd2); | ||
|
||
List<Attendant> attendants = attendantRepository.findAll(); | ||
Assertions.assertThat(attendants).hasSize(2); | ||
Assertions.assertThat(attendants.get(0).getAttendance()).isEqualTo("O"); | ||
} | ||
|
||
@Test | ||
void findByName() { | ||
Attendant atd1 = Attendant.builder() | ||
.name("고희준") | ||
.build(); | ||
|
||
Attendant atd2 = Attendant.builder() | ||
.name("준희고") | ||
.build(); | ||
|
||
attendantRepository.saveAll(List.of(atd1, atd2)); | ||
|
||
Attendant result1 = attendantRepository.findByName("희준고"); | ||
Attendant result2 = attendantRepository.findByName("준희고"); | ||
Attendant result3 = attendantRepository.findByName("준희고"); | ||
|
||
Assertions.assertThat(result1).isNull(); | ||
Assertions.assertThat(result2).isNotNull(); | ||
Assertions.assertThat(result3.getName()).isEqualTo("준희고"); | ||
|
||
|
||
|
||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/test/java/doit/jpastudy2/repository/StudentRepositoryTest.java
This file contains hidden or 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,54 @@ | ||
package doit.jpastudy2.repository; | ||
|
||
import jakarta.transaction.Transactional; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.util.List; | ||
|
||
@Transactional | ||
@SpringBootTest | ||
class StudentRepositoryTest { | ||
|
||
@Autowired | ||
private StudentRepository studentRepository; | ||
|
||
@Test | ||
void test(){ | ||
Student student1 = Student.builder() | ||
.grade(4) | ||
.major("사이버보안학과") | ||
.build(); | ||
|
||
studentRepository.save(student1); | ||
|
||
List<Student> students = studentRepository.findAll(); | ||
Assertions.assertThat(students).hasSize(1); | ||
Assertions.assertThat(students.get(0).getGrade()).isEqualTo(4); | ||
} | ||
@Test | ||
void findByEmail() { | ||
Student student1 = Student.builder() | ||
.grade(4) | ||
.email("[email protected]") | ||
.build(); | ||
|
||
Student student2 = Student.builder() | ||
.grade(3) | ||
.email("[email protected]") | ||
.build(); | ||
|
||
studentRepository.save(student1); | ||
studentRepository.save(student2); | ||
|
||
Student result1 = studentRepository.findByEmail("[email protected]"); | ||
Student result2 = studentRepository.findByEmail("[email protected]"); | ||
|
||
Assertions.assertThat(result1).isNotNull(); | ||
Assertions.assertThat(result2).isNotNull(); | ||
Assertions.assertThat(result2).isNotEqualTo("[email protected]"); | ||
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
우선 자동으로 할당해주신 점 좋습니다!
n주차라고 작성해주신 것 보니, 아마 1주차에 해당하는 출석들을 모아서 설정하시려는 것 같은데 맞을까요?
맞다면 요 로직보다는 다음과 같이 작성해주시는 편이 좋을 것 같습니다
pk에는 의미가 없는 인공적인 값을 넣어주시는 것이 DB 구조 상 로직 작성하기에 편하실 것 같습니다! 참고하시면 될 것 같아요