Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correction crenaux etablissement #17

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
import javax.validation.Valid;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Iterator;
import java.util.List;

@RestController
@RequestMapping("/etablissements")
@RequestMapping("/etablissements/{idEtab}")
@CrossOrigin(origins = {"*"}, maxAge = 4800, allowCredentials = "false")

public class CreneauController {
Expand All @@ -27,22 +28,29 @@ public class CreneauController {
CreneauService creneauService;

// Get All creneau for selected week
@GetMapping("/{id}/creneaux")
@GetMapping("/creneaux")
public List<Creneau> getWeekCreneaux(
@PathVariable(value = "id") Long etablissementId,
@PathVariable(value = "idEtab") Long etablissementId,
@RequestParam(value="year", required=true) int year,
@RequestParam(value="week", required=true) int week
) {
long[] weekBeginEndTimestamps = getWeekTimestampsFromYearAndId(year, week);

List<Creneau> creneaux = creneauRepository.findByDateDebutAndDateFin(weekBeginEndTimestamps[0], weekBeginEndTimestamps[1]);

for (Iterator<Creneau> iterator = creneaux.iterator(); iterator.hasNext();) {
Creneau creneau = iterator.next();
if (creneau.getSalle().getEtablissement().getIdEtablissement() != etablissementId){
iterator.remove();
}
}

return creneaux;
}



@GetMapping("/{idEtab}/creneaux/{idCreneau}")
@GetMapping("/creneaux/{idCreneau}")
public Creneau getCreneauxById(
@PathVariable(value = "idEtab") Long etablissementId,
@PathVariable(value = "idCreneau") Long creneauId
Expand All @@ -56,23 +64,23 @@ public Creneau getCreneauxById(



@PostMapping("/{idEtab}/creneaux")
@PostMapping("/creneaux")
public long createCreneau(@Valid @RequestBody Creneau creneau){
creneauRepository.save(creneau);

return creneau.getIdCreneau();
}


@PostMapping("/{idEtab}/creneaux/duplication")
@PostMapping("/creneaux/duplication")
public void duplicateCreneau(@Valid @RequestBody Long[][] timestamps){
Long[] semainesADupliquer = timestamps[0];
Long[] semainesReceptrices = timestamps[1];

creneauService.duplicationSemaines(semainesADupliquer, semainesReceptrices);
}

@DeleteMapping("/{idEtab}/creneaux/{idCreneau}")
@DeleteMapping("/creneaux/{idCreneau}")
public ResponseEntity<?> deleteCreneaux(
@PathVariable(value = "idEtab") Long etablissementId,
@PathVariable(value = "idCreneau") Long creneauId){
Expand All @@ -84,7 +92,7 @@ public ResponseEntity<?> deleteCreneaux(
}


@PutMapping("/{idEtab}/creneaux/{idCreneau}")
@PutMapping("/creneaux/{idCreneau}")
public long updateCreneau(@Valid @RequestBody Creneau creneau){
creneauRepository.save(creneau);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ public Message getById(@PathVariable(value = "id") long idMessage) {

// get tous les messages d'un eleve
@GetMapping("/eleves/{id}")
public List<Message> getAll(@PathVariable(value = "id") long idEleve) {
public List<Message> getAllByEleve(@PathVariable(value = "id") long idEleve) {
return messageService.BuildAllMessagesForEleve(idEleve);
}

@PostMapping("")
public String createMessage(@Valid @RequestBody Message message){

System.out.println("stop");
return messageService.save(message);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ public interface MessageRepository extends JpaRepository<Message, Long> {

List<Message> findAllByEleve_IdUtilisateur(long idEleve);
void deleteByIdMessage(long idMessage);
}
}