Class ChallengeService

java.lang.Object
me.nickhanson.codeforge.service.ChallengeService

public class ChallengeService extends Object
Service layer for managing Challenge entities.
  • Constructor Details

    • ChallengeService

      public ChallengeService()
    • ChallengeService

      public ChallengeService(ChallengeDao dao)
  • Method Details

    • listChallenges

      public List<Challenge> listChallenges(Difficulty difficulty)
      Lists all challenges, optionally filtered by difficulty.
      Parameters:
      difficulty - The difficulty to filter by, or null for all difficulties.
      Returns:
      A list of challenges.
    • getById

      public Optional<Challenge> getById(Long id)
      Retrieves a challenge by its ID.
      Parameters:
      id - The ID of the challenge.
      Returns:
      An Optional containing the Challenge if found, or empty if not found.
    • titleExists

      public boolean titleExists(String title)
      Checks if a challenge title already exists (case insensitive).
      Parameters:
      title - The title to check.
      Returns:
      true if the title exists, false otherwise.
    • titleExistsForOther

      public boolean titleExistsForOther(String title, Long id)
      Checks if a challenge title already exists for a different challenge (case insensitive).
      Parameters:
      title - The title to check.
      id - The ID of the challenge to exclude from the check.
      Returns:
      true if the title exists for another challenge, false otherwise.
    • create

      public Challenge create(ChallengeForm form)
      Creates a new challenge from the provided form data.
      Parameters:
      form - The form data for the new challenge.
      Returns:
      The created Challenge.
    • update

      public Optional<Challenge> update(Long id, ChallengeForm form)
      Updates an existing challenge with the provided form data.
      Parameters:
      id - The ID of the challenge to update.
      form - The form data for the update.
      Returns:
      An Optional containing the updated Challenge if found, or empty if not found.
    • delete

      public boolean delete(Long id)
      Deletes a challenge by its ID.
      Parameters:
      id - The ID of the challenge to delete.
      Returns:
      true if the challenge was deleted, false if not found.