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
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import playground.controller.document.request.CreateDocumentRequest;
import playground.service.document.DocumentService;
import playground.service.document.request.CreateDocumentRequest;
import playground.service.document.response.SelectCategoryResponse;
import playground.service.document.response.SelectDocumentResponse;
import playground.service.document.response.SelectSingleOutBoxResponse;

Expand All @@ -29,19 +30,25 @@ public DocumentController(final DocumentService documentService) {

@PostMapping
public ResponseEntity<Void> create(@RequestBody @Valid final CreateDocumentRequest createDocumentRequest) {
documentService.save(createDocumentRequest);
documentService.create(createDocumentRequest);
return new ResponseEntity<>(HttpStatus.CREATED);
}

@GetMapping("/{documentId}")
public ResponseEntity<SelectDocumentResponse> select(final @PathVariable Long documentId) {
SelectDocumentResponse selectDocumentResponse = documentService.select(documentId);
public ResponseEntity<SelectDocumentResponse> find(final @PathVariable Long documentId) {
SelectDocumentResponse selectDocumentResponse = documentService.find(documentId);
return ResponseEntity.ok(selectDocumentResponse);
}

@GetMapping("/outbox")
public ResponseEntity<List<SelectSingleOutBoxResponse>> selectOutBox(final @RequestParam Long drafterId) {
List<SelectSingleOutBoxResponse> selectMultiOutBoxResponse = documentService.selectOutBox(drafterId);
public ResponseEntity<List<SelectSingleOutBoxResponse>> findOutBox(final @RequestParam Long drafterId) {
List<SelectSingleOutBoxResponse> selectMultiOutBoxResponse = documentService.findOutBox(drafterId);
return ResponseEntity.ok(selectMultiOutBoxResponse);
}

@GetMapping("/categories")
public ResponseEntity<List<SelectCategoryResponse>> findCategories() {
List<SelectCategoryResponse> selectCategoryResponses = documentService.findCategories();
return ResponseEntity.ok(selectCategoryResponses);
}
}
38 changes: 38 additions & 0 deletions src/main/java/playground/controller/team/TeamController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package playground.controller.team;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import playground.service.team.TeamService;
import playground.service.team.request.CreateTeamRequest;
import playground.service.team.response.SelectTeamResponse;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping(path = "/api/teams")
public class TeamController {

private final TeamService teamService;

public TeamController(final TeamService teamService) {
this.teamService = teamService;
}

@PostMapping
public ResponseEntity<Void> create(@RequestBody @Valid final CreateTeamRequest createTeamRequest) {
teamService.create(createTeamRequest);
return new ResponseEntity<>(HttpStatus.CREATED);
}

@GetMapping
public ResponseEntity<List<SelectTeamResponse>> findAll() {
List<SelectTeamResponse> selectTeamResponses = teamService.findAll();
return ResponseEntity.ok(selectTeamResponses);
}
}
16 changes: 13 additions & 3 deletions src/main/java/playground/controller/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import playground.controller.user.request.CreateUserRequest;
import playground.service.user.UserService;
import playground.service.user.request.CreateUserRequest;
import playground.service.user.response.SelectUserResponse;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping(path = "/api/user")
@RequestMapping(path = "/api/users")
public class UserController {

private final UserService userService;
Expand All @@ -23,7 +27,13 @@ public UserController(final UserService userService) {

@PostMapping
public ResponseEntity<Void> create(@RequestBody @Valid final CreateUserRequest createUserRequest) {
userService.save(createUserRequest);
userService.create(createUserRequest);
return new ResponseEntity<>(HttpStatus.CREATED);
}

@GetMapping()
public ResponseEntity<List<SelectUserResponse>> findAllUserInTeam(@RequestParam final Long teamId) {
List<SelectUserResponse> selectUserResponses = userService.findAllUserInTeam(teamId);
return ResponseEntity.ok(selectUserResponses);
}
}
78 changes: 52 additions & 26 deletions src/main/java/playground/domain/document/Document.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,77 @@
package playground.domain.document;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import playground.domain.document.vo.ApprovalState;
import playground.domain.document.vo.Category;
import playground.domain.user.User;

import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.util.Collections;
import java.util.List;

@Entity
@Getter
@EqualsAndHashCode(of = "id")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "document")
public class Document {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "document_id")
private Long id;

@Column(name = "title", nullable = false)
private String title;

@Enumerated(value = EnumType.STRING)
@Column(name = "category", nullable = false)
private Category category;

@Column(name = "contents", nullable = false)
private String contents;
private Long drafterId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "drafter_id")
private User drafter;

@Embedded
private DocumentApprovals documentApprovals = new DocumentApprovals();

@Enumerated(value = EnumType.STRING)
@Column(name = "approval_state", nullable = false)
private ApprovalState approvalState;

@Builder
private Document(final String title, final String category,
final String contents, final Long drafterId) {
private Document(final String title, final Category category,
final String contents, final User drafter) {
this.title = title;
this.category = Category.valueOf(category);
this.category = category;
this.contents = contents;
this.drafterId = drafterId;
this.drafter = drafter;
this.approvalState = ApprovalState.DRAFTING;
}

@Builder(builderMethodName = "builderForDao", builderClassName = "BuilderForDao")
private Document(final Long id, final String title, final String category,
final String contents, final Long drafterId, final String approvalState) {
this.id = id;
this.title = title;
this.category = Category.valueOf(category);
this.contents = contents;
this.drafterId = drafterId;
this.approvalState = ApprovalState.valueOf(approvalState);
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final Document document = (Document) o;
return Objects.equals(id, document.id);
public void enrollApprovals(final List<User> approvers) {
documentApprovals.enroll(approvers, this);
}

@Override
public int hashCode() {
return Objects.hash(id);
public List<DocumentApproval> getDocumentApprovals() {
return Collections.unmodifiableList(documentApprovals.getDocumentApprovals());
}
}
55 changes: 47 additions & 8 deletions src/main/java/playground/domain/document/DocumentApproval.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,68 @@
package playground.domain.document;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import playground.domain.document.vo.ApprovalState;
import playground.domain.user.User;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Getter
@EqualsAndHashCode(of = "id")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "document_approval")
public class DocumentApproval {

private Long approverId;
private Long documentId;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "document_approval_id")
private Long id;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "approver_id")
private User approver;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "document_id")
private Document document;

