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
5 changes: 4 additions & 1 deletion http/document.http
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ Content-Type: application/json
GET http://localhost:8080/api/documents/1

### OUT BOX 문서 조회
GET http://localhost:8080/api/documents/out?userId=1
GET http://localhost:8080/api/documents/out?userId=1

### 문서 분류 조회
GET http://localhost:8080/api/documents/categories
19 changes: 19 additions & 0 deletions http/team.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### 팀 저장1
POST http://localhost:8080/api/team
Content-Type: application/json

{
"name": "정산시스템팀"
}

### 팀 저장2
POST http://localhost:8080/api/team
Content-Type: application/json

{
"name": "서비스개발팀"
}


### 전체 팀 조회
GET http://localhost:8080/api/teams
33 changes: 30 additions & 3 deletions http/user.http
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
### 사용자 저장
### 팀 저장
POST http://localhost:8080/api/team
Content-Type: application/json

{
"name": "정산시스템팀"
}

### 회원 저장1
POST http://localhost:8080/api/user
Content-Type: application/json

{
"name": "userA",
"password": "pa@sw**d",
"email": "userA@gmail.com",
"teamName": "정산시스템팀",
"jobPosition": "PART_MANAGER"
}

### 회원 저장2
POST http://localhost:8080/api/user
Content-Type: application/json

{
"name": "userA"
"name": "userA",
"password": "pa@sw**d",
"email": "userA@gmail.com",
"teamName": "정산시스템팀",
"jobPosition": "TEAM_LEADER"
}

### 사용자 1명 조회
### 회원 1명 조회
GET http://localhost:8080/api/users/1

### 팀에 속한 회원 조회
GET http://localhost:8080/api/users?teamId=1
15 changes: 12 additions & 3 deletions src/main/java/playground/controller/DocumentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import playground.domain.document.Category;
import playground.service.document.DocumentService;
import playground.service.document.dto.CategoryResponse;
import playground.service.document.dto.DocumentRequest;
import playground.service.document.dto.DocumentResponse;
import playground.service.document.dto.OutboxResponse;

import java.net.URI;
import java.util.Arrays;
import java.util.List;

@RestController
Expand All @@ -18,21 +21,27 @@ public class DocumentController {

private final DocumentService documentService;

@GetMapping("/documents/{id}")
@GetMapping(value = "/documents/{id}")
public ResponseEntity<DocumentResponse> find(@PathVariable Long id) {
DocumentResponse document = documentService.findOne(id);
return ResponseEntity.ok(document);
}

@GetMapping("/documents/out")
@GetMapping(value = "/documents/out")
public ResponseEntity<List<OutboxResponse>> list(@RequestParam("userId") Long userId) {
List<OutboxResponse> outBox = documentService.findOutBox(userId);
return ResponseEntity.ok(outBox);
}

@PostMapping("/document")
@PostMapping(value = "/document")
public ResponseEntity<DocumentResponse> save(@RequestBody DocumentRequest requestDto) {
DocumentResponse document = documentService.save(requestDto);
return ResponseEntity.created(URI.create("/documents/" + document.getId())).body(document);
}

@GetMapping(value = "/documents/categories")
public ResponseEntity<List<CategoryResponse>> findCategories() {
List<CategoryResponse> categories = CategoryResponse.ofList(Arrays.asList(Category.values()));
return ResponseEntity.ok(categories);
}
}
36 changes: 36 additions & 0 deletions src/main/java/playground/controller/TeamController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package playground.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import playground.service.user.TeamService;
import playground.service.user.dto.TeamRequest;
import playground.service.user.dto.TeamResponse;

import java.net.URI;
import java.util.List;

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

private final TeamService teamService;

@PostMapping(value = "/team")
public ResponseEntity<TeamResponse> save(@RequestBody TeamRequest request) {
TeamResponse team = teamService.saveTeam(request);
return ResponseEntity.created(URI.create("/teams/" + team.getId())).body(team);
}

@GetMapping(value = "teams")
public ResponseEntity<List<TeamResponse>> findUserByTeam() {
try {
List<TeamResponse> teams = teamService.findTeams();
return ResponseEntity.ok(teams);

} catch (RuntimeException e) {
return ResponseEntity.notFound().build();
}
}
}
28 changes: 21 additions & 7 deletions src/main/java/playground/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
package playground.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import playground.service.user.UserService;
import playground.service.user.dto.TeamUserResponse;
import playground.service.user.dto.UserRequest;
import playground.service.user.dto.UserResponse;

import java.net.URI;
import java.util.List;

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

private final UserService userService;

@GetMapping("/users/{id}")
@PostMapping(value = "/user")
public ResponseEntity<UserResponse> save(@RequestBody UserRequest requestDto) {
UserResponse user = userService.saveUser(requestDto);
return ResponseEntity.created(URI.create("users/" + user.getId())).body(user);
}

