feat: port instances
This commit is contained in:
parent
ee40c425de
commit
291ec7e8f3
@ -9,6 +9,7 @@ import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.SequenceGenerator;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@ -21,9 +22,11 @@ import lombok.NoArgsConstructor;
|
||||
public class Instance {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@SequenceGenerator(name = "InstanceSeq", sequenceName = "instance_id_seq", allocationSize = 1, initialValue = 1)
|
||||
public Long id;
|
||||
public String name;
|
||||
public String ssh;
|
||||
public Long port;
|
||||
public String pwd;
|
||||
|
||||
@JsonBackReference
|
||||
@ -31,15 +34,16 @@ public class Instance {
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
public User user;
|
||||
|
||||
@ManyToOne
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "practical_id")
|
||||
public Tp tp;
|
||||
|
||||
public Instance(String name, String ssh, String pwd, User user, Tp tp) {
|
||||
this.name = name;
|
||||
this.ssh = ssh;
|
||||
this.pwd = pwd;
|
||||
this.user = user;
|
||||
this.tp = tp;
|
||||
}
|
||||
public Instance(String name, String ssh, String pwd, Long port, User user, Tp tp) {
|
||||
this.name = name;
|
||||
this.ssh = ssh;
|
||||
this.pwd = pwd;
|
||||
this.port = port;
|
||||
this.user = user;
|
||||
this.tp = tp;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.SequenceGenerator;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
@ -19,6 +20,7 @@ import lombok.NoArgsConstructor;
|
||||
public class Tp {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@SequenceGenerator(name = "TpSeq", sequenceName = "tp_id_seq", allocationSize = 1, initialValue = 1)
|
||||
public Long id;
|
||||
public String name;
|
||||
public String description;
|
||||
@ -26,11 +28,11 @@ public class Tp {
|
||||
public String respo;
|
||||
public String date;
|
||||
|
||||
public Tp(String name, String description, String pdfLink, String respo, String date) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.pdfLink = pdfLink;
|
||||
this.respo = respo;
|
||||
this.date = date;
|
||||
}
|
||||
public Tp(String name, String description, String pdfLink, String respo, String date) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.pdfLink = pdfLink;
|
||||
this.respo = respo;
|
||||
this.date = date;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.SequenceGenerator;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@ -28,6 +29,7 @@ import lombok.Setter;
|
||||
public class User {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@SequenceGenerator(name = "UserSeq", sequenceName = "user_id_seq", allocationSize = 1, initialValue = 1)
|
||||
public Long id;
|
||||
public String name;
|
||||
|
||||
|
@ -6,4 +6,9 @@ package fr.la_banquise.backend.rest.request;
|
||||
public class UserRequest {
|
||||
public String name;
|
||||
public String email;
|
||||
public String password;
|
||||
public String instance_name;
|
||||
public String instance_ssh;
|
||||
public Long instance_port;
|
||||
public String instance_pwd;
|
||||
}
|
||||
|
@ -41,18 +41,18 @@ public class InstanceService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Instance createInstance(String name, String ssh, String pwd, String username, Long tpId) {
|
||||
public Instance createInstance(String name, String ssh, String pwd, Long port, String username, Long tpId) {
|
||||
User user = userRepository.findByName(username);
|
||||
Tp tp = tpRepository.findById(tpId);
|
||||
Instance instance = new Instance(name, ssh, pwd, user, tp);
|
||||
Instance instance = new Instance(name, ssh, pwd, port, user, tp);
|
||||
instanceRepository.persist(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Instance createInstance(String name, String ssh, String pwd, User user, Long tpId) {
|
||||
public Instance createInstance(String name, String ssh, String pwd, Long port, User user, Long tpId) {
|
||||
Tp tp = tpRepository.findById(tpId);
|
||||
Instance instance = new Instance(name, ssh, pwd, user, tp);
|
||||
Instance instance = new Instance(name, ssh, pwd, port, user, tp);
|
||||
instanceRepository.persist(instance);
|
||||
return instance;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package fr.la_banquise.backend.services;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import fr.la_banquise.backend.data.model.Instance;
|
||||
|
@ -55,7 +55,9 @@ public class UserService {
|
||||
for (UserRequest user : usersRequest.users) {
|
||||
User newUser = createUser(user.name);
|
||||
users.add(newUser);
|
||||
instanceService.createInstance("test", "test", "test", user.name, usersRequest.tpId);
|
||||
instanceService.createInstance(user.instance_name, user.instance_ssh, user.instance_pwd, user.instance_port,
|
||||
user.name,
|
||||
usersRequest.tpId);
|
||||
}
|
||||
return new ArrayList<User>();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user