DTO and Resource test
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
# dependencies
|
# dependencies
|
||||||
/node_modules
|
/node_modules
|
||||||
/.pnp
|
/.pnp
|
||||||
|
|||||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"java.configuration.updateBuildConfiguration": "interactive"
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package hackathon.FrisbYEE.jpa.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ActiviteDTO {
|
||||||
|
private String name;
|
||||||
|
private String theme;
|
||||||
|
private Long duree; // optional, can be null
|
||||||
|
private List<String> dataActivite;
|
||||||
|
private Integer sessionId;
|
||||||
|
|
||||||
|
// Getters and Setters
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTheme() {
|
||||||
|
return theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTheme(String theme) {
|
||||||
|
this.theme = theme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getDuree() {
|
||||||
|
return duree;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDuree(Long duree) {
|
||||||
|
this.duree = duree;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getDataActivite() {
|
||||||
|
return dataActivite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDataActivite(List<String> dataActivite) {
|
||||||
|
this.dataActivite = dataActivite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getSessionId() {
|
||||||
|
return sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSessionId(Integer sessionId) {
|
||||||
|
this.sessionId = sessionId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ package hackathon.FrisbYEE.jpa.dto;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AthleteDTO implements java.io.Serializable {
|
public class AthleteDTO {
|
||||||
|
|
||||||
private String nom;
|
private String nom;
|
||||||
private String niveau;
|
private String niveau;
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package hackathon.FrisbYEE.rest;
|
||||||
|
|
||||||
|
import hackathon.FrisbYEE.jpa.dto.ActiviteDTO;
|
||||||
|
import hackathon.FrisbYEE.jpa.metier.Activite;
|
||||||
|
import hackathon.FrisbYEE.jpa.metier.Session;
|
||||||
|
import hackathon.FrisbYEE.jpa.service.ActiviteDAO;
|
||||||
|
import hackathon.FrisbYEE.jpa.service.SessionDAO;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@RequestMapping("/activite")
|
||||||
|
|
||||||
|
public class ActiviteResource {
|
||||||
|
@Autowired
|
||||||
|
private ActiviteDAO activiteDAO;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SessionDAO sessionDAO;
|
||||||
|
|
||||||
|
/*
|
||||||
|
POST /activite/create
|
||||||
|
DELETE /activite/delete/{id}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@ResponseBody
|
||||||
|
@PreAuthorize("hasRole('Coach')")
|
||||||
|
public String create(@RequestBody ActiviteDTO dto) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Session session = sessionDAO.findById(dto.getSessionId()).get();
|
||||||
|
Activite activite = new Activite();
|
||||||
|
activite.setName(dto.getName());
|
||||||
|
activite.setTheme(dto.getTheme());
|
||||||
|
activite.setDuree(dto.getDuree() != null ? dto.getDuree() : 0L);
|
||||||
|
activite.setDataActivite(dto.getDataActivite());
|
||||||
|
activite.setSession(session);
|
||||||
|
activiteDAO.save(activite);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return ex.toString();
|
||||||
|
}
|
||||||
|
return "ok";
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete/{id}")
|
||||||
|
@ResponseBody
|
||||||
|
@PreAuthorize("hasRole('Coach')")
|
||||||
|
public String delete(@PathVariable("id") int id) {
|
||||||
|
try {
|
||||||
|
Activite activite = activiteDAO.findById(id).get();
|
||||||
|
activiteDAO.delete(activite);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return ex.toString();
|
||||||
|
}
|
||||||
|
return "ok";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package hackathon.FrisbYEE.rest;
|
|
||||||
|
|
||||||
public class ActiviteResources {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,34 +1,28 @@
|
|||||||
package hackathon.FrisbYEE.jpa.web;
|
package hackathon.FrisbYEE.rest;
|
||||||
|
|
||||||
|
|
||||||
import hackathon.FrisbYEE.jpa.metier.Activite;
|
import hackathon.FrisbYEE.jpa.metier.Activite;
|
||||||
|
import hackathon.FrisbYEE.jpa.metier.Session;
|
||||||
import hackathon.FrisbYEE.jpa.service.ActiviteDAO;
|
import hackathon.FrisbYEE.jpa.service.ActiviteDAO;
|
||||||
|
import hackathon.FrisbYEE.jpa.service.SessionDAO;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/activite")
|
@RequestMapping("/session")
|
||||||
|
|
||||||
public class ActiviteController {
|
public class SessionResource {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ActiviteDAO activiteDAO;
|
private SessionDAO sessionDAO;
|
||||||
|
|
||||||
/*
|
|
||||||
POST /activite/create
|
|
||||||
DELETE /activite/delete/{id}
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@PreAuthorize("hasRole('Coach')")
|
@PreAuthorize("hasRole('Coach')")
|
||||||
public String create(@PathVariable("id") int id) {
|
public String create(@PathVariable("id") int id) {
|
||||||
String activiteID = "";
|
String sessionID = "";
|
||||||
String activiteNom = "";
|
|
||||||
try {
|
try {
|
||||||
Activite activite = new Activite();
|
Session session = new Session();
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
return ex.toString();
|
return ex.toString();
|
||||||
@@ -41,8 +35,8 @@ public class ActiviteController {
|
|||||||
@PreAuthorize("hasRole('Coach')")
|
@PreAuthorize("hasRole('Coach')")
|
||||||
public String delete(@PathVariable("id") int id) {
|
public String delete(@PathVariable("id") int id) {
|
||||||
try {
|
try {
|
||||||
Activite activite = activiteDAO.findById(id).get();
|
Session session = sessionDAO.findById(id).get();
|
||||||
activiteDAO.delete(activite);
|
sessionDAO.delete(session);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
return ex.toString();
|
return ex.toString();
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user