Test keycloak worked with README.md

This commit is contained in:
Vu Tuan Minh
2025-10-25 01:56:58 +02:00
parent 2404733cbe
commit 571d7f0402
6 changed files with 781 additions and 13 deletions

View File

@@ -5,4 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
import sample.data.jpa.metier.Session;
public interface SessionDao extends JpaRepository<Session, Integer> {
boolean existsByCodePIN(int codePIN);
}

View File

@@ -177,7 +177,6 @@ public class QuestionController {
@ResponseBody
@PreAuthorize("hasRole('ADMIN')")
public String delete(@PathVariable("id") int id) {
try {
Question q = qDao.findById(id).get();
qDao.delete(q);

View File

@@ -2,6 +2,7 @@ package sample.data.jpa.web;
import java.util.List;
import java.util.Map;
import java.util.Random;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -48,17 +49,28 @@ public class SessionController {
@PreAuthorize("hasRole('ADMIN')")
public String create(@RequestBody Map<String, String> body) {
String sId = "";
Session q = new Session();
Session session = new Session();
try {
if (body.containsKey("theme")) {
q.setTheme(body.get("theme"));
} else q.setTheme("");
sDao.save(q);
sId = String.valueOf(q.getId());
session.setTheme(body.getOrDefault("theme", ""));
int codePIN;
if (body.containsKey("codePIN")) {
codePIN = Integer.parseInt(body.get("codePIN"));
if (sDao.existsByCodePIN(codePIN)) {
return "Error: codePIN already exists.";
}
} else {
do {
codePIN = new Random().nextInt(900000) + 100000;
} while (sDao.existsByCodePIN(codePIN));
}
session.setCodePIN(codePIN);
sDao.save(session);
sId = String.valueOf(session.getId());
} catch (Exception ex) {
return "Error creating the Session : " + ex.toString();
}
return "Session \"" + q.getTheme() + "\" succesfully created with id = " + sId;
return "Session \"" + session.getTheme() + "\" successfully created with id = " + sId + " and codePIN = " + session.getCodePIN();
}
@DeleteMapping("/delete/{id}")