Class SubscriptionRepository
java.lang.Object
org.strassburger.subscriptionmanager.model.repositories.SubscriptionRepository
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddSubscription(int profileId, String name, double price, BillingPeriod billingPeriod, Long startDate, String category) Add a new subscription to the database.booleandeleteSubscription(int id) Delete a subscription from the database.getAllSubscriptions(int profileId) Get all subscriptions from the database.Fetches all distinct categories from the database.getSubscriptionById(int id) Get a subscription by its ID.getSubscriptionByName(int profileId, String name) Get a subscription by its name.booleanupdateSubscription(Subscription subscription) Update a subscription in the database.
-
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
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
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
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
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
Fetches all distinct categories from the database.- Returns:
- A set of unique category names as strings.
-