Commit 9aaaba98 authored by Alexandre Ducarne's avatar Alexandre Ducarne

Expose new services

parent 3f122569
package com.RESTAPI.RESTAPI.Controllers;
import com.RESTAPI.RESTAPI.Entities.Proposition;
import com.RESTAPI.RESTAPI.Repositories.PropositionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping(path="/proposition")
public class PropositionController {
@Autowired
private PropositionRepository propositionRepository;
@PutMapping(path = "/")
public @ResponseBody
Proposition create(@RequestBody Proposition proposition)
{
return proposition.getSujet() != null ? propositionRepository.save(proposition) : new Proposition();
}
@GetMapping(path = "/")
public @ResponseBody
Iterable<Proposition> getAll()
{
return propositionRepository.findAll();
}
}
\ No newline at end of file
package com.RESTAPI.RESTAPI.Controllers;
import com.RESTAPI.RESTAPI.Entities.Sujet;
import com.RESTAPI.RESTAPI.Repositories.SujetRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping(path="/sujet")
......@@ -11,9 +12,22 @@ public class SujetController {
@Autowired
private SujetRepository sujetRepository;
// @PutMapping(path = "/")
// public @ResponseBody
// Sujet createSujet(@RequestBody Sujet id) {
//// return compteRepository.findById(id).get();
// }
@PutMapping(path = "/")
public @ResponseBody
Sujet createSujet(@RequestBody Sujet sujet) {
sujetRepository.save(sujet);
return sujet;
}
@GetMapping(path = "/{id}")
public @ResponseBody
Sujet getSujetById(@PathVariable int id) {
return sujetRepository.findById(id).get();
}
@GetMapping(path = "/")
public @ResponseBody
Iterable<Sujet> getAllSujets() {
return sujetRepository.findAll();
}
}
\ No newline at end of file
......@@ -21,7 +21,6 @@ public class UserController {
public @ResponseBody
User addNewUser (@RequestBody User user) {
compteRepository.save(user.getCompte());
user.setCompte(user.getCompte());
userRepository.save(user);
return user;
}
......
package com.RESTAPI.RESTAPI.Controllers;
import com.RESTAPI.RESTAPI.Entities.Vote;
import com.RESTAPI.RESTAPI.Repositories.ConsultationRepository;
import com.RESTAPI.RESTAPI.Repositories.PropositionRepository;
import com.RESTAPI.RESTAPI.Repositories.VoteRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping(path="/vote")
public class VoteController {
@Autowired
private PropositionRepository propositionRepository;
@Autowired
private ConsultationRepository consultationRepository;
@Autowired
private VoteRepository voteRepository;
@PutMapping(path="/")
public Vote vote(@RequestBody Vote vote) {
return voteRepository.save(vote);
}
}
\ No newline at end of file
package com.RESTAPI.RESTAPI.Entities;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
@Entity
@Getter
@Setter
public class Consultation {
@Id
......@@ -13,6 +17,4 @@ public class Consultation {
private Date dateConsultation;
@ManyToOne
private Sujet sujet;
@ManyToMany
List<Avis> avis;
}
package com.RESTAPI.RESTAPI.Entities;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
@Entity
@Getter
@Setter
public class Proposition {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
......
package com.RESTAPI.RESTAPI.Entities;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
......@@ -7,6 +10,8 @@ import javax.persistence.Id;
import java.util.Date;
@Entity
@Getter
@Setter
public class Sujet {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
......
package com.RESTAPI.RESTAPI.Entities;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
@Entity
public class Avis {
@Getter
@Setter
public class Vote {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer id;
private String choix;
private String commentaire;
@ManyToOne
Consultation consultation;
@ManyToOne
Proposition proposition;
String choix;
String commentaire;
}
package com.RESTAPI.RESTAPI.Repositories;
import com.RESTAPI.RESTAPI.Entities.Consultation;
import org.springframework.data.repository.CrudRepository;
public interface ConsultationRepository extends CrudRepository<Consultation, Integer> {
}
package com.RESTAPI.RESTAPI.Repositories;
import com.RESTAPI.RESTAPI.Entities.Proposition;
import org.springframework.data.repository.CrudRepository;
public interface PropositionRepository extends CrudRepository<Proposition, Integer> {
}
package com.RESTAPI.RESTAPI.Repositories;
import com.RESTAPI.RESTAPI.Entities.Compte;
import com.RESTAPI.RESTAPI.Entities.Sujet;
import org.springframework.data.repository.CrudRepository;
public interface SujetRepository extends CrudRepository<Compte, Integer> {
public interface SujetRepository extends CrudRepository<Sujet, Integer> {
}
package com.RESTAPI.RESTAPI.Repositories;
import com.RESTAPI.RESTAPI.Entities.Vote;
import org.springframework.data.repository.CrudRepository;
public interface VoteRepository extends CrudRepository<Vote, Integer> {
}
spring.datasource.url=jdbc:mysql://localhost:3306/restAPI?serverTimezone=UTC
spring.datasource.username=root
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment