Class SubscriptionRepository

java.lang.Object
org.strassburger.subscriptionmanager.model.repositories.SubscriptionRepository

public class SubscriptionRepository extends Object
  • Constructor Details

    • SubscriptionRepository

      public SubscriptionRepository(org.jooq.DSLContext dsl)
  • Method Details

    • addSubscription

      public boolean addSubscription(int profileId, String name, double price, BillingPeriod billingPeriod, Long startDate, String category)
      Add a new subscription to the database.
      Parameters:
      profileId - The ID of the profile to add the subscription to.
      name - The name of the subscription.
      price - The price of the subscription per billing period.
      billingPeriod - The billing period of the subscription.
      startDate - The start date of the subscription in milliseconds since epoch (nullable).
      category - The category of the subscription.
      Returns:
      True if the subscription was added successfully, false otherwise.
    • getAllSubscriptions

      public List<Subscription> getAllSubscriptions(int profileId)
      Get all subscriptions from the database.
      Parameters:
      profileId - The ID of the profile to get the subscriptions from.
      Returns:
      A list of all subscriptions.
    • getSubscriptionById

      public Optional<Subscription> getSubscriptionById(int id)
      Get a subscription by its ID.
      Parameters:
      id - The ID of the subscription.
      Returns:
      An optional containing the subscription if it exists, empty otherwise.
    • getSubscriptionByName

      public Optional<Subscription> getSubscriptionByName(int profileId, String name)
      Get a subscription by its name.
      Parameters:
      profileId - The ID of the profile to get the subscription from.
      name - The name of the subscription.
      Returns:
      An optional containing the subscription if it exists, empty otherwise.
    • updateSubscription

      public boolean updateSubscription(Subscription subscription)
      Update a subscription in the database.
      Parameters:
      subscription - The subscription to update.
      Returns:
      True if the subscription was updated successfully, false otherwise.
    • deleteSubscription

      public boolean deleteSubscription(int id)
      Delete a subscription from the database.
      Parameters:
      id - The ID of the subscription to delete.
      Returns:
      True if the subscription was deleted successfully, false otherwise.
    • getExistingCategories

      public Set<String> getExistingCategories()
      Fetches all distinct categories from the database.
      Returns:
      A set of unique category names as strings.