Commit 1273d6bb authored by Alexandre Ducarne's avatar Alexandre Ducarne

Change exposed services to English, refactor var types

parent 4ba553cc
package com.RESTAPI.RESTAPI.Controllers;
import com.RESTAPI.RESTAPI.Entities.Compte;
import com.RESTAPI.RESTAPI.Repositories.CompteRepository;
import com.RESTAPI.RESTAPI.Requests.CompteRequest;
import com.RESTAPI.RESTAPI.Entities.Account;
import com.RESTAPI.RESTAPI.Repositories.AccountRepository;
import com.RESTAPI.RESTAPI.Requests.AccountRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.time.LocalDate;
@Controller
@RequestMapping(path="/compte")
public class CompteController {
@RequestMapping(path = "/account")
public class AccountController {
@Autowired
private CompteRepository compteRepository;
private AccountRepository accountRepository;
@PutMapping(path="/")
public Compte create(@RequestBody CompteRequest compteRequest) {
Compte compte = Compte.builder()
.email(compteRequest.getEmail())
.mdp(compteRequest.getMdp())
.status(compteRequest.getStatus())
.dateCreation(new Date())
public ResponseEntity<Account> create(@RequestBody AccountRequest accountRequest) {
Account account = Account.builder()
.email(accountRequest.getEmail())
.pwd(accountRequest.getPwd())
.isActive(accountRequest.getIsActive())
.creationDate(LocalDate.now())
.build();
compteRepository.save(compte);
return compte;
return new ResponseEntity<>(accountRepository.save(account), HttpStatus.OK);
}
@GetMapping(path = "/{id}")
public @ResponseBody
ResponseEntity<Compte> getById(@PathVariable Integer id) {
return compteRepository
ResponseEntity<Account> getById(@PathVariable Integer id) {
return accountRepository
.findById(id)
.map(result -> new ResponseEntity<>(result, HttpStatus.OK))
.orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
......@@ -41,14 +40,14 @@ public class CompteController {
@GetMapping(path="/")
public @ResponseBody
Iterable<Compte> getAll() {
return compteRepository.findAll();
Iterable<Account> getAll() {
return accountRepository.findAll();
}
@DeleteMapping(path="/{id}")
public ResponseEntity<Integer> delete(@PathVariable int id) {
try {
compteRepository.deleteById(id);
accountRepository.deleteById(id);
}
catch (Exception e) {
return new ResponseEntity<>(id, HttpStatus.NOT_FOUND);
......
......@@ -8,6 +8,9 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.Objects;
@Controller
@RequestMapping(path="/consultation")
public class ConsultationController {
......@@ -18,7 +21,11 @@ public class ConsultationController {
public @ResponseBody
Consultation create(@RequestBody Consultation consultation)
{
return consultation.getSujet() != null ? consultationRepository.save(consultation) : new Consultation();
consultation.setReviewDate(LocalDateTime.now());
return Objects.nonNull(consultation.getSubject()) ?
consultationRepository.save(consultation)
: new Consultation();
}
@GetMapping(path = "/")
......
......@@ -8,6 +8,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Objects;
@Controller
@RequestMapping(path="/proposition")
public class PropositionController {
......@@ -18,7 +20,9 @@ public class PropositionController {
public @ResponseBody
ResponseEntity<Proposition> create(@RequestBody Proposition proposition)
{
return proposition.getSujet() != null ? new ResponseEntity<>(propositionRepository.save(proposition), HttpStatus.OK) : new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
return Objects.nonNull(proposition.getSubject()) ?
new ResponseEntity<>(propositionRepository.save(proposition), HttpStatus.OK)
: new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
}
@GetMapping(path = "/")
......
package com.RESTAPI.RESTAPI.Controllers;
import com.RESTAPI.RESTAPI.Entities.Sujet;
import com.RESTAPI.RESTAPI.Repositories.SujetRepository;
import com.RESTAPI.RESTAPI.Entities.Subject;
import com.RESTAPI.RESTAPI.Repositories.SubjectRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -9,28 +9,28 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@Controller
@RequestMapping(path="/sujet")
public class SujetController {
@RequestMapping(path = "/subject")
public class SubjectController {
@Autowired
private SujetRepository sujetRepository;
private SubjectRepository subjectRepository;
@PutMapping(path = "/")
public @ResponseBody
Sujet create(@RequestBody Sujet sujet) {
return sujetRepository.save(sujet);
Subject create(@RequestBody Subject subject) {
return subjectRepository.save(subject);
}
@GetMapping(path = "/{id}")
public @ResponseBody
ResponseEntity<Sujet> getById(@PathVariable int id) {
return sujetRepository.findById(id)
ResponseEntity<Subject> getById(@PathVariable int id) {
return subjectRepository.findById(id)
.map(result -> new ResponseEntity<>(result, HttpStatus.OK))
.orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
@GetMapping(path = "/")
public @ResponseBody
Iterable<Sujet> getAll() {
return sujetRepository.findAll();
Iterable<Subject> getAll() {
return subjectRepository.findAll();
}
}
\ No newline at end of file
package com.RESTAPI.RESTAPI.Controllers;
import com.RESTAPI.RESTAPI.Entities.User;
import com.RESTAPI.RESTAPI.Repositories.CompteRepository;
import com.RESTAPI.RESTAPI.Repositories.AccountRepository;
import com.RESTAPI.RESTAPI.Repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
......@@ -9,18 +9,21 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
@Controller
@RequestMapping(path="/user")
public class UserController {
@Autowired
private UserRepository userRepository;
@Autowired
private CompteRepository compteRepository;
private AccountRepository accountRepository;
@PutMapping(path="/")
public @ResponseBody
User add(@RequestBody User user) {
compteRepository.save(user.getCompte());
user.getAccount().setCreationDate(LocalDate.now());
accountRepository.save(user.getAccount());
return userRepository.save(user);
}
......
package com.RESTAPI.RESTAPI.Controllers;
import com.RESTAPI.RESTAPI.Entities.Vote;
import com.RESTAPI.RESTAPI.Enums.ChoixVote;
import com.RESTAPI.RESTAPI.Enums.ChoiceEnum;
import com.RESTAPI.RESTAPI.Repositories.PropositionRepository;
import com.RESTAPI.RESTAPI.Repositories.VoteRepository;
import javassist.tools.web.BadHttpRequest;
......@@ -22,7 +22,7 @@ public class VoteController {
@PutMapping(path = "/")
public ResponseEntity<Vote> create(@RequestBody Vote vote) {
try {
handleChoice(vote.getChoix(), vote.getProposition().getId());
handleChoice(vote.getChoice(), vote.getProposition().getId());
} catch (BadHttpRequest e) {
return new ResponseEntity<>(new Vote(), HttpStatus.BAD_REQUEST);
}
......@@ -43,21 +43,21 @@ public class VoteController {
return voteRepository.findAll();
}
private void handleChoice(ChoixVote choice, int id) throws BadHttpRequest {
private void handleChoice(ChoiceEnum choice, int id) throws BadHttpRequest {
propositionRepository.findById(id)
.map(p -> {
switch (choice) {
case POUR:
p.setScorePour(p.getScorePour() + 1);
case FOR:
p.setScoreFor(p.getScoreFor() + 1);
break;
case MAISPOUR:
p.setScoreMais(p.getScoreMais() + 1);
case FOR_BUT:
p.setScoreYesBut(p.getScoreYesBut() + 1);
break;
case NEUTRE:
p.setScoreNeutre(p.getScoreNeutre() + 1);
case NEUTRAL:
p.setScoreNeutral(p.getScoreNeutral() + 1);
break;
case NON:
p.setScoreNon(p.getScoreNon() + 1);
case NO:
p.setScoreAgainst(p.getScoreAgainst() + 1);
break;
}
return propositionRepository.save(p);
......
......@@ -6,7 +6,7 @@ import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;
import java.time.LocalDate;
@Entity
@Getter
......@@ -14,12 +14,12 @@ import java.util.Date;
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Compte {
public class Account {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer id;
private String email;
private String mdp;
private Boolean status;
private Date dateCreation;
private String pwd;
private Boolean isActive;
private LocalDate creationDate;
}
......@@ -4,7 +4,7 @@ import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.util.Date;
import java.time.LocalDateTime;
@Entity
@Getter
......@@ -14,7 +14,9 @@ public class Consultation {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer id;
private Date dateConsultation;
private LocalDateTime reviewDate;
@ManyToOne
private Sujet sujet;
private Subject subject;
@ManyToOne
private User user;
}
......@@ -12,12 +12,12 @@ public class Proposition {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer id;
private String nom;
private String name;
@ManyToOne
private Sujet sujet;
private Subject subject;
private int scorePour;
private int scoreMais;
private int scoreNeutre;
private int scoreNon;
private int scoreFor;
private int scoreYesBut;
private int scoreNeutral;
private int scoreAgainst;
}
package com.RESTAPI.RESTAPI.Entities;
import com.RESTAPI.RESTAPI.Enums.StatusSujet;
import com.RESTAPI.RESTAPI.Enums.SubjectStatusEnum;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.*;
import java.util.Date;
import java.time.LocalDate;
@Entity
@Getter
@Setter
public class Sujet {
public class Subject {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer id;
private String nom;
private Date dateFinPhase;
private String name;
private LocalDate endDate;
@Enumerated(EnumType.STRING)
private StatusSujet status;
private SubjectStatusEnum status;
}
package com.RESTAPI.RESTAPI.Entities;
import com.RESTAPI.RESTAPI.Enums.TypeUtilisateur;
import com.RESTAPI.RESTAPI.Enums.GenderEnum;
import com.RESTAPI.RESTAPI.Enums.UserTypeEnum;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.time.LocalDate;
@Entity
@Getter
......@@ -18,25 +18,19 @@ public class User {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private Integer id;
private String nom;
private Boolean sexe;
private String name;
private String type;
private Date dateNaissance;
private Integer telephone;
private LocalDate birthDate;
@Column(length = 12)
private String phone;
@Enumerated(EnumType.STRING)
private TypeUtilisateur typeUtilisateur;
private UserTypeEnum userTypeEnum;
@Enumerated(EnumType.STRING)
private GenderEnum sex;
@OneToOne
private Compte compte;
@ManyToMany
private List<Consultation> consultations;
public User(String nom, Boolean sexe, String type, Date dateNaissance, Integer telephone, TypeUtilisateur typeUtilisateur, Compte compte) {
this.nom = nom;
this.sexe = sexe;
this.type = type;
this.dateNaissance = dateNaissance;
this.telephone = telephone;
this.typeUtilisateur = typeUtilisateur;
this.compte = compte;
}
private Account account;
}
\ No newline at end of file
package com.RESTAPI.RESTAPI.Entities;
import com.RESTAPI.RESTAPI.Enums.ChoixVote;
import com.RESTAPI.RESTAPI.Enums.ChoiceEnum;
import lombok.Getter;
import lombok.Setter;
......@@ -21,7 +21,7 @@ public class Vote {
Proposition proposition;
@Enumerated(EnumType.STRING)
ChoixVote choix;
ChoiceEnum choice;
String commentaire;
String comment;
}
package com.RESTAPI.RESTAPI.Enums;
public enum ChoixVote
{
POUR,
MAISPOUR,
NEUTRE,
NON
public enum ChoiceEnum {
FOR,
FOR_BUT,
NEUTRAL,
NO
}
package com.RESTAPI.RESTAPI.Enums;
public enum StatusSujet
{
EN_CREATION,
ACTIF,
CLOS
public enum GenderEnum {
MALE,
FEMALE,
NON_BINARY
}
package com.RESTAPI.RESTAPI.Enums;
public enum SubjectStatusEnum {
PENDING,
ACTIVE,
CLOSED
}
package com.RESTAPI.RESTAPI.Enums;
public enum TypeUtilisateur
{
UTILISATEUR,
PARTICIPANT
public enum UserTypeEnum {
MODERATOR,
USER
}
package com.RESTAPI.RESTAPI.Repositories;
import com.RESTAPI.RESTAPI.Entities.Sujet;
import com.RESTAPI.RESTAPI.Entities.Account;
import org.springframework.data.repository.CrudRepository;
public interface SujetRepository extends CrudRepository<Sujet, Integer> {
public interface AccountRepository extends CrudRepository<Account, Integer> {
}
package com.RESTAPI.RESTAPI.Repositories;
import com.RESTAPI.RESTAPI.Entities.Compte;
import com.RESTAPI.RESTAPI.Entities.Subject;
import org.springframework.data.repository.CrudRepository;
public interface CompteRepository extends CrudRepository<Compte, Integer> {
public interface SubjectRepository extends CrudRepository<Subject, Integer> {
}
......@@ -3,8 +3,8 @@ package com.RESTAPI.RESTAPI.Requests;
import lombok.Getter;
@Getter
public class CompteRequest {
public class AccountRequest {
private String email;
private String mdp;
private Boolean status;
private String pwd;
private Boolean isActive;
}
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