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; package com.RESTAPI.RESTAPI.Controllers;
import com.RESTAPI.RESTAPI.Entities.Sujet;
import com.RESTAPI.RESTAPI.Repositories.SujetRepository; import com.RESTAPI.RESTAPI.Repositories.SujetRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*;
@Controller @Controller
@RequestMapping(path="/sujet") @RequestMapping(path="/sujet")
...@@ -11,9 +12,22 @@ public class SujetController { ...@@ -11,9 +12,22 @@ public class SujetController {
@Autowired @Autowired
private SujetRepository sujetRepository; private SujetRepository sujetRepository;
// @PutMapping(path = "/") @PutMapping(path = "/")
// public @ResponseBody public @ResponseBody
// Sujet createSujet(@RequestBody Sujet id) { Sujet createSujet(@RequestBody Sujet sujet) {
//// return compteRepository.findById(id).get(); 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 { ...@@ -21,7 +21,6 @@ public class UserController {
public @ResponseBody public @ResponseBody
User addNewUser (@RequestBody User user) { User addNewUser (@RequestBody User user) {
compteRepository.save(user.getCompte()); compteRepository.save(user.getCompte());
user.setCompte(user.getCompte());
userRepository.save(user); userRepository.save(user);
return 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; package com.RESTAPI.RESTAPI.Entities;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*; import javax.persistence.*;
import java.util.Date; import java.util.Date;
import java.util.List;
@Entity @Entity
@Getter
@Setter
public class Consultation { public class Consultation {
@Id @Id
...@@ -13,6 +17,4 @@ public class Consultation { ...@@ -13,6 +17,4 @@ public class Consultation {
private Date dateConsultation; private Date dateConsultation;
@ManyToOne @ManyToOne
private Sujet sujet; private Sujet sujet;
@ManyToMany
List<Avis> avis;
} }
package com.RESTAPI.RESTAPI.Entities; package com.RESTAPI.RESTAPI.Entities;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*; import javax.persistence.*;
@Entity @Entity
@Getter
@Setter
public class Proposition { public class Proposition {
@Id @Id
@GeneratedValue(strategy= GenerationType.IDENTITY) @GeneratedValue(strategy= GenerationType.IDENTITY)
......
package com.RESTAPI.RESTAPI.Entities; package com.RESTAPI.RESTAPI.Entities;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
...@@ -7,6 +10,8 @@ import javax.persistence.Id; ...@@ -7,6 +10,8 @@ import javax.persistence.Id;
import java.util.Date; import java.util.Date;
@Entity @Entity
@Getter
@Setter
public class Sujet { public class Sujet {
@Id @Id
@GeneratedValue(strategy= GenerationType.IDENTITY) @GeneratedValue(strategy= GenerationType.IDENTITY)
......
package com.RESTAPI.RESTAPI.Entities; package com.RESTAPI.RESTAPI.Entities;
import javax.persistence.Entity; import lombok.Getter;
import javax.persistence.GeneratedValue; import lombok.Setter;
import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.*;
@Entity @Entity
public class Avis { @Getter
@Setter
public class Vote {
@Id @Id
@GeneratedValue(strategy= GenerationType.IDENTITY) @GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer id; 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; package com.RESTAPI.RESTAPI.Repositories;
import com.RESTAPI.RESTAPI.Entities.Compte; import com.RESTAPI.RESTAPI.Entities.Sujet;
import org.springframework.data.repository.CrudRepository; 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.url=jdbc:mysql://localhost:3306/restAPI?serverTimezone=UTC
spring.datasource.username=root spring.datasource.username=root
spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.ddl-auto=update
\ No newline at end of file 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