many improvements mais flm
This commit is contained in:
parent
7e12f6a838
commit
20568ed0b2
@ -1,7 +1,5 @@
|
||||
package fr.la_banquise.backend.data.model;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
@ -29,25 +27,20 @@ public class Instance {
|
||||
allocationSize = 1, initialValue = 1)
|
||||
public Long id;
|
||||
|
||||
@Column(unique = true, nullable = false)
|
||||
public String name;
|
||||
@Column(unique = true, nullable = false) public String name;
|
||||
// So people cant have more than one
|
||||
// container per JI because name will be login-jiId
|
||||
|
||||
public int port;
|
||||
|
||||
//@JsonBackReference
|
||||
@JsonIgnore
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
public User owner;
|
||||
|
||||
//@ManyToOne @JoinColumn(name = "ji_id", nullable = false) public Ji ji;
|
||||
|
||||
public Instance(String name, int port, User user ) {//, Ji ji) {
|
||||
public Instance(String name, int port, User user) {
|
||||
this.name = name;
|
||||
this.port = port;
|
||||
this.owner = user;
|
||||
//this.ji = ji;
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,6 +30,11 @@ public class Ji {
|
||||
public Long id;
|
||||
public String name;
|
||||
public String description;
|
||||
public String date;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "site_id") //@JsonIgnore
|
||||
public Site site;
|
||||
|
||||
@JsonIgnore
|
||||
@ManyToMany
|
||||
@ -45,12 +50,6 @@ public class Ji {
|
||||
inverseJoinColumns = @JoinColumn(name = "user_id"))
|
||||
public List<User> participants;
|
||||
|
||||
public String date;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "site_id") //@JsonIgnore
|
||||
public Site site;
|
||||
|
||||
@OneToMany @JoinColumn(name = "instance_id") public List<Instance> instances;
|
||||
|
||||
public Ji(String name, String description, List<User> respos, String date,
|
||||
@ -61,5 +60,6 @@ public class Ji {
|
||||
this.date = date;
|
||||
this.site = site;
|
||||
this.participants = new ArrayList<User>();
|
||||
this.instances = new ArrayList<Instance>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package fr.la_banquise.backend.data.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
@ -34,15 +33,12 @@ public class Site {
|
||||
public String description;
|
||||
public String address;
|
||||
|
||||
/*@OneToMany(mappedBy = "ji", cascade = CascadeType.ALL)
|
||||
public List<Instance> instances;*/
|
||||
|
||||
@OneToMany(mappedBy = "site") @JsonIgnore public List<Ji> jiInSite;
|
||||
@OneToMany(mappedBy = "site") @JsonIgnore public List<Ji> listJi;
|
||||
|
||||
public Site(String name, String description, String address) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.address = address;
|
||||
this.jiInSite = new ArrayList<Ji>();
|
||||
this.listJi = new ArrayList<Ji>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,9 +43,9 @@ public class JiResource {
|
||||
public Response createJi(@QueryParam("name") String name,
|
||||
@QueryParam("date") String date,
|
||||
@QueryParam("respo") String respo,
|
||||
@QueryParam("site") String name_site) {
|
||||
@QueryParam("site_id") Long siteId) {
|
||||
try {
|
||||
Ji jsp = jiService.createJi(name, date, respo, name_site);
|
||||
Ji jsp = jiService.createJi(name, date, respo, siteId);
|
||||
return Response.ok(Map.of("created", jsp)).build();
|
||||
} catch (Exception e) {
|
||||
return Response.status(500)
|
||||
|
||||
@ -71,7 +71,7 @@ public class SiteEndpoints {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{name}")
|
||||
@Path("/{ID}")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Authenticated
|
||||
@Operation(summary = "Gets a site with its name", description = "")
|
||||
@ -83,9 +83,9 @@ public class SiteEndpoints {
|
||||
})
|
||||
|
||||
public Response
|
||||
getSiteByName(@PathParam("name") String name) {
|
||||
getSite(@PathParam("ID") Long id) {
|
||||
try {
|
||||
Site site = siteService.getSiteByName(name);
|
||||
Site site = siteService.getSite(id);
|
||||
return Response.ok(site.toString()).build();
|
||||
} catch (Exception e) {
|
||||
return Response.status(500)
|
||||
@ -111,9 +111,9 @@ public class SiteEndpoints {
|
||||
"Internal server error, usually site not found")
|
||||
})
|
||||
public Response
|
||||
deleteSiteByName(@QueryParam("name") String name) {
|
||||
deleteSite(@QueryParam("ID") Long id) {
|
||||
try {
|
||||
boolean retour = siteService.deleteSiteByName(name);
|
||||
boolean retour = siteService.deleteSite(id);
|
||||
if (retour) {
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@ -23,8 +23,8 @@ public class JiService {
|
||||
|
||||
@Transactional
|
||||
public Ji createJi(String name, String description, String address,
|
||||
String site_name) {
|
||||
Site site = siteService.getSiteByName(site_name);
|
||||
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);
|
||||
|
||||
@ -28,38 +28,24 @@ public class SiteService {
|
||||
|
||||
public List<Site> getAllSites() { return siteRepository.listAll(); }
|
||||
|
||||
public Site getSiteByName(String name) {
|
||||
return siteRepository.find("name", name).firstResult();
|
||||
}
|
||||
|
||||
public Site getSiteById(Long id) { return siteRepository.findById(id); }
|
||||
public Site getSite(Long id) { return siteRepository.findById(id); }
|
||||
|
||||
@Transactional
|
||||
public void addJi(Site site, Ji ji) {
|
||||
site.jiInSite.add(ji);
|
||||
site.listJi.add(ji);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void removeJi(Site site, Ji ji) {
|
||||
site.jiInSite.remove(ji);
|
||||
site.listJi.remove(ji);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean deleteSiteById(Long id) {
|
||||
if (getSiteById(id).jiInSite.isEmpty()) {
|
||||
public boolean deleteSite(Long id) {
|
||||
if (getSite(id).listJi.isEmpty()) {
|
||||
siteRepository.deleteById(id);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public boolean deleteSiteByName(String name) {
|
||||
Site site = getSiteByName(name);
|
||||
if (site.jiInSite.isEmpty()) {
|
||||
siteRepository.delete(site);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user