-
Notifications
You must be signed in to change notification settings - Fork 0
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 #12 from GDSC-snowflowerthon/feature/7
Feature/7
- Loading branch information
Showing
6 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/tenten/blooming/domain/subgoal/controller/SubgoalController.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,42 @@ | ||
package tenten.blooming.domain.subgoal.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.*; | ||
import tenten.blooming.domain.goal.entity.Goal; | ||
import tenten.blooming.domain.goal.repository.GoalRepository; | ||
import tenten.blooming.domain.subgoal.dto.GetSubgoalInfoByUserIdRequest; | ||
import tenten.blooming.domain.subgoal.dto.SubgoalResponse; | ||
import tenten.blooming.domain.subgoal.service.SubgoalService; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class SubgoalController { | ||
|
||
@Autowired private final GoalRepository goalRepository; | ||
@Autowired private final SubgoalService subgoalService; | ||
@PostMapping("/subgoal/{goalId}/detail/{subgoalId}") | ||
public ResponseEntity<List<LocalDate>> updateSubgoal( | ||
@PathVariable("goalId") Long goalId, | ||
@PathVariable("subgoalId") Long subgoalId | ||
) { | ||
List<LocalDate> doneDates = subgoalService.updateSubgoal(subgoalId); | ||
|
||
return ResponseEntity.ok(doneDates); | ||
} | ||
|
||
@GetMapping("/subgoal/{goalId}/progress") | ||
public ResponseEntity<SubgoalResponse> getSubgoalInfoByUserId( | ||
@PathVariable Long goalId, | ||
@RequestBody @Validated GetSubgoalInfoByUserIdRequest request | ||
) { | ||
SubgoalResponse subgoalResponse = subgoalService.getSubgoalInfoByUserId(request.getUserId()); | ||
|
||
return ResponseEntity.ok(subgoalResponse); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/tenten/blooming/domain/subgoal/dto/GetSubgoalInfoByUserIdRequest.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,11 @@ | ||
package tenten.blooming.domain.subgoal.dto; | ||
|
||
import lombok.*; | ||
|
||
@Data | ||
@Getter @Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class GetSubgoalInfoByUserIdRequest { | ||
private Long userId; | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/tenten/blooming/domain/subgoal/dto/SubgoalResponse.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 tenten.blooming.domain.subgoal.dto; | ||
|
||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@Getter @Setter | ||
public class SubgoalResponse { | ||
private String goalName; | ||
private Long goalId; | ||
private LocalDate goalCreateDate; | ||
private List<SubgoalInfo> SubgoalList; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public static class SubgoalInfo { | ||
private Long subgoalId; | ||
private String subgoalName; | ||
private List<LocalDate> doneDateList; | ||
} | ||
} | ||
|
||
|
||
|
9 changes: 9 additions & 0 deletions
9
src/main/java/tenten/blooming/domain/subgoal/dto/UpdateSubgoalRequest.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,9 @@ | ||
package tenten.blooming.domain.subgoal.dto; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class UpdateSubgoalRequest { | ||
private Long goalId; | ||
private Long subgoalId; | ||
} |
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
76 changes: 76 additions & 0 deletions
76
src/main/java/tenten/blooming/domain/subgoal/service/SubgoalService.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,76 @@ | ||
package tenten.blooming.domain.subgoal.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import tenten.blooming.domain.goal.entity.Goal; | ||
import tenten.blooming.domain.goal.repository.GoalRepository; | ||
import tenten.blooming.domain.subgoal.dto.SubgoalResponse; | ||
import tenten.blooming.domain.subgoal.entity.Subgoal; | ||
import tenten.blooming.domain.subgoal.repository.SubgoalRepository; | ||
import tenten.blooming.domain.user.entity.User; | ||
import tenten.blooming.domain.user.repository.UserRepository; | ||
|
||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class SubgoalService { | ||
|
||
@Autowired private final UserRepository userRepository; | ||
@Autowired private final SubgoalRepository subgoalRepository; | ||
@Autowired private final GoalRepository goalRepository; | ||
/** | ||
* Subgoal 생성 | ||
*/ | ||
@Transactional | ||
public Subgoal createSubgoal(Goal goal) { | ||
Subgoal subgoal = Subgoal.createSubgoal(goal); | ||
|
||
return subgoalRepository.save(subgoal); | ||
} | ||
|
||
/** | ||
* subgoal의 과제 한 개 완료 | ||
*/ | ||
@Transactional | ||
public List<LocalDate> updateSubgoal(Long subgoalId) { | ||
Subgoal findSubgoal = subgoalRepository.findById(subgoalId).orElse(null); | ||
|
||
return findSubgoal.addDoneDate(); | ||
} | ||
|
||
public List<Goal> getGoalByUserId(Long userId) { | ||
User findUser = userRepository.findById(userId).orElse(null); | ||
|
||
return findUser.getGoals(); | ||
} | ||
|
||
public SubgoalResponse getSubgoalInfoByUserId(Long userId) { | ||
List<Goal> goals = getGoalByUserId(userId); | ||
Goal goal = goals.get(goals.size() - 1); | ||
List<Subgoal> subgoals = goal.getSubgoals(); | ||
SubgoalResponse subgoalResponse = new SubgoalResponse(); | ||
List<SubgoalResponse.SubgoalInfo> subgoalInfoList = new ArrayList<>(); | ||
|
||
for(Subgoal subgoal : subgoals) { | ||
SubgoalResponse.SubgoalInfo subgoalInfo = new SubgoalResponse.SubgoalInfo(); | ||
subgoalInfo.setSubgoalId(subgoal.getSubgoalId()); | ||
subgoalInfo.setSubgoalName(subgoal.getSubgoalName()); | ||
subgoalInfo.setDoneDateList(subgoal.getDoneDates()); | ||
subgoalInfoList.add(subgoalInfo); | ||
} | ||
|
||
subgoalResponse.setGoalName(goal.getGoalName()); | ||
subgoalResponse.setGoalId(goal.getGoalId()); | ||
subgoalResponse.setGoalCreateDate(goal.getCreatedAt()); | ||
subgoalResponse.setSubgoalList(subgoalInfoList); | ||
|
||
return subgoalResponse; | ||
} | ||
} |