-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from Louie-03/BE-feature-74
[BE] 마일스톤 기능 구현
- Loading branch information
Showing
9 changed files
with
207 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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
56 changes: 56 additions & 0 deletions
56
BE/src/main/java/louie/hanse/issuetracker/service/MileStoneService.java
This file contains 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,56 @@ | ||
package louie.hanse.issuetracker.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import louie.hanse.issuetracker.domain.Issue; | ||
import louie.hanse.issuetracker.domain.Milestone; | ||
import louie.hanse.issuetracker.domain.Status; | ||
import louie.hanse.issuetracker.repository.MilestoneRepository; | ||
import louie.hanse.issuetracker.web.dto.milestone.MilestoneListResponse; | ||
import louie.hanse.issuetracker.web.dto.milestone.MilestoneRequest; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class MileStoneService { | ||
|
||
private final MilestoneRepository milestoneRepository; | ||
|
||
@Transactional | ||
public void register(MilestoneRequest request) { | ||
Milestone milestone = request.toEntity(); | ||
milestoneRepository.save(milestone); | ||
} | ||
|
||
public MilestoneListResponse getMilestoneList(Status status) { | ||
List<Milestone> closedMilestone = milestoneRepository.findClosedMilestone(LocalDate.now()); | ||
List<Milestone> openedMilestone = milestoneRepository.findOpenedMilestone(LocalDate.now()); | ||
if (status.isOpened()) { | ||
return new MilestoneListResponse(openedMilestone.size(), closedMilestone.size(), openedMilestone); | ||
} | ||
return new MilestoneListResponse(openedMilestone.size(), closedMilestone.size(), closedMilestone); | ||
} | ||
|
||
@Transactional | ||
public void edit(Long id, MilestoneRequest request) { | ||
Milestone milestone = milestoneRepository.findById(id).orElseThrow(IllegalStateException::new); | ||
|
||
milestone.updateTitle(request.getTitle()); | ||
milestone.updateDescription(request.getDescription()); | ||
milestone.updateCompletedDate(request.getCompletedDate()); | ||
} | ||
|
||
@Transactional | ||
public void delete(Long id) { | ||
Milestone milestone = milestoneRepository.findById(id).orElseThrow(IllegalStateException::new); | ||
List<Issue> issues = milestone.getIssues(); | ||
for (Issue issue : issues) { | ||
issue.deleteMilestone(); | ||
} | ||
milestoneRepository.delete(milestone); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
BE/src/main/java/louie/hanse/issuetracker/web/controller/MileStoneController.java
This file contains 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,36 @@ | ||
package louie.hanse.issuetracker.web.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import louie.hanse.issuetracker.domain.Status; | ||
import louie.hanse.issuetracker.service.MileStoneService; | ||
import louie.hanse.issuetracker.web.dto.milestone.MilestoneListResponse; | ||
import louie.hanse.issuetracker.web.dto.milestone.MilestoneRequest; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/milestone") | ||
@RequiredArgsConstructor | ||
public class MileStoneController { | ||
|
||
private final MileStoneService mileStoneService; | ||
|
||
@PostMapping | ||
public void registerMilestone(@RequestBody MilestoneRequest request) { | ||
mileStoneService.register(request); | ||
} | ||
|
||
@GetMapping | ||
public MilestoneListResponse getMilestoneList(@RequestParam("status") Status status) { | ||
return mileStoneService.getMilestoneList(status); | ||
} | ||
|
||
@PutMapping("/{id}") | ||
public void editMilestone(@PathVariable Long id, @RequestBody MilestoneRequest request) { | ||
mileStoneService.edit(id, request); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public void deleteMilestone(@PathVariable Long id) { | ||
mileStoneService.delete(id); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
BE/src/main/java/louie/hanse/issuetracker/web/dto/milestone/MilestoneDetailResponse.java
This file contains 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,30 @@ | ||
package louie.hanse.issuetracker.web.dto.milestone; | ||
|
||
import lombok.Getter; | ||
import louie.hanse.issuetracker.domain.Issue; | ||
import louie.hanse.issuetracker.domain.Milestone; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Getter | ||
public class MilestoneDetailResponse { | ||
private Long id; | ||
private String title; | ||
private String description; | ||
private LocalDate completedDate; | ||
private long openedIssueCount; | ||
private long closedIssueCount; | ||
|
||
public MilestoneDetailResponse(Milestone milestone) { | ||
this.id = milestone.getId(); | ||
this.title = milestone.getTitle(); | ||
this.description = milestone.getDescription(); | ||
this.completedDate = milestone.getCompletedDate(); | ||
this.openedIssueCount = milestone.getIssues().stream() | ||
.filter(Issue::isOpened) | ||
.count(); | ||
this.closedIssueCount = milestone.getIssues().stream() | ||
.filter(Issue::isClosed) | ||
.count(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
BE/src/main/java/louie/hanse/issuetracker/web/dto/milestone/MilestoneListResponse.java
This file contains 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,22 @@ | ||
package louie.hanse.issuetracker.web.dto.milestone; | ||
|
||
import lombok.Getter; | ||
import louie.hanse.issuetracker.domain.Milestone; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
public class MilestoneListResponse { | ||
private int openedMileStoneCount; | ||
private int closedMileStoneCount; | ||
private List<MilestoneDetailResponse> milestones; | ||
|
||
public MilestoneListResponse(int openedMileStoneCount, int closedMileStoneCount, List<Milestone> milestones) { | ||
this.openedMileStoneCount = openedMileStoneCount; | ||
this.closedMileStoneCount = closedMileStoneCount; | ||
this.milestones = milestones.stream() | ||
.map(MilestoneDetailResponse::new) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
BE/src/main/java/louie/hanse/issuetracker/web/dto/milestone/MilestoneRequest.java
This file contains 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,19 @@ | ||
package louie.hanse.issuetracker.web.dto.milestone; | ||
|
||
import lombok.Getter; | ||
import louie.hanse.issuetracker.domain.Milestone; | ||
|
||
import javax.validation.constraints.NotEmpty; | ||
import java.time.LocalDate; | ||
|
||
@Getter | ||
public class MilestoneRequest { | ||
@NotEmpty | ||
private String title; | ||
private String description; | ||
private LocalDate completedDate; | ||
|
||
public Milestone toEntity() { | ||
return new Milestone(title, description, completedDate); | ||
} | ||
} |