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; package fr.la_banquise.backend.data.model;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType; import jakarta.persistence.GenerationType;

View File

@ -55,6 +55,7 @@ public class User {
@CollectionTable(name = "user_roles") @CollectionTable(name = "user_roles")
public Set<RolesAsso> role; public Set<RolesAsso> role;
public String email;
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Dans l'ordre d'affichage dans le dashboard : // Dans l'ordre d'affichage dans le dashboard :
@ManyToMany(mappedBy = "respos", cascade = CascadeType.ALL) @ManyToMany(mappedBy = "respos", cascade = CascadeType.ALL)
@ -80,7 +81,7 @@ public class User {
.collect(Collectors.toSet()); .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.name = name;
this.password = password; this.password = password;
if (role == RolesAsso.NONE) if (role == RolesAsso.NONE)
@ -88,5 +89,6 @@ public class User {
else else
this.role = new HashSet<>(Arrays.asList(role)); this.role = new HashSet<>(Arrays.asList(role));
this.instances = new ArrayList<>(); 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.InstanceService;
import fr.la_banquise.backend.services.JiService; 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 io.quarkus.security.identity.SecurityIdentity;
import jakarta.annotation.security.RolesAllowed; import jakarta.annotation.security.RolesAllowed;
import jakarta.inject.Inject; import jakarta.inject.Inject;
@ -25,6 +27,7 @@ public class InstanceEndpoints {
@Inject JiService jiService; @Inject JiService jiService;
@Inject InstanceService instanceService; @Inject InstanceService instanceService;
@Inject UserService userService;
@GET @GET
@RolesAllowed("ROOT") @RolesAllowed("ROOT")
@ -33,6 +36,15 @@ public class InstanceEndpoints {
return Response.ok(instanceService.getAllInstances()).build(); 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 @POST
@Path("/{id}/instance") @Path("/{id}/instance")
public Response createInstance(@PathParam("id") Long jiId, public Response createInstance(@PathParam("id") Long jiId,
@ -50,8 +62,10 @@ public class InstanceEndpoints {
@GET @GET
@Path("/{id}/instance/container") @Path("/{id}/instance/container")
public Response getStatusContainer(@PathParam("id") Long jiId, public Response
getStatusContainer(@PathParam("id") Long jiId,
@QueryParam("username") String username) { @QueryParam("username") String username) {
return Response.ok(jiService.getStatusContainer(jiId, username)).build(); return Response.ok(jiService.getStatusContainer(jiId, username))
.build();
} }
} }

View File

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

View File

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

View File

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

View File

@ -22,12 +22,12 @@ public class JiService {
@Inject SecurityContext security; @Inject SecurityContext security;
@Transactional @Transactional
public Ji createJi(String name, String description, String address, public Ji createJi(String name, String description, String date,
Long siteId) { Long siteId) {
Site site = siteService.getSite(siteId); Site site = siteService.getSite(siteId);
User currentUser = User currentUser =
userRepository.findByName(security.getUserPrincipal().getName()); 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); jiRepository.persist(ji);
siteService.addJi(site, ji); siteService.addJi(site, ji);
return ji; return ji;
@ -40,7 +40,6 @@ public class JiService {
return user.jiRespo; return user.jiRespo;
} }
public Ji getJi(Long id) { return jiRepository.findById(id); } public Ji getJi(Long id) { return jiRepository.findById(id); }
@Transactional @Transactional
@ -58,6 +57,17 @@ public class JiService {
return instance; 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 @Transactional
public String createContainer(Long id, String username) { public String createContainer(Long id, String username) {
Ji ji = jiRepository.findById(id); 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(Long id) { return userRepository.findById(id); }
public User getUser(String name) { return userRepository.findByName(name); } public User getUser(String name) { return userRepository.findByName(name); }
public Long getId(String name) {
return userRepository.findByName(name).id;
}
@Transactional @Transactional
public UserPostResponse createUser(UserRequest request, String code) { public UserPostResponse createUser(UserRequest request, String code) {
User user = new User(request.name, User user = new User(request.name,
BcryptUtil.bcryptHash(request.name.concat(code)), BcryptUtil.bcryptHash(request.name.concat(code)),
RolesAsso.NONE); RolesAsso.NONE, request.email);
userRepository.persist(user); userRepository.persist(user);
String passwd = request.name.concat(code); String passwd = request.name.concat(code);
UserPostResponse retour = new UserPostResponse(user, passwd); UserPostResponse retour = new UserPostResponse(user, passwd);
@ -101,7 +104,9 @@ public class UserService {
Random rand = new Random(); Random rand = new Random();
int random = rand.nextInt(8999) + 1000; int random = rand.nextInt(8999) + 1000;
createUser(user, String.valueOf(random)); 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) { } catch (Exception e) {
response.alreadyCreated.add(user.name); response.alreadyCreated.add(user.name);
} }

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