Package me.nickhanson.codeforge.service
Class DrillService
java.lang.Object
me.nickhanson.codeforge.service.DrillService
Service for managing drill items and recording outcomes.
-
Constructor Summary
ConstructorsConstructorDescriptionDrillService(DrillItemDao drillItemDao, SubmissionDao submissionDao, ChallengeDao challengeDao) -
Method Summary
Modifier and TypeMethodDescriptionensureDrillItem(Long challengeId, String userId) Ensures that a DrillItem exists for the given challenge and user, creating one if necessary.intensureEnrollmentForUser(List<Challenge> challenges, String userId) Ensures that DrillItems exist for a list of challenges for the specified user.getDueQueue(int limit, String userId) Retrieves a list of due drill items for the specified user, up to the given limit.booleanisEnrolledInDrill(Long challengeId, String userId) Checks if a user is enrolled in a drill for a specific challenge.Retrieves the next due DrillItem for the specified user.recordOutcome(Long challengeId, Outcome outcome, String code, String userId) Records the outcome of a user's attempt at a challenge and updates the corresponding drill item.
-
Constructor Details
-
DrillService
public DrillService() -
DrillService
public DrillService(DrillItemDao drillItemDao, SubmissionDao submissionDao, ChallengeDao challengeDao)
-
-
Method Details
-
getDueQueue
Retrieves a list of due drill items for the specified user, up to the given limit. If no items are currently due, returns the soonest upcoming item if available.- Parameters:
limit- the maximum number of drill items to retrieveuserId- the ID of the user- Returns:
- a list of due drill items or the soonest upcoming item
- Throws:
IllegalArgumentException- if limit is less than or equal to zero or if userId is null/blank
-
recordOutcome
Records the outcome of a user's attempt at a challenge and updates the corresponding drill item.- Parameters:
challengeId- the ID of the challengeoutcome- the outcome of the attemptcode- the code submitted by the useruserId- the ID of the user- Returns:
- the recorded submission
- Throws:
IllegalArgumentException- if userId is null/blank or if the challenge is not found
-
isEnrolledInDrill
Checks if a user is enrolled in a drill for a specific challenge.- Parameters:
challengeId- the ID of the challengeuserId- the ID of the user- Returns:
- true if the user is enrolled in the drill, false otherwise
-
ensureDrillItem
Ensures that a DrillItem exists for the given challenge and user, creating one if necessary.- Parameters:
challengeId- the ID of the challengeuserId- the ID of the user- Returns:
- the existing or newly created DrillItem
- Throws:
IllegalArgumentException- if the challenge is not found
-
nextDue
Retrieves the next due DrillItem for the specified user.- Parameters:
userId- the ID of the user- Returns:
- an Optional containing the next due DrillItem, or empty if none are due
-
ensureEnrollmentForUser
Ensures that DrillItems exist for a list of challenges for the specified user.- Parameters:
challenges- the list of challengesuserId- the ID of the user- Returns:
- the number of DrillItems created
- Throws:
IllegalArgumentException- if userId is null/blank
-