Skip to content

권세빈 1주차 과제 #10

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
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

sebeeeen
Copy link

@sebeeeen sebeeeen commented Oct 2, 2024

이미지 2024  10  2  오전 11 33

Comment on lines +18 to +28
@Column(name = "School_id")
private Long id;

@Column(name = "School_name")
private String schoolName;

@Column(name = "Total_students")
private int totalStudents;

@Column(name = "Average_grade")
private double averageGrade;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘 작성해주셨습니다!
틀린 것은 아니지만! 관례상 자주 사용되는 패턴이 있습니다.
MySQL에서는 Column 이름을 snake_case로 작성하는 것이 일반적입니다.
실제로도 @Column(name = ~)를 생략하게 되면, 이를 snake_case로 변경하여 DB에 생성합니다.
그리고 table명_id 구조로 PK를 작성하는 편이기도 합니다.
따라서 아래처럼 써보시는 것이 어떠할까 싶네용

Suggested change
@Column(name = "School_id")
private Long id;
@Column(name = "School_name")
private String schoolName;
@Column(name = "Total_students")
private int totalStudents;
@Column(name = "Average_grade")
private double averageGrade;
@Column(name = "school_id")
private Long id;
@Column(name = "school_name")
private String schoolName;
@Column(name = "total_students")
private int totalStudents;
@Column(name = "average_grade")
private double averageGrade;

Comment on lines +59 to +82
@DisplayName("SchoolName과 TotalStudent를 이용한 찾기")
@Test
void testFindBySchoolNameAndTotalStudents() {
// Given
School school1 = School.builder()
.schoolName("아주대학교")
.totalStudents(13884)
.averageGrade(4.3)
.build();
School school2 = School.builder()
.schoolName("서울대학교")
.totalStudents(35000)
.averageGrade(4.0)
.build();
schoolRepository.saveAll(List.of(school1, school2));

// When
School result1 = schoolRepository.findBySchoolNameAndTotalStudents("아주대학교", 13884);
School result2 = schoolRepository.findBySchoolNameAndTotalStudents("서울대학교", 35000);

// Then.
Assertions.assertThat(result1).isNotNull();
Assertions.assertThat(result2.getSchoolName()).isEqualTo("서울대학교");
Assertions.assertThat(result2.getTotalStudents()).isEqualTo(35000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

너무 깔끔합니다. LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants