Class QuestionService
- java.lang.Object
-
- edu.cnm.deepdive.interviewprep.service.QuestionService
-
-
Constructor Summary
Constructors Constructor Description QuestionService(QuestionRepository questionRepository)Constructor that instantiates a newQuestionservice object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description QuestioncreateQuestion(Question question, User user)Creates a newQuestionobject in the database for the current user.voiddelete(UUID externalKey, User user)Deletes aQuestionobject 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 aQuestionobject identified by the external key for the current user.List<Question>getQuestions()Returns a list of allQuestionin the database.QuestiongetRandomQuestion()Returns a randomQuestionobject from the database.QuestionsaveQuestion(Question question, User user)Saves aQuestionobject to the database for the current user.Optional<Question>updateQuestion(UUID externalKey, Question question, User user)Updates aQuestionobject to the database for the current user.
-
-
-
Constructor Detail
-
QuestionService
@Autowired public QuestionService(QuestionRepository questionRepository)
Constructor that instantiates a newQuestionservice object.- Parameters:
questionRepository- Question repository object.
-
-
Method Detail
-
get
public Optional<Question> get(UUID externalKey, User user)
Returns aQuestionobject 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 aQuestionobject 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 allQuestionin 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 newQuestionobject 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 aQuestionobject 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 randomQuestionobject from the database.- Returns:
- A random Question object.
-
updateQuestion
public Optional<Question> updateQuestion(UUID externalKey, Question question, User user)
Updates aQuestionobject 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.
-
-