[x] Create unified data object (each type [catagorical/quantitative] should be inherited by this)
[x] Associate StappletData to user using detailsService file
[x] Finish functional api controllers
[x] Integrate api to frontend
public void addQrCodeToUser(String personEmail, Long qrCodeId) {
Person person = personJpaRepository.findByEmail(personEmail);
if (person != null) { // verify person
Optional<QrCode> qrCode = QrCodeJpaRepository.findById(qrCodeId);
if (qrCode != null) { // verify role
person.getQrCodes().add(qrCode.get());
}
}
}
@GetMapping("/getQuantitative{id}")
public ResponseEntity<Quantitative> getQuantitative(@PathVariable long id) {
Optional<Quantitative> optional = qRepository.findById(id);
if (optional.isPresent()) { // Good ID
Quantitative quantitative = optional.get(); // value from findByID
return new ResponseEntity<>(quantitative, HttpStatus.OK); // OK HTTP response: status code, headers, and body
}
// Bad ID
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
function postApi(){
if(window.location.href.includes("127.0.0.1")){
var url = 'http://localhost:8911/api/stats/newQuantitative';
}
else {
var url = 'https://https://jcc.stu.nighthawkcodingsociety.com/api/stats/newQuantitative';
}
var name = document.getElementById('variableName').value;
var variable = document.getElementById('variable').value.split(',');
const quantitativeRequest = {
data: variable,
name: name
};
fetch(url, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(quantitativeRequest)
})
.then(response => response.json())
.then(data => console.log('Success:', data))
.catch(error => {
console.error('Error:', error);
if (error instanceof SyntaxError) {
console.error('There was a syntax error in the response, possibly not JSON:', error.message);
} else {
console.error('There was a network or other error:', error.message);
}
});
}
public List<Double> customSort(List<Double> arr){
int n = arr.size();
for (int i = 1; i < n; ++i) {
double key = arr.get(i);
int j = i - 1;
while (j >= 0 && arr.get(j) > key) {
arr.set(j + 1, arr.get(j));
j = j - 1;
}
arr.set(j + 1, key);
}
return arr;
}
public void addTwoQuantitativeToUser(String personEmail, Long twoQuantitativeId) {
Person person = personJpaRepository.findByEmail(personEmail);
if (person != null) { // verify person
Optional<TwoQuantitative> twoQuantitative = twoQuantitativeJpaRepository.findById(twoQuantitativeId);
if (twoQuantitative != null) { // verify role
person.getTwoQuantitatives().add(twoQuantitative.get());
}
}
}