blob: f3ba98c6d77521cefa839abb39763c0f1519dd76 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package com.stileeducation.markr.service;
import com.stileeducation.markr.entity.Test;
import com.stileeducation.markr.repository.TestRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Optional;
@Service
public class TestService {
@Autowired
TestRepository testRepository;
public Test findOrCreateTest(String testId, Integer marksAvailable) {
Optional<Test> optionalTest = testRepository.findByTestId(testId);
if (optionalTest.isPresent()) {
return optionalTest.get();
} else {
Test test = new Test();
test.setTestId(testId);
test.setMarksAvailable(marksAvailable);
return testRepository.save(test);
}
}
}
|