@GetMapping(value = "/users/{id}")
public ResponseEntity<UserResponse> find(@PathVariable Long id) {
try {
UserResponse user = userService.findOne(id);
return new ResponseEntity<>(user, HttpStatus.OK);
return ResponseEntity.ok(user);

} catch (RuntimeException e) {
return ResponseEntity.notFound().build();
}
}

@PostMapping("/user")
public ResponseEntity<UserResponse> save(@RequestBody UserRequest requestDto) {
UserResponse user = userService.save(requestDto);
return new ResponseEntity<>(user, HttpStatus.OK);
@GetMapping(value = "/users")
public ResponseEntity<List<TeamUserResponse>> findByTeam(@RequestParam("teamId") Long id) {
try {
List<TeamUserResponse> users = userService.findUserByTeam(id);
return ResponseEntity.ok(users);

} catch (RuntimeException e) {
return ResponseEntity.notFound().build();
}
}
}
16 changes: 12 additions & 4 deletions src/main/java/playground/domain/document/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.List;

import static javax.persistence.CascadeType.ALL;
import static javax.persistence.ConstraintMode.NO_CONSTRAINT;
import static javax.persistence.FetchType.LAZY;
import static javax.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;
Expand All @@ -35,7 +36,7 @@ public class Document extends BaseTimeEntity {
private String contents;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "drafter_id", foreignKey = @ForeignKey(name = "fk_document_drafter"))
@JoinColumn(name = "drafter_id", foreignKey = @ForeignKey(value = NO_CONSTRAINT))
private User drafter;

@Enumerated(EnumType.STRING)
Expand All @@ -54,8 +55,15 @@ public Document(String title, Category category, String contents, User drafter)
this.documentApprovals = new ArrayList<>();
}

public void addDocumentApprovals(DocumentApproval documentApproval) {
this.documentApprovals.add(documentApproval);
documentApproval.setDocument(this);
public void createApprovals(List<User> aprovers) {
for (int i = 0; i < aprovers.size(); i++) {
DocumentApproval approval = DocumentApproval.builder()
.approver(aprovers.get(i))
.approvalOrder(i + 1)
.build();

approval.upDateDocument(this);
this.documentApprovals.add(approval);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public interface DocumentRepository extends JpaRepository<Document, Long> {
"on d.id = a.document.id " +
"where a.approver.id = :userId order by a.insertDate asc")
List<Document> findOutBox(@Param(value = "userId") Long userId);

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package playground.domain.document.approval;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import playground.domain.document.BaseTimeEntity;
import playground.domain.document.Document;
import playground.domain.user.Team;
import playground.domain.user.User;

import javax.persistence.*;

import static javax.persistence.ConstraintMode.NO_CONSTRAINT;
import static javax.persistence.FetchType.LAZY;
import static javax.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;
Expand All @@ -22,11 +25,11 @@ public class DocumentApproval extends BaseTimeEntity {
private Long id;

@ManyToOne(fetch = LAZY)
@JoinColumn(name = "document_id", foreignKey = @ForeignKey(name = "fk_approval_document"))
@JoinColumn(name = "document_id", foreignKey = @ForeignKey(value = NO_CONSTRAINT))
private Document document;

@OneToOne
@JoinColumn(name = "approver_id", foreignKey = @ForeignKey(name = "fk_document_approver"))
@ManyToOne(fetch = LAZY)
@JoinColumn(name = "approver_id", foreignKey = @ForeignKey(value = NO_CONSTRAINT))
private User approver;

@Enumerated(EnumType.STRING)
Expand All @@ -37,17 +40,18 @@ public class DocumentApproval extends BaseTimeEntity {
@Lob
private String approvalComment;

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

public static DocumentApproval create(User approver, int approvalOrder) {
return new DocumentApproval(approver, approvalOrder);
public void upDateDocument(Document document) {
this.document = document;
}

public void setDocument(Document document) {
this.document = document;
public Team getTeam() {
return approver.getTeam();
}
}
15 changes: 15 additions & 0 deletions src/main/java/playground/domain/user/JobPosition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package playground.domain.user;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum JobPosition {

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

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

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import playground.domain.document.BaseTimeEntity;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

import static javax.persistence.CascadeType.ALL;
import static javax.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;

@Getter
@Entity
@RequiredArgsConstructor(access = PROTECTED)
public class Team extends BaseTimeEntity {

@Id
@GeneratedValue(strategy = IDENTITY)
private Long id;

@Column(unique = true)
private String name;

@OneToMany(mappedBy = "team", cascade = ALL, orphanRemoval = true)
private List<User> users = new ArrayList<>();

public Team(String name) {
this.name = name;
}
}
11 changes: 11 additions & 0 deletions src/main/java/playground/domain/user/TeamRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package playground.domain.user;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface TeamRepository extends JpaRepository<Team, Long> {

Team findTeamByName(String name);

}
Loading