-
Notifications
You must be signed in to change notification settings - Fork 301
π 3λ¨κ³ - μκ°μ μ²(DB μ μ©) #756
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
base: gukin-han
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package nextstep.courses.domain; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public class EnrolledStudent { | ||
private Long id; | ||
|
||
private String userId; | ||
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. κ°μ²΄μ§ν₯μ μΌλ‘ Userλ₯Ό κ°μ§κ³ μκ² νλ©΄ μ΄λ¨κΉμ? |
||
|
||
private Session session; | ||
|
||
private LocalDateTime enrolledAt; | ||
|
||
public EnrolledStudent(String userId, Session session, LocalDateTime enrolledAt) { | ||
this.userId = userId; | ||
this.session = session; | ||
this.enrolledAt = enrolledAt; | ||
} | ||
|
||
public EnrolledStudent(Long id, String userId, Session session, LocalDateTime enrolledAt) { | ||
this.id = id; | ||
this.userId = userId; | ||
this.session = session; | ||
this.enrolledAt = enrolledAt; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getUserId() { | ||
return userId; | ||
} | ||
|
||
public Session getSession() { | ||
return session; | ||
} | ||
|
||
public LocalDateTime getEnrolledAt() { | ||
return enrolledAt; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package nextstep.courses.domain; | ||
|
||
public interface EnrolledStudentRepository { | ||
void save(EnrolledStudent enrolledStudent); | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package nextstep.courses.infrastructure; | ||
|
||
import nextstep.courses.domain.EnrolledStudent; | ||
import nextstep.courses.domain.EnrolledStudentRepository; | ||
import org.springframework.jdbc.core.JdbcOperations; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public class JdbcEnrolledStudentRepository implements EnrolledStudentRepository { | ||
|
||
private final JdbcOperations jdbcTemplate; | ||
|
||
public JdbcEnrolledStudentRepository(JdbcOperations jdbcTemplate) { | ||
this.jdbcTemplate = jdbcTemplate; | ||
} | ||
|
||
@Override | ||
public void save(EnrolledStudent enrolledStudent) { | ||
String sql = "INSERT INTO enrolled_student (session_id, user_id, enrolled_at) VALUES (?, ?, ?)"; | ||
jdbcTemplate.update( | ||
sql, | ||
enrolledStudent.getSession().getId(), // session κ°μ²΄μμ id κΊΌλ | ||
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. λλ―Έν°μ λ²μΉμ μλ°νκ² κ°μ΅λλ€. |
||
enrolledStudent.getId(), | ||
enrolledStudent.getEnrolledAt() | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package nextstep.courses.infrastructure; | ||
|
||
import nextstep.courses.domain.*; | ||
import org.springframework.jdbc.core.JdbcOperations; | ||
import org.springframework.jdbc.core.RowMapper; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.sql.Timestamp; | ||
import java.time.LocalDateTime; | ||
|
||
@Repository | ||
public class JdbcSessionRepository implements SessionRepository { | ||
|
||
private final JdbcOperations jdbcTemplate; | ||
|
||
public JdbcSessionRepository(JdbcOperations jdbcTemplate) { | ||
this.jdbcTemplate = jdbcTemplate; | ||
} | ||
|
||
@Override | ||
public Session findById(Long sessionId) { | ||
String sql = "SELECT id, created_at, updated_at, cover_image_size, cover_image_type, cover_image_width, cover_image_height, session_type, session_status, price, capacity FROM session WHERE id = ?"; | ||
return jdbcTemplate.queryForObject(sql, sessionRowMapper(), sessionId); | ||
} | ||
|
||
private RowMapper<Session> sessionRowMapper() { | ||
return (rs, rowNum) -> { | ||
CoverImage coverImage = new CoverImage( | ||
rs.getInt("cover_image_size"), | ||
ImageType.valueOf(rs.getString("cover_image_type")), | ||
rs.getInt("cover_image_width"), | ||
rs.getInt("cover_image_height") | ||
); | ||
Comment on lines
+28
to
+33
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. CoverImageκ° μ¬μ¬μ©λ μΌμ΄ μμκΉμ? |
||
return new Session( | ||
rs.getLong("id"), | ||
toLocalDateTime(rs.getTimestamp("created_at")), | ||
toLocalDateTime(rs.getTimestamp("updated_at")), | ||
coverImage, | ||
SessionType.valueOf(rs.getString("session_type")), | ||
SessionStatus.valueOf(rs.getString("session_status")), | ||
rs.getLong("price"), | ||
rs.getObject("capacity", Long.class) | ||
); | ||
}; | ||
} | ||
|
||
private LocalDateTime toLocalDateTime(Timestamp timestamp) { | ||
if (timestamp == null) { | ||
return null; | ||
} | ||
return timestamp.toLocalDateTime(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
INSERT INTO ns_user (id, user_id, password, name, email, created_at) values (1, 'javajigi', 'test', 'μλ°μ§κΈ°', '[email protected]', CURRENT_TIMESTAMP()); | ||
INSERT INTO ns_user (id, user_id, password, name, email, created_at) values (2, 'sanjigi', 'test', 'μ°μ§κΈ°', '[email protected]', CURRENT_TIMESTAMP()); | ||
INSERT INTO ns_user (id, user_id, password, name, email, created_at) | ||
values (1, 'javajigi', 'test', 'μλ°μ§κΈ°', '[email protected]', CURRENT_TIMESTAMP()); | ||
INSERT INTO ns_user (id, user_id, password, name, email, created_at) | ||
values (2, 'sanjigi', 'test', 'μ°μ§κΈ°', '[email protected]', CURRENT_TIMESTAMP()); | ||
|
||
INSERT INTO question (id, writer_id, title, contents, created_at, deleted) VALUES (1, 1, 'κ΅λ΄μμ Ruby on Railsμ Playκ° νμ±νλκΈ° νλ μ΄μ λ λκΉ?', 'Ruby on Rails(μ΄ν RoR)λ 2006λ μ¦μμ μ λ§ λ¨κ²κ² λ¬μμ¬λλ€κ° κΈλ°© κ°λΌ μμλ€. Play νλ μμν¬λ μ λ§ ν μκ° μ μ λμ λ¨μ΄λ€κ° μ¬λΌμ Έ λ²λ Έλ€. RoRκ³Ό Play κΈ°λ°μΌλ‘ κ°λ°μ ν΄λ³΄λ©΄ μ λ§ μμ°μ±μ΄ λμΌλ©°, μΉ νλ‘κ·Έλλ°μ΄ μ¬λ―ΈμκΈ°κΉμ§ νλ€. Spring MVC + JPA(Hibernate) κΈ°λ°μΌλ‘ μ§ννλ©΄ μ€μ ν λΆλΆλ λ§κ³ , κΈ°λ³ΈμΌλ‘ μ§μνμ§ μλ κΈ°λ₯λ λ§μ RoRκ³Ό Playμμ κΈ°λ³Έμ μΌλ‘ μ§μνλ κΈ°λ₯μ μλΉμ€νλ €λ©΄ μΆκ°μ μΈ κ°λ°μ΄ νμνλ€.', CURRENT_TIMESTAMP(), false); | ||
INSERT INTO question (id, writer_id, title, contents, created_at, deleted) | ||
VALUES (1, 1, 'κ΅λ΄μμ Ruby on Railsμ Playκ° νμ±νλκΈ° νλ μ΄μ λ λκΉ?', | ||
'Ruby on Rails(μ΄ν RoR)λ 2006λ μ¦μμ μ λ§ λ¨κ²κ² λ¬μμ¬λλ€κ° κΈλ°© κ°λΌ μμλ€. Play νλ μμν¬λ μ λ§ ν μκ° μ μ λμ λ¨μ΄λ€κ° μ¬λΌμ Έ λ²λ Έλ€. RoRκ³Ό Play κΈ°λ°μΌλ‘ κ°λ°μ ν΄λ³΄λ©΄ μ λ§ μμ°μ±μ΄ λμΌλ©°, μΉ νλ‘κ·Έλλ°μ΄ μ¬λ―ΈμκΈ°κΉμ§ νλ€. Spring MVC + JPA(Hibernate) κΈ°λ°μΌλ‘ μ§ννλ©΄ μ€μ ν λΆλΆλ λ§κ³ , κΈ°λ³ΈμΌλ‘ μ§μνμ§ μλ κΈ°λ₯λ λ§μ RoRκ³Ό Playμμ κΈ°λ³Έμ μΌλ‘ μ§μνλ κΈ°λ₯μ μλΉμ€νλ €λ©΄ μΆκ°μ μΈ κ°λ°μ΄ νμνλ€.', | ||
CURRENT_TIMESTAMP(), false); | ||
|
||
INSERT INTO answer (writer_id, contents, created_at, question_id, deleted) VALUES (1, 'http://underscorejs.org/docs/underscore.html Underscore.js κ°μΆν©λλ€! μΈμΌλ λ§κ³ , μ½λλ κΈΈμ§ μκ³ , μλ°μ€ν¬λ¦½νΈμ μΈμ΄λ κΈ°λ³Έ APIλ₯Ό 보μνλ κΈ°λ₯λ€μ΄λΌ μλ°μ€ν¬λ¦½νΈ μ΄ν΄μ λμμ΄ λ©λλ€. 무μλ³΄λ€ λΌμ΄λΈλ¬λ¦¬ μμ²΄κ° μμ£Ό μ μ©ν©λλ€.', CURRENT_TIMESTAMP(), 1, false); | ||
INSERT INTO answer (writer_id, contents, created_at, question_id, deleted) | ||
VALUES (1, | ||
'http://underscorejs.org/docs/underscore.html Underscore.js κ°μΆν©λλ€! μΈμΌλ λ§κ³ , μ½λλ κΈΈμ§ μκ³ , μλ°μ€ν¬λ¦½νΈμ μΈμ΄λ κΈ°λ³Έ APIλ₯Ό 보μνλ κΈ°λ₯λ€μ΄λΌ μλ°μ€ν¬λ¦½νΈ μ΄ν΄μ λμμ΄ λ©λλ€. 무μλ³΄λ€ λΌμ΄λΈλ¬λ¦¬ μμ²΄κ° μμ£Ό μ μ©ν©λλ€.', | ||
CURRENT_TIMESTAMP(), 1, false); | ||
|
||
INSERT INTO answer (writer_id, contents, created_at, question_id, deleted) VALUES (2, 'μΈλμ€μ½μ΄ κ°λ ₯ μΆμ²λλ €μ. λ€λ§ μ΅μ λ²μ μ 곡λΆνλ κ²λ³΄λ€λ 0.10.0 λ²μ λΆν° 보λκ² λ μ’λκ΅°μ. μ½λμ λ³μ²μ¬λ μ μ μκ³ , μ΅μ νλμ§ μμ μ½λλ€μ΄ κΈ°λ₯μ κ·Έλλ‘ λκ³ μ΅μ νλμ΄ κ°λ κ±Έ 보면 μ¬λ―Έκ° μμ΅λλ€ :)', CURRENT_TIMESTAMP(), 1, false); | ||
INSERT INTO answer (writer_id, contents, created_at, question_id, deleted) | ||
VALUES (2, | ||
'μΈλμ€μ½μ΄ κ°λ ₯ μΆμ²λλ €μ. λ€λ§ μ΅μ λ²μ μ 곡λΆνλ κ²λ³΄λ€λ 0.10.0 λ²μ λΆν° 보λκ² λ μ’λκ΅°μ. μ½λμ λ³μ²μ¬λ μ μ μκ³ , μ΅μ νλμ§ μμ μ½λλ€μ΄ κΈ°λ₯μ κ·Έλλ‘ λκ³ μ΅μ νλμ΄ κ°λ κ±Έ 보면 μ¬λ―Έκ° μμ΅λλ€ :)', | ||
CURRENT_TIMESTAMP(), 1, false); | ||
|
||
INSERT INTO question (id, writer_id, title, contents, created_at, deleted) VALUES (2, 2, 'runtime μ reflect λ°λ 주체 κ°μ²΄κ° λμ§ μ λ°©λ²μ΄ μμκΉμ?', 'μ€κ³λ₯Ό ν¬ννκ² νλ λ°λμ κΌ¬μΈ λ¬Έμ κ°κΈ΄ ν©λλ€λ§. μ¬μμ΅λλ€. μν©μ mybatis select μ€νλ μμ return object μ getter κ° νΈμΆλλ©΄μμΈλ°μ. getter μμ λ€λ₯Έ property μ μμ‘΄μ€μΈ μ½λκ° μ½μ λμ΄ μμ΄μ, λ§μ½ λ€λ₯Έ mybatis select ꡬ문μ ν΄λΉ property κ° μλ€λ©΄ exception μ΄ λ°μνκ² λ©λλ€.', CURRENT_TIMESTAMP(), false); | ||
INSERT INTO question (id, writer_id, title, contents, created_at, deleted) | ||
VALUES (2, 2, 'runtime μ reflect λ°λ 주체 κ°μ²΄κ° λμ§ μ λ°©λ²μ΄ μμκΉμ?', | ||
'μ€κ³λ₯Ό ν¬ννκ² νλ λ°λμ κΌ¬μΈ λ¬Έμ κ°κΈ΄ ν©λλ€λ§. μ¬μμ΅λλ€. μν©μ mybatis select μ€νλ μμ return object μ getter κ° νΈμΆλλ©΄μμΈλ°μ. getter μμ λ€λ₯Έ property μ μμ‘΄μ€μΈ μ½λκ° μ½μ λμ΄ μμ΄μ, λ§μ½ λ€λ₯Έ mybatis select ꡬ문μ ν΄λΉ property κ° μλ€λ©΄ exception μ΄ λ°μνκ² λ©λλ€.', | ||
CURRENT_TIMESTAMP(), false); | ||
|
||
insert into session (id, created_at, updated_at, cover_image_size, cover_image_type, cover_image_width, | ||
cover_image_height, session_type, session_status, price, capacity) | ||
values (1, now(), now(), 500000, 'JPG', 450, 300, 'PAID', 'OPEN', 10000, 100); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,80 @@ | ||
create table course ( | ||
id bigint generated by default as identity, | ||
title varchar(255) not null, | ||
creator_id bigint not null, | ||
created_at timestamp not null, | ||
create table course | ||
( | ||
id bigint generated by default as identity, | ||
title varchar(255) not null, | ||
creator_id bigint not null, | ||
created_at timestamp not null, | ||
updated_at timestamp, | ||
primary key (id) | ||
); | ||
|
||
create table ns_user ( | ||
id bigint generated by default as identity, | ||
user_id varchar(20) not null, | ||
password varchar(20) not null, | ||
name varchar(20) not null, | ||
email varchar(50), | ||
created_at timestamp not null, | ||
create table ns_user | ||
( | ||
id bigint generated by default as identity, | ||
user_id varchar(20) not null, | ||
password varchar(20) not null, | ||
name varchar(20) not null, | ||
email varchar(50), | ||
created_at timestamp not null, | ||
updated_at timestamp, | ||
primary key (id) | ||
); | ||
|
||
create table question ( | ||
id bigint generated by default as identity, | ||
created_at timestamp not null, | ||
create table question | ||
( | ||
id bigint generated by default as identity, | ||
created_at timestamp not null, | ||
updated_at timestamp, | ||
contents clob, | ||
deleted boolean not null, | ||
title varchar(100) not null, | ||
writer_id bigint, | ||
deleted boolean not null, | ||
title varchar(100) not null, | ||
writer_id bigint, | ||
primary key (id) | ||
); | ||
|
||
create table answer ( | ||
id bigint generated by default as identity, | ||
created_at timestamp not null, | ||
updated_at timestamp, | ||
create table answer | ||
( | ||
id bigint generated by default as identity, | ||
created_at timestamp not null, | ||
updated_at timestamp, | ||
contents clob, | ||
deleted boolean not null, | ||
deleted boolean not null, | ||
question_id bigint, | ||
writer_id bigint, | ||
writer_id bigint, | ||
primary key (id) | ||
); | ||
|
||
create table delete_history ( | ||
id bigint not null, | ||
content_id bigint, | ||
content_type varchar(255), | ||
created_date timestamp, | ||
create table delete_history | ||
( | ||
id bigint not null, | ||
content_id bigint, | ||
content_type varchar(255), | ||
created_date timestamp, | ||
deleted_by_id bigint, | ||
primary key (id) | ||
); | ||
|
||
create table session | ||
( | ||
id bigint generated by default as identity, | ||
created_at timestamp not null, | ||
updated_at timestamp, | ||
cover_image_size int not null, | ||
cover_image_type varchar(20) not null, | ||
cover_image_width int not null, | ||
cover_image_height int not null, | ||
session_type varchar(20) not null, | ||
session_status varchar(20) not null, | ||
price bigint not null, | ||
capacity bigint, | ||
primary key (id) | ||
); | ||
|
||
create table enrolled_student | ||
( | ||
id bigint generated by default as identity, | ||
session_id bigint not null, | ||
user_id varchar(20) not null, | ||
enrolled_at timestamp not null, | ||
primary key (id) | ||
); |
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.
κ΅³μ΄ Enrolledλ₯Ό λΆμΌ μ΄μ κ° μμκΉμ?
Studentλ‘λ§μΌλ‘λ μΆ©λΆν λλ©μΈ μ€λͺ μ΄ κ°λ₯ν΄ λ³΄μ¬μμ~