Skip to content
Snippets Groups Projects

Code of conduct

Files

@@ -17,15 +17,22 @@
@@ -17,15 +17,22 @@
*/
*/
package nl.tudelft.queue.controller;
package nl.tudelft.queue.controller;
 
import java.time.LocalDateTime;
 
 
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.*;
 
import com.fasterxml.jackson.core.JsonProcessingException;
 
import lombok.AllArgsConstructor;
import lombok.AllArgsConstructor;
import nl.tudelft.labracore.lib.security.user.AuthenticatedPerson;
import nl.tudelft.labracore.lib.security.user.AuthenticatedPerson;
import nl.tudelft.labracore.lib.security.user.Person;
import nl.tudelft.labracore.lib.security.user.Person;
import nl.tudelft.queue.dto.patch.ProfilePatchDTO;
import nl.tudelft.queue.dto.patch.ProfilePatchDTO;
 
import nl.tudelft.queue.dto.view.CodeOfConductDTO;
import nl.tudelft.queue.repository.ProfileRepository;
import nl.tudelft.queue.repository.ProfileRepository;
 
import nl.tudelft.queue.service.CodeOfConductService;
@AllArgsConstructor
@AllArgsConstructor
@RequestMapping("profile")
@RequestMapping("profile")
@@ -34,6 +41,8 @@ public class ProfileController {
@@ -34,6 +41,8 @@ public class ProfileController {
private ProfileRepository profileRepository;
private ProfileRepository profileRepository;
 
private CodeOfConductService codeOfConductService;
 
/**
/**
* Updates the user's profile.
* Updates the user's profile.
*
*
@@ -49,4 +58,33 @@ public class ProfileController {
@@ -49,4 +58,33 @@ public class ProfileController {
return ResponseEntity.ok().build();
return ResponseEntity.ok().build();
}
}
 
/**
 
* Get the code of conduct information for the specific person. This allows the front-end to check the
 
* last time the code of conduct was read and display it if needed.
 
*
 
* @param person The person fow whom to get the Code of Conduct information.
 
* @return
 
* @throws JsonProcessingException
 
*/
 
@GetMapping(value = "code-of-conduct", produces = MediaType.APPLICATION_JSON_VALUE)
 
@ResponseBody
 
public ResponseEntity<String> doesUserNeedToReadCoc(@AuthenticatedPerson Person person)
 
throws JsonProcessingException {
 
CodeOfConductDTO dto = codeOfConductService.getCodeOfConduct(person);
 
return ResponseEntity.ok(dto.toJsonValue());
 
}
 
 
/**
 
* Update the latest read variable for a person regarding their code of conduct to the current date/time.
 
* This allows for keeping track on when the user last read the code of conduct.
 
*
 
* @param person The person for which to update
 
* @return
 
*/
 
@PostMapping(value = "code-of-conduct/update")
 
@ResponseBody
 
public ResponseEntity<Void> updateLatestReadCoC(@AuthenticatedPerson Person person) {
 
codeOfConductService.updateLatestCoC(person, LocalDateTime.now());
 
return ResponseEntity.ok().build();
 
}
}
}
Loading