Class CreditCardService

java.lang.Object
com.goldenleaf.shop.service.CreditCardService

@Service public class CreditCardService extends Object
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 Details

  • Method Details

    • getAllCards

      public List<CreditCard> getAllCards()
      Retrieves all credit cards from the database.
      Returns:
      a List of all CreditCard entities
      See Also:
      • ListCrudRepository.findAll()
    • getCardById

      public CreditCard getCardById(Long id)
      Retrieves a CreditCard by its unique ID.
      Parameters:
      id - the ID of the credit card
      Returns:
      the CreditCard with the specified ID
      Throws:
      RuntimeException - if no credit card with the given ID exists
      See Also:
      • CrudRepository.findById(Object)
    • getCardByNumber

      public CreditCard getCardByNumber(String number)
      Retrieves a CreditCard by its unique number.
      Parameters:
      number - the number of the credit card
      Returns:
      the CreditCard with the specified number
      Throws:
      RuntimeException - if no credit card with the given number exists
      See Also:
    • addCreditCard

      public void addCreditCard(CreditCard card)
      Adds a new CreditCard to the database.
      Parameters:
      card - the credit card to add
      See Also:
      • CrudRepository.save(Object)
    • removeCreditCard

      public void removeCreditCard(CreditCard card)
      Removes an existing CreditCard from 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:
      • CrudRepository.delete(Object)
      • CrudRepository.existsById(Object)
    • removeCreditCardById

      public void removeCreditCardById(Long id)
      Removes a CreditCard by its ID.
      Parameters:
      id - the ID of the credit card to delete
      See Also:
      • CrudRepository.deleteById(Object)
    • removeCreditCardByNumber

      public void removeCreditCardByNumber(String number)
      Removes a CreditCard by 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

      public void editCreditCard(CreditCard card)
      Updates an existing CreditCard.

      The credit card must have a valid ID that exists in the database. Otherwise, a RuntimeException is thrown.

      Parameters:
      card - the credit card to update
      Throws:
      RuntimeException - if the credit card does not exist or ID is null
      See Also:
      • CrudRepository.save(Object)
      • CrudRepository.existsById(Object)