Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ dependencies {
testImplementation('org.springframework.boot:spring-boot-starter-test')

// JDBC
// implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'

// JPA
// implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

// validation
// implementation 'org.springframework.boot:spring-boot-starter-validation'
Expand Down
20 changes: 20 additions & 0 deletions http/document.http
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
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package playground.constants;
package learning.constants;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package playground.constants;
package learning.constants;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package playground.domain;
package learning.domain;

import lombok.Builder;
import lombok.Getter;
import playground.constants.ApprovalState;
import playground.constants.Category;
import learning.constants.ApprovalState;
import learning.constants.Category;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 객체 컴파일이 깨지는 것 같습니다


import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package playground.domain;
package learning.domain;

import lombok.Builder;
import lombok.Setter;
import playground.constants.ApprovalState;
import learning.constants.ApprovalState;

@Builder
@Setter
Expand Down
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;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/playground/PlaygroundApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing
@SpringBootApplication
public class PlaygroundApplication {

Expand Down
38 changes: 38 additions & 0 deletions src/main/java/playground/dao/document/DocumentApprovalDao.java
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();
}
}
76 changes: 76 additions & 0 deletions src/main/java/playground/dao/document/DocumentDao.java
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();
}

}
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();
}

}
50 changes: 50 additions & 0 deletions src/main/java/playground/dao/user/UserDao.java
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 src/main/java/playground/domain/document/ApprovalState.java
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;

}
16 changes: 16 additions & 0 deletions src/main/java/playground/domain/document/Category.java
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;

}
37 changes: 37 additions & 0 deletions src/main/java/playground/domain/document/Document.java
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;
Copy link

Choose a reason for hiding this comment

The 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 src/main/java/playground/domain/document/DocumentApproval.java
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;
}

}
Loading