[Added] Start of the DataService (and data collecting system)
This commit is contained in:
@@ -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 {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user