Skip to content

Commit

Permalink
회고 작성 시 보관함 내 목표 리마인드 기능 추가 (#58)
Browse files Browse the repository at this point in the history
* feat: 보관함 목표 리마인드 기능 개발
  • Loading branch information
jemlog authored Sep 1, 2023
1 parent a31241c commit 4726b61
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
30 changes: 29 additions & 1 deletion src/main/java/com/backend/goal/application/GoalService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.backend.goal.domain.*;
import com.backend.goal.application.dto.response.GoalResponse;
import com.backend.goal.domain.enums.GoalStatus;
import com.backend.goal.domain.enums.RewardType;
import com.backend.goal.domain.event.RemoveRelatedDetailGoalEvent;
import com.backend.goal.domain.repository.GoalListResponseDto;
import com.backend.goal.domain.repository.GoalQueryRepository;
Expand All @@ -22,16 +23,20 @@
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import java.util.Random;
import java.util.stream.Collectors;


@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class GoalService {

private static final int RANDOM_GOAL_COUNT = 3;

private final GoalRepository goalRepository;

private final GoalQueryRepository goalQueryRepository;
Expand Down Expand Up @@ -92,4 +97,27 @@ public void recoverGoal(Long goalId, GoalRecoverRequest goalRecoverRequest)
Goal goal = goalRepository.getByIdAndIsDeletedFalse(goalId);
goal.recover(goalRecoverRequest.startDate(), goalRecoverRequest.endDate(), goalRecoverRequest.reminderEnabled());
}

public List<GoalListResponseDto> getStoredGoalList() {

List<Goal> storedGoalList = goalRepository.getGoalsByGoalStatusAndIsDeletedFalse(GoalStatus.STORE);

Random random = new Random();

List<Goal> randomStoredGoalList = new ArrayList<>();

int goalCount = Math.min(storedGoalList.size(), RANDOM_GOAL_COUNT);

while (randomStoredGoalList.size() < goalCount) {

int index = random.nextInt(storedGoalList.size());
Goal goal = storedGoalList.get(index);

if (!randomStoredGoalList.contains(goal)) {
randomStoredGoalList.add(goal);
}
}

return randomStoredGoalList.stream().map(GoalListResponseDto::from).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ default Goal getByIdAndIsDeletedFalse(Long id){
int countByGoalStatusAndIsDeletedFalse(GoalStatus goalStatus);

List<Goal> getGoalsByGoalStatusAndIsDeletedFalse(GoalStatus goalStatus);


}
13 changes: 12 additions & 1 deletion src/main/java/com/backend/goal/presentation/GoalController.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.backend.goal.application.dto.response.GoalListResponse;
import com.backend.goal.application.dto.response.GoalResponse;
import com.backend.goal.application.dto.response.RetrospectEnabledGoalCountResponse;
import com.backend.goal.domain.repository.GoalListResponseDto;
import com.backend.goal.presentation.dto.GoalRecoverRequest;
import com.backend.goal.presentation.dto.GoalSaveRequest;
import com.backend.goal.presentation.dto.GoalUpdateRequest;
Expand All @@ -20,6 +21,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.backend.global.common.code.SuccessCode.*;

@RestController
Expand All @@ -41,7 +44,7 @@ public ResponseEntity<CustomResponse<GoalListResponse>> getGoalList(
return CustomResponse.success(SELECT_SUCCESS,goalService.getGoalList(lastId,pageable,goalStatus));
}


@Operation(summary = "상위 목표 상태별 개수 조회", description = "상위 목표 상태별 개수를 조회하는 API 입니다.")
@ApiResponse(responseCode = "200", description = "code : 200, message : SELECT_SUCCESS")
@GetMapping("/count")
Expand All @@ -58,6 +61,14 @@ public ResponseEntity<CustomResponse<RetrospectEnabledGoalCountResponse>> getRet
return CustomResponse.success(SELECT_SUCCESS,goalService.getGoalCountRetrospectEnabled());
}

@Operation(summary = "회고 완료 후 보관함 내 목표 추천", description = "보관함에 들어있는 목표들 중 랜덤하게 3개를 추천해줍니다")
@ApiResponse(responseCode = "200", description = "code : 200, message : SELECT_SUCCESS")
@GetMapping("/stored-goals")
public ResponseEntity<CustomResponse<List<GoalListResponseDto>>> getStoredGoalList()
{
return CustomResponse.success(SELECT_SUCCESS,goalService.getStoredGoalList());
}


@Operation(summary = "상위 목표 삭제", description = "상위 목표를 삭제하는 API 입니다.")
@ApiResponse(responseCode = "200", description = "code : 200, message : DELETE_SUCCESS")
Expand Down

0 comments on commit 4726b61

Please sign in to comment.