Skip to content
Snippets Groups Projects
Commit 1d761b27 authored by Victor Ekholt Gunrell Kaste's avatar Victor Ekholt Gunrell Kaste
Browse files

Added get goal endpoint and logic

parent 5776aae3
No related branches found
No related tags found
1 merge request!77Added get goal endpoint and logic
Pipeline #282291 passed
...@@ -125,4 +125,11 @@ public class GoalController { ...@@ -125,4 +125,11 @@ public class GoalController {
challengeService.updateSavingAmount(identity.getId(), request.getId(), request.getAmount()); challengeService.updateSavingAmount(identity.getId(), request.getId(), request.getAmount());
return ResponseEntity.status(HttpStatus.ACCEPTED).build(); return ResponseEntity.status(HttpStatus.ACCEPTED).build();
} }
@GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<GoalDTO> getGoal(@RequestParam Long id) {
Goal goal = goalService.getGoal(id);
GoalDTO goalDTO = modelMapper.map(goal, GoalDTO.class);
return ResponseEntity.ok(goalDTO);
}
} }
...@@ -31,4 +31,6 @@ public interface GoalService { ...@@ -31,4 +31,6 @@ public interface GoalService {
* The list may be empty if the user has no goals. * The list may be empty if the user has no goals.
*/ */
List<Goal> getGoals(long userId); List<Goal> getGoals(long userId);
Goal getGoal(long goalId);
} }
...@@ -3,7 +3,10 @@ package no.ntnu.idi.stud.savingsapp.service.impl; ...@@ -3,7 +3,10 @@ package no.ntnu.idi.stud.savingsapp.service.impl;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.Instant; import java.time.Instant;
import java.util.List; import java.util.List;
import java.util.Optional;
import no.ntnu.idi.stud.savingsapp.exception.goal.ChallengeNotFoundException;
import no.ntnu.idi.stud.savingsapp.exception.goal.GoalNotFoundException;
import no.ntnu.idi.stud.savingsapp.model.goal.Challenge; import no.ntnu.idi.stud.savingsapp.model.goal.Challenge;
import no.ntnu.idi.stud.savingsapp.model.goal.Goal; import no.ntnu.idi.stud.savingsapp.model.goal.Goal;
import no.ntnu.idi.stud.savingsapp.model.user.User; import no.ntnu.idi.stud.savingsapp.model.user.User;
...@@ -56,4 +59,14 @@ public class GoalServiceImpl implements GoalService { ...@@ -56,4 +59,14 @@ public class GoalServiceImpl implements GoalService {
public List<Goal> getGoals(long userId) { public List<Goal> getGoals(long userId) {
return goalRepository.findByUser_Id(userId); return goalRepository.findByUser_Id(userId);
} }
@Override
public Goal getGoal(long goalId) {
Optional<Goal> optionalGoal = goalRepository.findById(goalId);
if (optionalGoal.isPresent()) {
return optionalGoal.get();
} else {
throw new GoalNotFoundException();
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment