Class CreditCardService
java.lang.Object
com.goldenleaf.shop.service.CreditCardService
Service class for managing
CreditCard entities.
Provides business logic for retrieving, adding, updating, and deleting credit cards.
Acts as an intermediary between controllers and the CreditCardRepository.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newCreditCardServicewith the provided repository. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCreditCard(CreditCard card) Adds a newCreditCardto the database.voideditCreditCard(CreditCard card) Updates an existingCreditCard.Retrieves all credit cards from the database.getCardById(Long id) Retrieves aCreditCardby its unique ID.getCardByNumber(String number) Retrieves aCreditCardby its unique number.voidremoveCreditCard(CreditCard card) Removes an existingCreditCardfrom the database.voidRemoves aCreditCardby its ID.voidremoveCreditCardByNumber(String number) Removes aCreditCardby its number.
-
Constructor Details
-
CreditCardService
Constructs a newCreditCardServicewith the provided repository.- Parameters:
repo- the repository used to perform operations on credit cards- Throws:
IllegalArgumentException- ifrepoisnull- See Also:
-
-
Method Details
-
getAllCards
Retrieves all credit cards from the database.- Returns:
- a
Listof allCreditCardentities - See Also:
-
getCardById
Retrieves aCreditCardby its unique ID.- Parameters:
id- the ID of the credit card- Returns:
- the
CreditCardwith the specified ID - Throws:
RuntimeException- if no credit card with the given ID exists- See Also:
-
getCardByNumber
Retrieves aCreditCardby its unique number.- Parameters:
number- the number of the credit card- Returns:
- the
CreditCardwith the specified number - Throws:
RuntimeException- if no credit card with the given number exists- See Also:
-
addCreditCard
Adds a newCreditCardto the database.- Parameters:
card- the credit card to add- See Also:
-
removeCreditCard
Removes an existingCreditCardfrom the database.If the credit card exists (by ID), it will be deleted; otherwise, nothing happens.
- Parameters:
card- the credit card to remove- See Also:
-
removeCreditCardById
Removes aCreditCardby its ID.- Parameters:
id- the ID of the credit card to delete- See Also:
-
removeCreditCardByNumber
Removes aCreditCardby its number.- Parameters:
number- the number of the credit card to delete- Throws:
RuntimeException- if no credit card with the given number exists- See Also:
-
editCreditCard
Updates an existingCreditCard.The credit card must have a valid ID that exists in the database. Otherwise, a
RuntimeExceptionis thrown.- Parameters:
card- the credit card to update- Throws:
RuntimeException- if the credit card does not exist or ID is null- See Also:
-