| 1 | package mk.ukim.finki.wp.db.service;
|
|---|
| 2 |
|
|---|
| 3 | import lombok.RequiredArgsConstructor;
|
|---|
| 4 | import mk.ukim.finki.wp.db.entity.SubscriptionPlan;
|
|---|
| 5 | import mk.ukim.finki.wp.db.repository.SubscriptionPlanRepository;
|
|---|
| 6 | import org.springframework.stereotype.Service;
|
|---|
| 7 |
|
|---|
| 8 | import java.math.BigDecimal;
|
|---|
| 9 | import java.util.List;
|
|---|
| 10 |
|
|---|
| 11 | @Service
|
|---|
| 12 | @RequiredArgsConstructor
|
|---|
| 13 | public class SubscriptionPlanService {
|
|---|
| 14 |
|
|---|
| 15 | private final SubscriptionPlanRepository subscriptionPlanRepository;
|
|---|
| 16 |
|
|---|
| 17 | public List<SubscriptionPlan> findAll() {
|
|---|
| 18 | return subscriptionPlanRepository.findAll();
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | public SubscriptionPlan findById(Integer id) {
|
|---|
| 22 | return subscriptionPlanRepository.findById(id).get();
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | public void addSubscriptionPlan(String name, BigDecimal price, Integer durationMonths, String description) {
|
|---|
| 26 | SubscriptionPlan subscriptionPlan = new SubscriptionPlan();
|
|---|
| 27 | subscriptionPlan.setName(name);
|
|---|
| 28 | subscriptionPlan.setPrice(price);
|
|---|
| 29 | subscriptionPlan.setDurationMonths(durationMonths);
|
|---|
| 30 | subscriptionPlan.setDescription(description);
|
|---|
| 31 | subscriptionPlanRepository.save(subscriptionPlan);
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | public void editSubscriptionPlan(Integer id, String name, BigDecimal price, Integer durationMonths, String description, String accessType) {
|
|---|
| 35 | SubscriptionPlan subscriptionPlan = findById(id);
|
|---|
| 36 | subscriptionPlan.setName(name);
|
|---|
| 37 | subscriptionPlan.setPrice(price);
|
|---|
| 38 | subscriptionPlan.setDurationMonths(durationMonths);
|
|---|
| 39 | subscriptionPlan.setDescription(description);
|
|---|
| 40 | subscriptionPlanRepository.save(subscriptionPlan);
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | public void deleteSubscriptionPlan(Integer id) {
|
|---|
| 44 | subscriptionPlanRepository.deleteById(id);
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | }
|
|---|