Class QuestionService
- java.lang.Object
-
- edu.cnm.deepdive.interviewprep.service.QuestionService
-
-
Constructor Summary
Constructors Constructor Description QuestionService(QuestionRepository questionRepository)
Constructor that instantiates a newQuestion
service object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Question
createQuestion(Question question, User user)
Creates a newQuestion
object in the database for the current user.void
delete(UUID externalKey, User user)
Deletes aQuestion
object identified by external key for the current user.Optional<Question>
get(UUID externalKey)
Gets the current Question object records from the database identified by external key.Optional<Question>
get(UUID externalKey, User user)
Returns aQuestion
object identified by the external key for the current user.List<Question>
getQuestions()
Returns a list of allQuestion
in the database.Question
getRandomQuestion()
Returns a randomQuestion
object from the database.Question
saveQuestion(Question question, User user)
Saves aQuestion
object to the database for the current user.Optional<Question>
updateQuestion(UUID externalKey, Question question, User user)
Updates aQuestion
object to the database for the current user.
-
-
-
Constructor Detail
-
QuestionService
@Autowired public QuestionService(QuestionRepository questionRepository)
Constructor that instantiates a newQuestion
service object.- Parameters:
questionRepository
- Question repository object.
-
-
Method Detail
-
get
public Optional<Question> get(UUID externalKey, User user)
Returns aQuestion
object identified by the external key for the current user.- Parameters:
externalKey
- External key in the form of a universally unique identifier.user
- A User object.- Returns:
- An optional Question object.
-
delete
public void delete(UUID externalKey, User user)
Deletes aQuestion
object identified by external key for the current user.- Parameters:
externalKey
- External key in the form of a universally unique identifier.user
- A User object.
-
getQuestions
public List<Question> getQuestions()
Returns a list of allQuestion
in the database.- Returns:
- A list of all Question objects.
-
get
public Optional<Question> get(UUID externalKey)
Gets the current Question object records from the database identified by external key.- Parameters:
externalKey
- Id in the form of a universally unique identifier.- Returns:
- An optional Question object.
-
createQuestion
public Question createQuestion(Question question, User user)
Creates a newQuestion
object in the database for the current user.- Parameters:
question
- A Question object.user
- A User object.- Returns:
- A Question object.
-
saveQuestion
public Question saveQuestion(Question question, User user)
Saves aQuestion
object to the database for the current user.- Parameters:
question
- A Question object.user
- A User object.- Returns:
- A Question object.
-
getRandomQuestion
public Question getRandomQuestion()
Returns a randomQuestion
object from the database.- Returns:
- A random Question object.
-
updateQuestion
public Optional<Question> updateQuestion(UUID externalKey, Question question, User user)
Updates aQuestion
object to the database for the current user.- Parameters:
externalKey
- External key in the form of a universally unique identifier.question
- A Question object.user
- A User object.- Returns:
- A Question object.
-
-