@Enumerated(value = EnumType.STRING)
@Column(name = "approval_state", nullable = false)
private ApprovalState approvalState;

@Column(name = "approval_order", nullable = false)
private Integer approvalOrder;

@Column(name = "approval_comment")
private String approvalComment;

@Builder
private DocumentApproval(final Long approverId, final Long documentId, final String approvalState,
private DocumentApproval(final User approver, final Document document, final ApprovalState approvalState,
final Integer approvalOrder, final String approvalComment) {
this.approverId = approverId;
this.documentId = documentId;
this.approvalState = ApprovalState.valueOf(approvalState);
this.approver = approver;
this.document = document;
this.approvalState = approvalState;
this.approvalOrder = approvalOrder;
this.approvalComment = approvalComment;
}

public static DocumentApproval of(final Long approverId, final Long documentId, final int approvalOrder) {
return new DocumentApproval(approverId, documentId, ApprovalState.DRAFTING.name(),
public static DocumentApproval of(final User approver, final Document document, final int approvalOrder) {
return new DocumentApproval(approver, document, ApprovalState.DRAFTING,
approvalOrder, null);
}
}
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/playground/domain/document/DocumentApprovals.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package playground.domain.document;

import lombok.Getter;
import playground.domain.user.User;

import javax.persistence.CascadeType;
import javax.persistence.Embeddable;
import javax.persistence.OneToMany;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Getter
@Embeddable
public class DocumentApprovals {

@OneToMany(mappedBy = "document", cascade = CascadeType.ALL, orphanRemoval = true)
private List<DocumentApproval> documentApprovals = new ArrayList<>();

public void enroll(final List<User> approvers, final Document document) {
checkEmpty();

for (int i = 0; i < approvers.size(); i++) {
DocumentApproval documentApproval = DocumentApproval.of(approvers.get(i), document, i + 1);
documentApprovals.add(documentApproval);
}
}

private void checkEmpty() {
if (!documentApprovals.isEmpty()) {
throw new IllegalStateException("결재자 추가 등록이 불가능합니다.");
}
}

public List<DocumentApproval> getDocumentApprovals() {
return Collections.unmodifiableList(documentApprovals);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package playground.domain.document;
package playground.domain.document.vo;

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

import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/playground/domain/team/Team.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package playground.domain.team;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import playground.domain.user.User;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import java.util.ArrayList;
import java.util.List;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "team", uniqueConstraints = {
@UniqueConstraint(name = "team_name_contraint", columnNames = "name")
})
public class Team {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "team_id")
private Long id;

@Column(name = "name", nullable = false)
private String name;

@OneToMany(mappedBy = "team")
private List<User> users = new ArrayList<>();

public Team(final String name) {
this.name = name;
}

public void addUser(final User user) {
this.users.add(user);
}
}
Loading