| 1 | package mk.ukim.finki.wp.db.controller;
|
|---|
| 2 |
|
|---|
| 3 | import lombok.RequiredArgsConstructor;
|
|---|
| 4 | import mk.ukim.finki.wp.db.entity.SubscriptionPlan;
|
|---|
| 5 | import mk.ukim.finki.wp.db.service.SubscriptionPlanService;
|
|---|
| 6 | import org.springframework.stereotype.Controller;
|
|---|
| 7 | import org.springframework.ui.Model;
|
|---|
| 8 | import org.springframework.web.bind.annotation.*;
|
|---|
| 9 |
|
|---|
| 10 | import java.math.BigDecimal;
|
|---|
| 11 |
|
|---|
| 12 | @Controller
|
|---|
| 13 | @RequiredArgsConstructor
|
|---|
| 14 | public class SubscriptionPlanController {
|
|---|
| 15 |
|
|---|
| 16 | private final SubscriptionPlanService subscriptionPlanService;
|
|---|
| 17 |
|
|---|
| 18 | @GetMapping("/subscription-plans")
|
|---|
| 19 | public String getSubscriptionPlansPage(Model model) {
|
|---|
| 20 | model.addAttribute("plans", subscriptionPlanService.findAll());
|
|---|
| 21 | return "subscription/subscription_plans";
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | // Show add subscription plan form
|
|---|
| 25 | @GetMapping("/add/subscription-plan")
|
|---|
| 26 | public String getAddSubscriptionPlanPage() {
|
|---|
| 27 | return "subscription/subscription_plan_form";
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | @PostMapping("/add/subscription-plan")
|
|---|
| 31 | public String addSubscriptionPlan(@RequestParam String name,
|
|---|
| 32 | @RequestParam BigDecimal price,
|
|---|
| 33 | @RequestParam Integer durationMonths,
|
|---|
| 34 | @RequestParam String description) {
|
|---|
| 35 | subscriptionPlanService.addSubscriptionPlan(name, price, durationMonths, description);
|
|---|
| 36 | return "redirect:/subscription-plans";
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | @GetMapping("/edit/subscription-plan/{id}")
|
|---|
| 40 | public String getEditSubscriptionPlanPage(@PathVariable Integer id, Model model) {
|
|---|
| 41 | SubscriptionPlan plan = subscriptionPlanService.findById(id);
|
|---|
| 42 | model.addAttribute("plan", plan);
|
|---|
| 43 | return "subscription/subscription_plan_form";
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | @PostMapping("/edit/subscription-plan/{id}")
|
|---|
| 47 | public String editSubscriptionPlan(@PathVariable Integer id,
|
|---|
| 48 | @RequestParam String name,
|
|---|
| 49 | @RequestParam BigDecimal price,
|
|---|
| 50 | @RequestParam Integer durationMonths,
|
|---|
| 51 | @RequestParam String description) {
|
|---|
| 52 | subscriptionPlanService.editSubscriptionPlan(id, name, price, durationMonths, description, null); // pass null for accessType if not used
|
|---|
| 53 | return "redirect:/subscription-plans";
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | @PostMapping("/delete/subscription-plan/{id}")
|
|---|
| 57 | public String deleteSubscriptionPlan(@PathVariable Integer id) {
|
|---|
| 58 | subscriptionPlanService.deleteSubscriptionPlan(id);
|
|---|
| 59 | return "redirect:/subscription-plans";
|
|---|
| 60 | }
|
|---|
| 61 | }
|
|---|