feat: port and tp changes

This commit is contained in:
Malo BEAUCHAMPS 2024-10-21 14:01:39 +02:00
parent 291ec7e8f3
commit 927c117822
4 changed files with 11 additions and 7 deletions

View File

@ -32,7 +32,7 @@ public class InstanceEndpoints {
@POST @POST
public Response createInstance(InstanceRequest request) { public Response createInstance(InstanceRequest request) {
instanceService.createInstance(request.name, request.ssh, request.pwd, request.username, request.tpId); instanceService.createInstance(request.name, request.ssh, request.pwd, request.port, request.username, request.tpId);
return Response.ok().build(); return Response.ok().build();
} }
} }

View File

@ -10,6 +10,7 @@ public class InstanceRequest {
public String ssh; public String ssh;
public String pwd; public String pwd;
public String username; public String username;
public Long port;
@Nullable @Nullable
public Long tpId; public Long tpId;
} }

View File

@ -20,4 +20,6 @@ public class PracticalResponse {
public String pwd; public String pwd;
@Nullable @Nullable
public String ssh; public String ssh;
@Nullable
public Long port;
} }

View File

@ -1,5 +1,6 @@
package fr.la_banquise.backend.services; package fr.la_banquise.backend.services;
import java.text.Collator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -39,18 +40,18 @@ public class TpService {
} }
public List<Tp> getAllTps(String username) { public List<Tp> getAllTps(String username) {
return tpRepository.listAll().stream() User user = userRepository.findByName(username);
.filter(tp -> instanceRepository.find("name = ?1 AND tp = ?2", username, tp) == null) List<Instance> instances = instanceRepository.find("user = ?1 AND tp IS NOT NULL", user).list();
.collect(Collectors.toList()); return tpRepository.find("id in ?1", instances.stream().map(i -> i.tp.id).collect(Collectors.toList())).list();
} }
public PracticalResponse getTp(Long id, String username) { public PracticalResponse getTp(Long id, String username) {
User user = userRepository.findByName(username); User user = userRepository.findByName(username);
Tp tp = tpRepository.findById(id); Tp tp = tpRepository.findById(id);
Instance instance = instanceRepository.find("name = ?1 AND tp = ?2", user.name, tp).firstResult(); Instance instance = instanceRepository.find("user = ?1 AND tp = ?2", user, tp).firstResult();
PracticalResponse res = new PracticalResponse(tp.name, tp.description, tp.pdfLink, tp.respo, tp.date, PracticalResponse res = new PracticalResponse(tp.name, tp.description, tp.pdfLink, tp.respo, tp.date,
instance.name, instance.name,
instance.pwd, instance.ssh); instance.pwd, instance.ssh, instance.port);
return res; return res;
} }
@ -58,7 +59,7 @@ public class TpService {
Tp tp = tpRepository.findById(id); Tp tp = tpRepository.findById(id);
return new PracticalResponse(tp.name, tp.description, tp.pdfLink, tp.respo, tp.date, return new PracticalResponse(tp.name, tp.description, tp.pdfLink, tp.respo, tp.date,
"", "",
"", ""); "", "", 0L);
} }
@Transactional @Transactional