DTO and Resource test
This commit is contained in:
@@ -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;
|
||||
|
||||
public class AthleteDTO implements java.io.Serializable {
|
||||
public class AthleteDTO {
|
||||
|
||||
private String nom;
|
||||
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.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")
|
||||
@RequestMapping("/session")
|
||||
|
||||
public class ActiviteController {
|
||||
public class SessionResource {
|
||||
@Autowired
|
||||
private ActiviteDAO activiteDAO;
|
||||
|
||||
/*
|
||||
POST /activite/create
|
||||
DELETE /activite/delete/{id}
|
||||
|
||||
*/
|
||||
private SessionDAO sessionDAO;
|
||||
|
||||
@PostMapping("/create")
|
||||
@ResponseBody
|
||||
@PreAuthorize("hasRole('Coach')")
|
||||
public String create(@PathVariable("id") int id) {
|
||||
String activiteID = "";
|
||||
String activiteNom = "";
|
||||
String sessionID = "";
|
||||
try {
|
||||
Activite activite = new Activite();
|
||||
Session session = new Session();
|
||||
|
||||
} catch (Exception ex) {
|
||||
return ex.toString();
|
||||
@@ -41,8 +35,8 @@ public class ActiviteController {
|
||||
@PreAuthorize("hasRole('Coach')")
|
||||
public String delete(@PathVariable("id") int id) {
|
||||
try {
|
||||
Activite activite = activiteDAO.findById(id).get();
|
||||
activiteDAO.delete(activite);
|
||||
Session session = sessionDAO.findById(id).get();
|
||||
sessionDAO.delete(session);
|
||||
} catch (Exception ex) {
|
||||
return ex.toString();
|
||||
}
|
||||
Reference in New Issue
Block a user