fix: affichage login, affichage donnees instance

This commit is contained in:
Arthur Wambst 2025-10-19 18:41:14 +02:00
parent 8f8fc804f8
commit 887f757719
No known key found for this signature in database
9 changed files with 53 additions and 24 deletions

View File

@ -1,6 +1,5 @@
package fr.la_banquise.backend.data.model;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;

View File

@ -55,6 +55,7 @@ public class User {
@CollectionTable(name = "user_roles")
public Set<RolesAsso> role;
public String email;
///////////////////////////////////////////////////////////////////////////
// Dans l'ordre d'affichage dans le dashboard :
@ManyToMany(mappedBy = "respos", cascade = CascadeType.ALL)
@ -80,7 +81,7 @@ public class User {
.collect(Collectors.toSet());
}
public User(String name, String password, RolesAsso role) {
public User(String name, String password, RolesAsso role, String mail) {
this.name = name;
this.password = password;
if (role == RolesAsso.NONE)
@ -88,5 +89,6 @@ public class User {
else
this.role = new HashSet<>(Arrays.asList(role));
this.instances = new ArrayList<>();
this.email = mail;
}
}

View File

@ -2,6 +2,8 @@ package fr.la_banquise.backend.rest;
import fr.la_banquise.backend.services.InstanceService;
import fr.la_banquise.backend.services.JiService;
import fr.la_banquise.backend.services.UserService;
import io.quarkus.security.Authenticated;
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.annotation.security.RolesAllowed;
import jakarta.inject.Inject;
@ -25,6 +27,7 @@ public class InstanceEndpoints {
@Inject JiService jiService;
@Inject InstanceService instanceService;
@Inject UserService userService;
@GET
@RolesAllowed("ROOT")
@ -33,6 +36,15 @@ public class InstanceEndpoints {
return Response.ok(instanceService.getAllInstances()).build();
}
@GET
@Authenticated
@Path("/{id}/instances")
public Response getMyInstancesJi(@PathParam("id") Long jiId) {
String name = identity.getPrincipal().getName();
Long userId = userService.getId(name);
return Response.ok(jiService.getInstance(jiId, userId)).build();
}
@POST
@Path("/{id}/instance")
public Response createInstance(@PathParam("id") Long jiId,
@ -44,14 +56,16 @@ public class InstanceEndpoints {
@POST
@Path("/{id}/instance/container")
public Response createContainer(@PathParam("id") Long jiId,
@QueryParam("username") String username) {
@QueryParam("username") String username) {
return Response.ok(jiService.createContainer(jiId, username)).build();
}
@GET
@Path("/{id}/instance/container")
public Response getStatusContainer(@PathParam("id") Long jiId,
@QueryParam("username") String username) {
return Response.ok(jiService.getStatusContainer(jiId, username)).build();
public Response
getStatusContainer(@PathParam("id") Long jiId,
@QueryParam("username") String username) {
return Response.ok(jiService.getStatusContainer(jiId, username))
.build();
}
}

View File

@ -42,10 +42,10 @@ public class JiEndpoints {
@RolesAllowed("ROOT")
public Response createJi(@QueryParam("name") String name,
@QueryParam("date") String date,
@QueryParam("respo") String respo,
@QueryParam("desc") String desc,
@QueryParam("site_id") Long siteId) {
try {
Long id = jiService.createJi(name, date, respo, siteId).id;
Long id = jiService.createJi(name, desc, date, siteId).id;
return Response.ok(Map.of("id", id)).build();
} catch (Exception e) {
return Response.status(500)

View File

@ -48,14 +48,11 @@ public class UsersEndpoints {
// existing JIs
public Response createUsersBulk(BulkUserPostRequest request) {
BulkUserPostResponse response = userService.createUsers(request);
if (response.successNames.size() == request.users.size())
return Response.ok().build();
if (response.successNames.size() == 0)
return Response.status(500).build();
return Response.status(202)
.entity(Map.of("These users were already created : ",
response.alreadyCreated))
.build();
if (response.successMails.size() == request.users.size())
return Response.ok(response).build();
if (response.successMails.size() == 0)
return Response.status(500).entity(response).build();
return Response.status(202).entity(response).build();
}
@DELETE

View File

@ -7,11 +7,13 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
public class BulkUserPostResponse {
public List<String> successNames;
public List<String> successMails;
public List<String> successPasswd;
public List<String> alreadyCreated;
public BulkUserPostResponse() {
this.successNames = new ArrayList<String>();
this.successMails = new ArrayList<String>();
this.successPasswd = new ArrayList<String>();
this.alreadyCreated = new ArrayList<String>();
}
}

View File

@ -22,12 +22,12 @@ public class JiService {
@Inject SecurityContext security;
@Transactional
public Ji createJi(String name, String description, String address,
public Ji createJi(String name, String description, String date,
Long siteId) {
Site site = siteService.getSite(siteId);
User currentUser =
userRepository.findByName(security.getUserPrincipal().getName());
Ji ji = new Ji(name, description, List.of(currentUser), "date", site);
Ji ji = new Ji(name, description, List.of(currentUser), date, site);
jiRepository.persist(ji);
siteService.addJi(site, ji);
return ji;
@ -40,7 +40,6 @@ public class JiService {
return user.jiRespo;
}
public Ji getJi(Long id) { return jiRepository.findById(id); }
@Transactional
@ -58,6 +57,17 @@ public class JiService {
return instance;
}
@Transactional
public Instance getInstance(Long jiId, Long userId) {
Ji ji = jiRepository.findById(jiId);
for (Instance inst : ji.instances) {
if (inst.owner.id == userId) {
return inst;
}
}
throw new Error("Instance or user not found");
}
@Transactional
public String createContainer(Long id, String username) {
Ji ji = jiRepository.findById(id);

View File

@ -32,12 +32,15 @@ public class UserService {
public User getUser(Long id) { return userRepository.findById(id); }
public User getUser(String name) { return userRepository.findByName(name); }
public Long getId(String name) {
return userRepository.findByName(name).id;
}
@Transactional
public UserPostResponse createUser(UserRequest request, String code) {
User user = new User(request.name,
BcryptUtil.bcryptHash(request.name.concat(code)),
RolesAsso.NONE);
RolesAsso.NONE, request.email);
userRepository.persist(user);
String passwd = request.name.concat(code);
UserPostResponse retour = new UserPostResponse(user, passwd);
@ -101,7 +104,9 @@ public class UserService {
Random rand = new Random();
int random = rand.nextInt(8999) + 1000;
createUser(user, String.valueOf(random));
response.successNames.add(user.name);
response.successMails.add(user.email);
response.successPasswd.add(user.name +
String.valueOf(random));
} catch (Exception e) {
response.alreadyCreated.add(user.name);
}

@ -1 +1 @@
Subproject commit 8c04856614474d177ec8fc5140ed0e780ceb6530
Subproject commit 69955ac4336fc9c492bbe24b23c8098f7afb69ab