-
Notifications
You must be signed in to change notification settings - Fork 14
강수빈 1주차 과제 #11
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
gae-ddong
wants to merge
2
commits into
doit-web-study:main
Choose a base branch
from
gae-ddong: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주차 과제 #11
Changes from all commits
Commits
Show all changes
2 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
17 changes: 0 additions & 17 deletions
17
src/main/java/doit/jpastudy2/repository/CategoryRepository.java
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,35 @@ | ||
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 Professor { | ||
|
||
@Id // PK임을 나타낸다. | ||
@GeneratedValue(strategy = GenerationType.AUTO) // 자동 생성되는 값임을 나타낸다. | ||
@Column(name = "prof_id") // 컬럼명을 지정한다. | ||
private Long id; | ||
|
||
// @Column(name = "type")이 생략된 경우 필드명이 컬럼명이 된다. snake_case로 변환된다. | ||
@Column(name = "prof_name") | ||
private String name; | ||
|
||
// @Column(name = "description")이 생략된 경우 필드명이 컬럼명이 된다. | ||
@Column(name = "prof_email") | ||
private String email; | ||
|
||
@Builder // 빌더 패턴을 사용할 수 있게 한다. | ||
public Professor(String name, String email) { | ||
this.name = name; | ||
this.email = email; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/doit/jpastudy2/repository/ProfessorRepository.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,10 @@ | ||
package doit.jpastudy2.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ProfessorRepository extends JpaRepository<Professor, Long> { | ||
Professor findByEmail(String email); | ||
Professor findByName(String name); | ||
Comment on lines
+6
to
+7
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. 규칙 지켜서 잘 작성해주셨습니다!
위의 쿼리 메소드와 비교해서, 이 메소드에 대해서 항상 유일하게 Professor 개체가 1개만 나오는가?를 고려해보신 뒤에
|
||
|
||
Professor findByNameAndEmail(String name, String email); | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/main/java/doit/jpastudy2/repository/SubjectsRepository.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,10 @@ | ||
package doit.jpastudy2.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface SubjectsRepository extends JpaRepository<Subjects, Long> { | ||
Subjects findByUnit(String unit); | ||
Subjects findByName(String name); | ||
|
||
Subjects findByNameAndUnit(String name, String unit); | ||
} |
108 changes: 0 additions & 108 deletions
108
src/test/java/doit/jpastudy2/repository/CategoryRepositoryTest.java
This file was deleted.
Oops, something went wrong.
121 changes: 121 additions & 0 deletions
121
src/test/java/doit/jpastudy2/repository/ProfessorRepositoryTest.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,121 @@ | ||
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 ProfessorRepositoryTest { | ||
@Autowired | ||
private ProfessorRepository professorRepository; | ||
|
||
@DisplayName("save test") | ||
@Test | ||
void test(){ | ||
Professor professor1 = Professor.builder() | ||
.name("노병희") | ||
.email("[email protected]") | ||
.build(); | ||
Professor professor2 = Professor.builder() | ||
.name("조현석") | ||
.email("[email protected]") | ||
.build(); | ||
Professor professor3 = Professor.builder() | ||
.name("이슬") | ||
.email("[email protected]") | ||
.build(); | ||
Professor professor4 = Professor.builder() | ||
.name("변광준") | ||
.email("[email protected]") | ||
.build(); | ||
|
||
professorRepository.save(professor1); | ||
professorRepository.save(professor2); | ||
professorRepository.save(professor3); | ||
professorRepository.save(professor4); | ||
|
||
List<Professor> professors = professorRepository.findAll(); | ||
Assertions.assertThat(professors).hasSize(4); | ||
Assertions.assertThat(professors.get(2).getName()).isEqualTo("이슬"); | ||
Assertions.assertThat(professors.get(2).getEmail()).isEqualTo("[email protected]"); | ||
|
||
System.out.println("2번째 교수 이름 : " + professors.get(2).getName()); | ||
} | ||
|
||
@DisplayName("Name을 이용한 조회") | ||
@Test | ||
void findByName(){ | ||
Professor professor1 = Professor.builder() | ||
.name("노병희") | ||
.email("[email protected]") | ||
.build(); | ||
Professor professor2 = Professor.builder() | ||
.name("조현석") | ||
.email("[email protected]") | ||
.build(); | ||
Professor professor3 = Professor.builder() | ||
.name("이슬") | ||
.email("[email protected]") | ||
.build(); | ||
Professor professor4 = Professor.builder() | ||
.name("변광준") | ||
.email("[email protected]") | ||
.build(); | ||
|
||
professorRepository.save(professor1); | ||
professorRepository.save(professor2); | ||
professorRepository.save(professor3); | ||
professorRepository.save(professor4); | ||
|
||
Professor result1 = professorRepository.findByName("노병희"); | ||
Professor result2 = professorRepository.findByName("조현석"); | ||
|
||
Assertions.assertThat(result1).isNull(); | ||
Assertions.assertThat(result2).isNotNull(); | ||
Assertions.assertThat(result2.getName()).isEqualTo("노병희"); | ||
} | ||
|
||
// @DisplayName("description과 type을 이용한 조회") | ||
// @Test | ||
// void findByTypeAndDescription() { | ||
// // Given | ||
// Category category1 = Category.builder() | ||
// .type("양식") | ||
// .description("데이트") | ||
// .build(); | ||
// | ||
// Category category2 = Category.builder() | ||
// .type("한식") | ||
// .description("한국인의 정") | ||
// .build(); | ||
// | ||
// Category category3 = Category.builder() | ||
// .type("중식") | ||
// .description("철가방") | ||
// .build(); | ||
// | ||
// Category category4 = Category.builder() | ||
// .type("미식") | ||
// .description("축구ㅋㅋ") | ||
// .build(); | ||
// | ||
// categoryRepository.saveAll(List.of(category1, category2, category3, category4)); | ||
// | ||
// // When | ||
// Category result1 = categoryRepository.findByTypeAndDescription("양식", "데이트"); | ||
// Category result2 = categoryRepository.findByTypeAndDescription("중식", "데이트"); // null | ||
// Category result3 = categoryRepository.findByTypeAndDescription("미식", "축구ㅋㅋ"); | ||
// | ||
// // Then | ||
// Assertions.assertThat(result1.getType()).isEqualTo("양식"); | ||
// Assertions.assertThat(result2).isNull(); | ||
// Assertions.assertThat(result3.getDescription()).isEqualTo("축구ㅋㅋ"); | ||
// } | ||
|
||
} |
Oops, something went wrong.
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 용량 차지한다고 DB Column 이름을 줄여서 사용하곤 했는데, 요즘은 그냥 이름 길게길게 사용하는게 일반적이라고 하더라구요. 물론 이건 어디나 프로젝트 바이 프로젝트이니, 참고만 하시면 될 것 같습니다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.
엥 이거 왜 줄이 그어지지
일부로 그은거 아닙니다..