[Added] Start of the DataService (and data collecting system)

This commit is contained in:
Ninjaws
2024-11-01 22:22:27 +01:00
parent 595b83b364
commit ddc421b4b3
14 changed files with 443 additions and 15 deletions
@@ -7,10 +7,20 @@ import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
@Entity
@Table(name = "question")
@Getter
@Setter
public class Question {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String type;
private String difficulty;
private String category;
@@ -0,0 +1,8 @@
package com.ninjaws.quiz.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import com.ninjaws.quiz.models.Question;
public interface QuestionRepository extends JpaRepository<Question, Long> {
}
@@ -0,0 +1,27 @@
package com.ninjaws.quiz.services;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ninjaws.quiz.models.Question;
import com.ninjaws.quiz.repositories.QuestionRepository;
@Service
public class DataService {
@Autowired
private QuestionRepository questionRepository;
public List<Question> getAllQuestions() {
return questionRepository.findAll();
}
public Question saveQuestion(Question question) {
return questionRepository.save(question);
}
public List<Question> saveQuestions(List<Question> questions) {
return questionRepository.saveAll(questions);
}
}
@@ -11,6 +11,8 @@ public class ResponseHandlingService {
@Autowired
private CacheService cacheService;
@Autowired
private DataService dataService;
/**
* If there is no sessionId, then this is a request from the scheduler
@@ -62,6 +64,7 @@ public class ResponseHandlingService {
switch (response.getResponseCode()) {
case 0:
// TODO: Store in DB
dataService.saveQuestions(response.getResults());
break;
case 4:
// Signal DataService that we have extracted all the data. Stop gathering, switch to caching-mode
@@ -27,6 +27,8 @@ public class SchedulerService {
Request request = queueService.popFromQueue();
if (request != null) {
apiService.handleRequest(request);
} else {
apiService.collectBulk();
}
}
@@ -1,5 +0,0 @@
package com.ninjaws.quiz.services;
public class StorageService {
}