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
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,8 +2,10 @@

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

@SpringBootApplication
@EnableJpaAuditing
public class PlaygroundApplication {
public static void main(String[] args) {
SpringApplication.run(PlaygroundApplication.class, args);
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/playground/controller/DocumentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import playground.dto.CategoryResponse;
import playground.dto.DocumentOutboxResponse;
import playground.dto.DocumentRequest;
import playground.dto.DocumentResponse;
Expand All @@ -11,26 +12,30 @@
import java.util.List;

@RestController
@RequestMapping("/api")
@RequestMapping("/api/documents")
public class DocumentController {
@Autowired
DocumentService documentService;

@GetMapping("/document/{documentId}")
@GetMapping("/{documentId}")
public ResponseEntity<DocumentResponse> getDocumentById(@PathVariable Long documentId) {
DocumentResponse DocumentResponse = documentService.findDocumentBy(documentId);
return ResponseEntity.ok().body(DocumentResponse);
}

@GetMapping("/documents/outbox")
@GetMapping("/outbox")
public ResponseEntity<List<DocumentOutboxResponse>> getDocumentsOutbox(@RequestParam Long userId) {
List<DocumentOutboxResponse> DocumentOutboxResponse = documentService.findDocumentsOutbox(userId);
return ResponseEntity.ok().body(DocumentOutboxResponse);
}

@PostMapping("/document")
@PostMapping
public ResponseEntity<Long> insertDocument(@RequestBody DocumentRequest documentRequest) {
Long id = documentService.insertDocument(documentRequest);
return ResponseEntity.ok().body(id);
}
@GetMapping("/categories")
public List<CategoryResponse> getCategories(){
return documentService.getCategories();
}
}
23 changes: 23 additions & 0 deletions src/main/java/playground/controller/TeamController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package playground.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import playground.dto.TeamResponse;
import playground.service.TeamService;

import java.util.List;

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

@Autowired
TeamService teamService;

@GetMapping()
public List<TeamResponse> getTeams() {
return teamService.findAll();
}
}
26 changes: 26 additions & 0 deletions src/main/java/playground/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package playground.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import playground.dto.UserResponse;
import playground.service.UserService;

import java.util.List;

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

@Autowired
UserService userService;

@GetMapping
public List<UserResponse> getUserBy(
@RequestParam Long teamId
) {
return userService.findBy(teamId);
}
}
2 changes: 1 addition & 1 deletion src/main/java/playground/domain/ApprovalState.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public enum ApprovalState {
APPROVED("승인"),
CANCELED("거절");

private final String status;
private final String name;

}
21 changes: 21 additions & 0 deletions src/main/java/playground/domain/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package playground.domain;

import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.time.LocalDateTime;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseEntity {
@CreatedDate
private LocalDateTime createdDate;

@LastModifiedDate
private LocalDateTime modifiedDate;
}
2 changes: 1 addition & 1 deletion src/main/java/playground/domain/Category.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public enum Category {
EDUCATION("교육"),
PRODUCT_PURCHASING("물품구매");

private final String category;
private final String name;


}
32 changes: 20 additions & 12 deletions src/main/java/playground/domain/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import playground.dto.DocumentRequest;

import javax.persistence.*;
import java.sql.Date;
Expand All @@ -17,9 +16,9 @@
@Entity
@NoArgsConstructor
@AllArgsConstructor
public class Document {
public class Document extends BaseEntity {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String title;
Expand All @@ -29,37 +28,46 @@ public class Document {

private String contents;

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

@Enumerated(EnumType.STRING)
private ApprovalState approvalState = ApprovalState.DRAFTING;

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

@Transient
private int approvalIndex;

@CreatedDate
private Date createdAt;
private int approvalIndex = 0;

@Builder
public Document(Long id, String title, Category category, String contents, User drafter, Date createdAt) {
public Document(Long id, String title, Category category, String contents, User drafter, List<DocumentApproval> documentApprovals) {
this.id = id;
this.title = title;
this.category = category;
this.contents = contents;
this.drafter = drafter;
this.createdAt = createdAt;
this.documentApprovals = documentApprovals;
}

public Document(String title, Category category, String contents, User drafter) {
this.title = title;
this.category = category;
this.contents = contents;
this.drafter = drafter;
}

public void addDocumentApproval(final DocumentApproval documentApproval){
documentApprovals.add(documentApproval);
documentApproval.setDocument(this);
}

public void addApprovers(List<User> approvals) {
AtomicInteger index = new AtomicInteger();
index.getAndIncrement();
approvalIndex = 0;
approvals.forEach(approver-> addDocumetApprovals(approver, index.getAndIncrement()));
approvals.forEach(approver -> addDocumetApprovals(approver, index.getAndIncrement()));
}

public List<DocumentApproval> getDocumentApprovals() {
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/playground/domain/DocumentApproval.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;

@Getter
@Setter
@Entity
public class DocumentApproval {
@NoArgsConstructor
public class DocumentApproval extends BaseEntity {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private User approver;

Expand All @@ -23,13 +27,25 @@ public class DocumentApproval {

private String approvalComment;

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

@Builder
public DocumentApproval(User approver, ApprovalState approvalState, int approvalOrder) {
this.approver = approver;
this.approvalState = approvalState;
this.approvalOrder = approvalOrder;
}

@Builder
public DocumentApproval(User approver, int approvalOrder, Document document) {
this.approver = approver;
this.approvalState = ApprovalState.DRAFTING;
this.approvalOrder = approvalOrder;
this.document = document;
}

public DocumentApproval approveBy(User approver, String approvalComment) {
this.approvalComment = approvalComment;
this.approver = approver;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/playground/domain/Rank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package playground.domain;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum Rank {

TEAM_LEADER("팀장"),
PART_MANAGER("파트장"),
TEAM_MEMBER("팀원");

private final String name;

}
26 changes: 26 additions & 0 deletions src/main/java/playground/domain/Team.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package playground.domain;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
@Getter
@NoArgsConstructor
public class Team extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String name;

@Builder
public Team(String name) {
this.name = name;
}
}
27 changes: 22 additions & 5 deletions src/main/java/playground/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,36 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.*;

@NoArgsConstructor
@Getter
@AllArgsConstructor
@Builder
@Entity
public class User {
public class User extends BaseEntity {
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String name;

private String email;

private String password;

@Enumerated(EnumType.STRING)
private Rank rank;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "team_id")
private Team team;

public User(String name, String email, String password, Rank rank, Team team) {
this.name = name;
this.email = email;
this.password = password;
this.rank = rank;
this.team = team;
}
}
35 changes: 35 additions & 0 deletions src/main/java/playground/dto/ApprovalResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package playground.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import playground.domain.DocumentApproval;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApprovalResponse {

private String approvarTeamName;

private String approvarName;

private int approvalOrder;

private String approvalComment;

private String approvalStateText;

public ApprovalResponse(DocumentApproval approvar) {

this.approvarTeamName = approvar.getApprover().getTeam().getName();

this.approvarName = approvar.getApprover().getName();

this.approvalOrder = approvar.getApprovalOrder();

this.approvalComment = approvar.getApprovalComment();

this.approvalStateText = approvar.getApprovalState().getName();
}
}
Loading