Class DrillService

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

public class DrillService extends Object
Service for managing drill items and recording outcomes.
  • Constructor Details

  • Method Details

    • getDueQueue

      public List<DrillItem> getDueQueue(int limit, String userId)
      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 retrieve
      userId - 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

      public Submission 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.
      Parameters:
      challengeId - the ID of the challenge
      outcome - the outcome of the attempt
      code - the code submitted by the user
      userId - the ID of the user
      Returns:
      the recorded submission
      Throws:
      IllegalArgumentException - if userId is null/blank or if the challenge is not found
    • isEnrolledInDrill

      public boolean isEnrolledInDrill(Long challengeId, String userId)
      Checks if a user is enrolled in a drill for a specific challenge.
      Parameters:
      challengeId - the ID of the challenge
      userId - the ID of the user
      Returns:
      true if the user is enrolled in the drill, false otherwise
    • ensureDrillItem

      public DrillItem ensureDrillItem(Long challengeId, String userId)
      Ensures that a DrillItem exists for the given challenge and user, creating one if necessary.
      Parameters:
      challengeId - the ID of the challenge
      userId - the ID of the user
      Returns:
      the existing or newly created DrillItem
      Throws:
      IllegalArgumentException - if the challenge is not found
    • nextDue

      public Optional<DrillItem> nextDue(String userId)
      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

      public int ensureEnrollmentForUser(List<Challenge> challenges, String userId)
      Ensures that DrillItems exist for a list of challenges for the specified user.
      Parameters:
      challenges - the list of challenges
      userId - the ID of the user
      Returns:
      the number of DrillItems created
      Throws:
      IllegalArgumentException - if userId is null/blank