-
Notifications
You must be signed in to change notification settings - Fork 14
권세빈 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
sebeeeen
wants to merge
6
commits into
doit-web-study:main
Choose a base branch
from
sebeeeen: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.
+125
−147
Open
권세빈 1주차 과제 #10
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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 was deleted.
Oops, something went wrong.
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,36 @@ | ||
package doit.jpastudy2.repository; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor | ||
@Getter | ||
public class School { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@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; | ||
|
||
@Builder | ||
public School(String schoolName, int totalStudents, double averageGrade) { | ||
this.schoolName = schoolName; | ||
this.totalStudents = totalStudents; | ||
this.averageGrade = averageGrade; | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
spring.application.name=jpastudy2 | ||
spring.application.name=jpastudy2 |
108 changes: 0 additions & 108 deletions
108
src/test/java/doit/jpastudy2/repository/CategoryRepositoryTest.java
This file was deleted.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
src/test/java/doit/jpastudy2/repository/SchoolRepositoryTest.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,84 @@ | ||
package doit.jpastudy2.repository; | ||
|
||
import java.util.List; | ||
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 org.springframework.transaction.annotation.Transactional; | ||
|
||
|
||
@Transactional | ||
@SpringBootTest | ||
class SchoolRepositoryTest { | ||
|
||
@Autowired | ||
private SchoolRepository schoolRepository; | ||
|
||
@DisplayName("save 테스트") | ||
@Test | ||
void test() { | ||
// Given | ||
School school = School.builder() | ||
.schoolName("아주대학교") | ||
.totalStudents(13884) | ||
.averageGrade(4.3) | ||
.build(); | ||
|
||
// When | ||
schoolRepository.save(school); | ||
|
||
// Then | ||
Assertions.assertThat(school).isNotNull(); | ||
Assertions.assertThat(school.getSchoolName()).isEqualTo("아주대학교"); | ||
Assertions.assertThat(school.getTotalStudents()).isEqualTo(13884); | ||
} | ||
|
||
@DisplayName("SchoolName을 이용한 찾기") | ||
@Test | ||
void testFindBySchoolName() { | ||
// Given | ||
School school = School.builder() | ||
.schoolName("아주대학교") | ||
.totalStudents(13884) | ||
.averageGrade(4.3) | ||
.build(); | ||
|
||
schoolRepository.save(school); | ||
|
||
// When | ||
School result = schoolRepository.findBySchoolName("아주대학교"); | ||
|
||
// Then | ||
Assertions.assertThat(result).isNotNull(); | ||
Assertions.assertThat(result.getSchoolName()).isEqualTo("아주대학교"); | ||
Assertions.assertThat(result.getTotalStudents()).isEqualTo(13884); | ||
} | ||
|
||
@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); | ||
Comment on lines
+59
to
+82
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. 너무 깔끔합니다. LGTM |
||
} | ||
} |
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.
잘 작성해주셨습니다!
틀린 것은 아니지만! 관례상 자주 사용되는 패턴이 있습니다.
MySQL에서는 Column 이름을 snake_case로 작성하는 것이 일반적입니다.
실제로도
@Column(name = ~)
를 생략하게 되면, 이를 snake_case로 변경하여 DB에 생성합니다.그리고 table명_id 구조로 PK를 작성하는 편이기도 합니다.
따라서 아래처럼 써보시는 것이 어떠할까 싶네용