Skip to content

Commit

Permalink
UserRestController final version
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio-octavio committed Mar 20, 2023
1 parent 8b5c394 commit 16e7aae
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ public ResponseEntity<User> register(@RequestBody User user) throws IOException

@GetMapping("/{userId}/moreCartGames/{page}")
public Page<Game> getMoreCartGames(@PathVariable int page, HttpServletRequest request, @PathVariable long userId) {

try {
User user = userService.findByMail(request.getUserPrincipal().getName()).orElseThrow();
return userService.getMoreCartGames(userId, page, user);

} catch (Exception e) {
return null;
}
}

@GetMapping("/{id}")
Expand All @@ -101,6 +103,8 @@ public ResponseEntity<User> getUser(@PathVariable long id) {
Optional<User> opUser = userService.findById(id);
if (opUser.isPresent()) {
return new ResponseEntity<>(opUser.get(), HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}

Expand Down Expand Up @@ -160,5 +164,25 @@ public ResponseEntity<Purchase> checkoutProcess(HttpServletRequest request, Stri
}
}


@GetMapping("/{userId}/purchase/{purchaseId}")
public ResponseEntity<Purchase> purchase(HttpServletRequest request, @PathVariable long userId,
@PathVariable long purchaseId) {
try {
User currentUser = userService.findByMail(request.getUserPrincipal().getName()).orElseThrow();
return purchaseService.getPurchase(currentUser, userId, purchaseId);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
}

@PutMapping("/{userId}")
public ResponseEntity<Object> editProfile(@PathVariable long userId, User newUser, HttpServletRequest request,
MultipartFile imageFile) throws IOException, SQLException {
try {
User currentUser = userService.findByMail(request.getUserPrincipal().getName()).orElseThrow();
return userService.editProfile(userId, newUser, currentUser, imageFile);
} catch (Exception e) {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
}
}

0 comments on commit 16e7aae

Please sign in to comment.