-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathPurchaseAndSubscriptionController.java
More file actions
45 lines (37 loc) · 1.71 KB
/
PurchaseAndSubscriptionController.java
File metadata and controls
45 lines (37 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package io.hexlet.cv.controller.account;
import io.github.inertia4j.spring.Inertia;
import io.hexlet.cv.service.PurchaseAndSubscriptionService;
import io.hexlet.cv.util.UserUtils;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.support.RequestContextUtils;
@Controller
@RequiredArgsConstructor
@RequestMapping("/account")
public class PurchaseAndSubscriptionController {
private final Inertia inertia;
private final PurchaseAndSubscriptionService service;
private final UserUtils userUtils;
@PreAuthorize("isAuthenticated()")
@GetMapping("/purchase")
public Object index(@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size,
HttpServletRequest request) {
var userId = userUtils.currentUserId(); // id юзера который залогинился
Pageable pageable = PageRequest.of(page, size);
var props = service.indexPurchSubs(userId.get(), pageable);
var flash = RequestContextUtils.getInputFlashMap(request);
if (!ObjectUtils.isEmpty(flash)) {
props.put("flash", flash);
}
return inertia.render("Account/Purchase/Index", props);
}
}