-
Notifications
You must be signed in to change notification settings - Fork 7
3주차 구현과제 제출합니다. #18
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
chunghyeon-kimm
wants to merge
14
commits into
kiworkshop:chunghyeon-kim
Choose a base branch
from
chunghyeon-kimm:chunghyeon-kim
base: chunghyeon-kim
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
3주차 구현과제 제출합니다. #18
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7599254
refactor: Add learning package and move class files to learning package
chunghyeon-kimm 7beed54
feat: Add data.sql, application.properties
chunghyeon-kimm f5fe48f
feat: Add db configs to properties, generate docoument, documentcontr…
chunghyeon-kimm 2245ddc
feat: Add APIs(getdocument, getoutbox)
chunghyeon-kimm 6125001
feat: Add ApproveGenerationRequestDto
chunghyeon-kimm d02bfb2
refactor: Modify h2 config
chunghyeon-kimm 60c1aaa
refactor: Modify RequestMapping
chunghyeon-kimm 1ec42de
refactor: Add domain classes
chunghyeon-kimm 4076358
feat: Add service, web documents
chunghyeon-kimm 498e8ec
feat: Add controller methods
chunghyeon-kimm b4cde26
refactor: Modify data.sql
chunghyeon-kimm 9497feb
feat: Add http file
chunghyeon-kimm c6ed28a
feat: Add persistence.xml
chunghyeon-kimm 57938ab
feat: Add jpa annotations, create documentRepository
chunghyeon-kimm 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 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 |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| ### document 단건 조회 | ||
| GET http://localhost:8080/api/documents/1 | ||
|
|
||
| ### document outbox 조회 | ||
| GET http://localhost:8080/api/documents/outbox?drafterId=1 | ||
|
|
||
| ### document create | ||
| POST http://localhost:8080/api/documents | ||
| Content-Type: application/json | ||
|
|
||
| { | ||
| "title": "교육비 결재 요청", | ||
| "category": "EDUCATION", | ||
| "contents": "사외교육비 결재 요청드립니다.", | ||
| "drafterId": 1, | ||
| "approverIds": [ | ||
| 1, | ||
| 2 | ||
| ] | ||
| } |
2 changes: 1 addition & 1 deletion
2
...a/playground/constants/ApprovalState.java → ...ava/learning/constants/ApprovalState.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
2 changes: 1 addition & 1 deletion
2
...n/java/playground/constants/Category.java → ...ain/java/learning/constants/Category.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
6 changes: 3 additions & 3 deletions
6
...main/java/playground/domain/Document.java → src/main/java/learning/domain/Document.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
4 changes: 2 additions & 2 deletions
4
...a/playground/domain/DocumentApproval.java → ...ava/learning/domain/DocumentApproval.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
2 changes: 1 addition & 1 deletion
2
src/main/java/playground/domain/User.java → src/main/java/learning/domain/User.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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package playground.domain; | ||
| package learning.domain; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
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
38 changes: 38 additions & 0 deletions
38
src/main/java/playground/dao/document/DocumentApprovalDao.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,38 @@ | ||
| package playground.dao.document; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
| import org.springframework.jdbc.support.GeneratedKeyHolder; | ||
| import org.springframework.jdbc.support.KeyHolder; | ||
| import org.springframework.stereotype.Repository; | ||
| import playground.domain.document.DocumentApproval; | ||
|
|
||
| import java.sql.PreparedStatement; | ||
| import java.util.Objects; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Repository | ||
| public class DocumentApprovalDao { | ||
|
|
||
| private final JdbcTemplate jdbcTemplate; | ||
|
|
||
| public Long save(DocumentApproval documentApproval) { | ||
| String sql = "insert into document_approval(document_id, approver_id, approval_state, approval_order, approval_comment) values(?,?,?,?,?)"; | ||
|
|
||
| KeyHolder keyHolder = new GeneratedKeyHolder(); | ||
| jdbcTemplate.update( | ||
| connection -> { | ||
| PreparedStatement pstmt = connection.prepareStatement(sql, new String[]{"id"}); | ||
| pstmt.setLong(1, documentApproval.getDocumentId()); | ||
| pstmt.setLong(2, documentApproval.getApproverId()); | ||
| pstmt.setString(3, documentApproval.getApprovalState().name()); | ||
| pstmt.setInt(4, documentApproval.getApprovalOrder()); | ||
| pstmt.setString(5, documentApproval.getApprovalComment()); | ||
| return pstmt; | ||
| }, | ||
| keyHolder | ||
| ); | ||
|
|
||
| return Objects.requireNonNull(keyHolder.getKey()).longValue(); | ||
| } | ||
| } |
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,76 @@ | ||
| package playground.dao.document; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
| import org.springframework.jdbc.support.GeneratedKeyHolder; | ||
| import org.springframework.jdbc.support.KeyHolder; | ||
| import org.springframework.stereotype.Repository; | ||
| import playground.domain.document.ApprovalState; | ||
| import playground.domain.document.Category; | ||
| import playground.domain.document.Document; | ||
|
|
||
| import java.sql.PreparedStatement; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Repository | ||
| public class DocumentDao { | ||
|
|
||
| private final JdbcTemplate jdbcTemplate; | ||
|
|
||
| public Document findById(Long id) { | ||
| String sql = "select * from document where id = ?"; | ||
|
|
||
| return jdbcTemplate.queryForObject( | ||
| sql, | ||
| (rs, rowNum) -> Document.builder() | ||
| .id(id) | ||
| .title(rs.getString("title")) | ||
| .category(Category.valueOf(rs.getString("category"))) | ||
| .contents(rs.getString("contents")) | ||
| .approvalState(ApprovalState.valueOf(rs.getString("approval_state"))) | ||
| .drafterId(rs.getLong("drafter_id")) | ||
| .build(), | ||
| id | ||
| ); | ||
| } | ||
|
|
||
| public List<Document> findStateDocumentsByDrafterId(Long drafterId, ApprovalState approvalState) { | ||
| String sql = "select * from document where drafter_id = ? and approval_state = ?"; | ||
|
|
||
| return jdbcTemplate.query( | ||
| sql, | ||
| (rs, rowNum) -> Document.builder() | ||
| .id(rs.getLong("id")) | ||
| .title(rs.getString("title")) | ||
| .category(Category.valueOf(rs.getString("category"))) | ||
| .approvalState(approvalState) | ||
| .drafterId(drafterId) | ||
| .build(), | ||
| drafterId, | ||
| approvalState.name() | ||
| ); | ||
| } | ||
|
|
||
| public Long save(Document document) { | ||
| String sql = "insert into document(title, category, contents, approval_state, drafter_id) values(?,?,?,?,?)"; | ||
|
|
||
| KeyHolder keyHolder = new GeneratedKeyHolder(); | ||
| jdbcTemplate.update( | ||
| connection -> { | ||
| PreparedStatement pstmt = connection.prepareStatement(sql, new String[]{"id"}); | ||
| pstmt.setString(1, document.getTitle()); | ||
| pstmt.setString(2, document.getCategory().name()); | ||
| pstmt.setString(3, document.getContents()); | ||
| pstmt.setString(4, document.getApprovalState().name()); | ||
| pstmt.setLong(5, document.getDrafterId()); | ||
| return pstmt; | ||
| }, | ||
| keyHolder | ||
| ); | ||
|
|
||
| return Objects.requireNonNull(keyHolder.getKey()).longValue(); | ||
| } | ||
|
|
||
| } |
33 changes: 33 additions & 0 deletions
33
src/main/java/playground/dao/document/dto/DocumentTitleResponse.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,33 @@ | ||
| package playground.dao.document.dto; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import playground.domain.document.ApprovalState; | ||
| import playground.domain.document.Category; | ||
| import playground.domain.document.Document; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| public class DocumentTitleResponse { | ||
|
|
||
| private Long id; | ||
| private String title; | ||
| private Category category; | ||
| private ApprovalState approvalState; | ||
|
|
||
| public DocumentTitleResponse(Document document) { | ||
| this.id = document.getId(); | ||
| this.title = document.getTitle(); | ||
| this.category = document.getCategory(); | ||
| this.approvalState = document.getApprovalState(); | ||
| } | ||
|
|
||
| public String getCategoryText() { | ||
| return category.getText(); | ||
| } | ||
|
|
||
| public String getApprovalStateText() { | ||
| return approvalState.getText(); | ||
| } | ||
|
|
||
| } |
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,50 @@ | ||
| package playground.dao.user; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
| import org.springframework.stereotype.Repository; | ||
| import playground.domain.user.User; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Repository | ||
| public class UserDao { | ||
|
|
||
| private final JdbcTemplate jdbcTemplate; | ||
|
|
||
| public User findById(Long id) { | ||
| String sql = "select * from user where id = ?"; | ||
|
|
||
| return jdbcTemplate.queryForObject( | ||
| sql, | ||
| (rs, rowNum) -> User.builder() | ||
| .id(id) | ||
| .email(rs.getString("email")) | ||
| .password(rs.getString("password")) | ||
| .name(rs.getString("name")) | ||
| .build(), | ||
| id | ||
| ); | ||
| } | ||
|
|
||
| public List<User> findAllByIds(List<Long> ids) { | ||
| String sql = "select * from user where id in (%s)"; | ||
| String inParams = ids.stream() | ||
| .map(id -> "?") | ||
| .collect(Collectors.joining(",")); | ||
|
|
||
| return jdbcTemplate.query( | ||
| String.format(sql, inParams), | ||
| (rs, rowNum) -> User.builder() | ||
| .id(rs.getLong("id")) | ||
| .email(rs.getString("email")) | ||
| .password(rs.getString("password")) | ||
| .name(rs.getString("name")) | ||
| .build(), | ||
| ids.toArray() | ||
| ); | ||
| } | ||
|
|
||
| } |
17 changes: 17 additions & 0 deletions
17
src/main/java/playground/domain/document/ApprovalState.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,17 @@ | ||
| package playground.domain.document; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum ApprovalState { | ||
|
|
||
| DRAFTING("기안"), | ||
| APPROVED("승인"), | ||
| CANCELED("거절"), | ||
| ; | ||
|
|
||
| private final String text; | ||
|
|
||
| } |
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,16 @@ | ||
| package playground.domain.document; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum Category { | ||
|
|
||
| OPERATING_EXPENSES("운영비"), | ||
| EDUCATION("교육") | ||
| ; | ||
|
|
||
| private final String text; | ||
|
|
||
| } |
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,37 @@ | ||
| package playground.domain.document; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import javax.persistence.*; | ||
|
|
||
| @Entity | ||
| @Table(name = "DOCUMENT") | ||
| @Getter | ||
| @NoArgsConstructor | ||
| public class Document { | ||
|
|
||
| @Id | ||
| @Column(name = "ID") | ||
| private Long id; | ||
|
|
||
| private String title; | ||
| private Category category; | ||
| private String contents; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| private ApprovalState approvalState; | ||
| private Long drafterId; | ||
|
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. drafter와의 관계가 객체 관계가 아니라 id만 가지고 있는 상태인 것 같은데, |
||
|
|
||
| @Builder | ||
| private Document(Long id, String title, Category category, String contents, ApprovalState approvalState, Long drafterId) { | ||
| this.id = id; | ||
| this.title = title; | ||
| this.category = category; | ||
| this.contents = contents; | ||
| this.approvalState = approvalState; | ||
| this.drafterId = drafterId; | ||
| } | ||
|
|
||
| } | ||
37 changes: 37 additions & 0 deletions
37
src/main/java/playground/domain/document/DocumentApproval.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,37 @@ | ||
| package playground.domain.document; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| import javax.persistence.*; | ||
|
|
||
| @Entity | ||
| @Table(name = "DOCUMENT_APPROVAL") | ||
| @Getter | ||
| @NoArgsConstructor | ||
| public class DocumentApproval { | ||
|
|
||
| @Id | ||
| @Column(name = "ID") | ||
| private Long id; | ||
|
|
||
| private Long documentId; | ||
| private Long approverId; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| private ApprovalState approvalState; | ||
| private Integer approvalOrder; | ||
| private String approvalComment; | ||
|
|
||
| @Builder | ||
| public DocumentApproval(Long id, Long documentId, Long approverId, ApprovalState approvalState, Integer approvalOrder, String approvalComment) { | ||
| this.id = id; | ||
| this.documentId = documentId; | ||
| this.approverId = approverId; | ||
| this.approvalState = approvalState; | ||
| this.approvalOrder = approvalOrder; | ||
| this.approvalComment = approvalComment; | ||
| } | ||
|
|
||
| } |
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.
요 객체 컴파일이 깨지는 것 같습니다