Skip to content

Commit

Permalink
refactoring quiz service and quiz bot session
Browse files Browse the repository at this point in the history
  • Loading branch information
XD-cods committed May 14, 2024
1 parent 658a2f4 commit cabd545
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 69 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/example/QuizBotListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ private void sendMessage(Long userId, String s) {
}

private void sendTopics(Long userId, QuizBotSession quizBotSession) {
List<String> allTopicsName = quizService.findAllTopicName();
List<String> allTopicsName = quizService.getTopics();
if (allTopicsName.isEmpty()) {
allTopicsName = QuizService.getTopics();
allTopicsName = quizService.getTopics();
if (allTopicsName.isEmpty()) {
sendMessage(userId, "Sorry nothing topics");
return;
Expand Down Expand Up @@ -290,7 +290,7 @@ private InlineKeyboardMarkup buildInlineKeyboard(int keyboardLength) {

private void choiceTopic(String messageText, QuizBotSession quizBotSession, Long userId) {
int topicIndex = Integer.parseInt(messageText) - 1;
List<String> allTopicName = QuizService.getTopics();
List<String> allTopicName = quizService.getTopics();
if (allTopicName.isEmpty()) {

quizBotSession.setBotSessionMode(QuizBotSessionMode.SESSION_CREATED);
Expand Down
42 changes: 1 addition & 41 deletions src/main/java/org/example/services/QuizService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ public QuizService(QuizRepo quizRepo) {
topics = quizRepo.findAllTopicName();
}

public static List<String> getTopics() {
return topics;
}

public List<String> findAllTopicName() {
//todo fetch topic list on start
public List<String> getTopics() {
ObjectMapper objectMapper = new ObjectMapper();
List<String> topic = quizRepo.findAllTopicName();
if (topic == null) {
Expand All @@ -47,45 +42,10 @@ public List<String> findAllTopicName() {
public void deleteAllQuiz() {
topics = new ArrayList<>();
quizRepo.deleteAll();
//
// try {
// Files.delete(Path.of(pathTopicsName));
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
}

@Deprecated(forRemoval = true)
public void updateTopicsFile() {
//
// long countOfQuiz = quizRepo.count();
// if (countOfQuiz <= 0) {
// return;
// }
// List<String> allTopicName = this.findAllTopicName();
//
// try {
// Files.write(Paths.get(pathTopicsName), allTopicName);
// } catch (IOException e) {
// throw new RuntimeException(e);
// }
}

public void insertNewQuiz(QuizQuestions quizQuestions) {
if (quizRepo.findByTopicName(quizQuestions.getTopicName()) != null) {
quizRepo.addByTopic(quizQuestions.getTopicName(), quizQuestions.getQuestionList());
return;
}
topics.add(quizQuestions.getTopicName());
quizRepo.save(quizQuestions);
}

public QuizQuestions findByTopicName(String topicName) {
return quizRepo.findByTopicName(topicName);
}

public void updateQuizByTopicName(String topicName, QuizQuestions newQuizQuestions) {
// quizRepo.deleteByTopicName(topicName);
// insertNewQuiz(newQuizQuestions);
}
}
25 changes: 0 additions & 25 deletions src/main/java/util/MongoListener.java

This file was deleted.

0 comments on commit cabd545

Please sign in to comment.