Package me.nickhanson.codeforge.service
Class ChallengeService
java.lang.Object
me.nickhanson.codeforge.service.ChallengeService
Service layer for managing Challenge entities.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreate(ChallengeForm form) Creates a new challenge from the provided form data.booleanDeletes a challenge by its ID.Retrieves a challenge by its ID.listChallenges(Difficulty difficulty) Lists all challenges, optionally filtered by difficulty.booleantitleExists(String title) Checks if a challenge title already exists (case insensitive).booleantitleExistsForOther(String title, Long id) Checks if a challenge title already exists for a different challenge (case insensitive).update(Long id, ChallengeForm form) Updates an existing challenge with the provided form data.
-
Constructor Details
-
ChallengeService
public ChallengeService() -
ChallengeService
-
-
Method Details
-
listChallenges
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
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
Checks if a challenge title already exists (case insensitive).- Parameters:
title- The title to check.- Returns:
- true if the title exists, false otherwise.
-
titleExistsForOther
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
Creates a new challenge from the provided form data.- Parameters:
form- The form data for the new challenge.- Returns:
- The created Challenge.
-
update
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
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.
-