1. 테스트에 앞서 필요한 데이터베이스 테이블 생성 (수정된 테이블은 수정된 create문이 아닌 update문을 덧붙인 형태로
첨부하였다 이런 코드가 학습하기 더 좋을 것 같다!)
CREATE DATABASE refactorlibrary
use refactorlibrary
CREATE TABLE user(
id BIGINT AUTO_INCREMENT,
name VARCHAR(25) NOT NULL,
age INT,
phone VARCHAR(15),
join_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
);
//테이블 수정
ALTER TABLE user
MODIFY phone VARCHAR(15) NOT NULL;
//테이블 수정
ALTER TABLE user
MODIFY age INT NOT NULL;
---
CREATE TABLE book(
id BIGINT AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
writer VARCHAR(255),
regi_date TIMESTAMP DEFAULT CURREMT_TIMESTAMP,
PRIMARY KEY (id)
);
---
CREATE TABLE user_loan_history(
id BIGINT AUTO_INCREMENT,
user_id BIGINT NOT NULL,
book_id BIGINT NOT NULL,
loan_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
return_date TIMESTAMP,
PRIMARY KEY (id)
);
- spring initialize
- IntelliJ의 open file or project로 spring initializer 에서 다운로드 받은 프로젝트를 압축 푼 후 연다
파일구성 ( 일단 패키지 기본 구조는 저거임)
- build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.17'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '11'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
- application.yml
server:
port: 8090
spring:
datasource:
url: "jdbc:mysql://localhost/refactorlibrary"
username: "root"
password: "비밀번호"
driver-class-name : com.mysql.cj.jdbc.Driver
Entity class 생성한후 Repository 에서 사용할 때 참고하면 좋은 점
Repository class 메소드에서 매개변수로 Entitny Class를 통째로 넣어주면
코드를 줄일 수 있다!
Service 에 필요한 메소드를 목록으로만 뽑아보자!!
[UserServicce]
1 createUser
2 updateUser
3 deleteUser
4 userList
5 searchUser
[Book]
1 registBook
2 updateBook
3 deleteBook
4 bookList
5 searchBook
[대출]
1 loanBook
2 returnBook
3 historyList
4 searchHistory
Repository에 쿼리문에 대응되는 메소드를 목록으로만 뽑아보자!
[UserRepository]
1. 존재하는 회원인지 - 연락처로 조회
2. 회원 등록 (기존)
3. 회원 수정 (기존)
4. 회원 삭제 (기존)
5. 회원 리스트 출력
6. 회원 검색
[BookReposiotry]
1 존재하는 책인지
2 책 등록 (기존)
3 책 수정 (기존)
4 책 삭제 (기존)
5 책 리스트 출력
6.책 검색
[UserLoanHistoryRepository]
1 현재 대출상태인지 확인
3 대출 등록 (기존)
4 반납 처리
5 대출&반납 이력 출력 - userId 와 bookId 로
6 대출&반납 기록 검색
<< ※ 검색 기능은 일괄적으로 맨 마지막에 처리할 예정 >>
'도서 관리 앱 2 (1의 리팩토링+버전업)' 카테고리의 다른 글
도서 관리 시스템 ver.2 깃허브 업로드 with 인텔리제이 (0) | 2023.12.12 |
---|---|
리팩토링+버전업#4 도서 관리 app - 도서 등록, 도서 수정, 도서 삭제 (0) | 2023.11.05 |
리팩토링+버전업#3 도서 관리 app - 사용자 정보 출력, 수정, 삭제 (0) | 2023.11.04 |
리팩토링+버전업#2 도서 관리 app - 파일 구조 잡기 + 사용자 등록 (0) | 2023.11.03 |