Compare commits

..

18 Commits

Author SHA1 Message Date
4199663d64 Huge commit
- Rework the inscription requests system so that it considers the equivalence systems and the impact of the teacher in the inscription procedure.
2024-04-11 16:45:48 +02:00
34c0a2bfe8 Merge remote-tracking branch 'origin/master' into Leo/InscriptionDesEtudiants
# Conflicts:
#	frontend/src/rest/apps.js
2024-04-10 23:28:00 +02:00
76c3b76153 Merge pull request 'Messaging system' (#150) from tonitch/Clyde:msg into master
All checks were successful
Build and test backend / Build-backend (push) Successful in 3m45s
deploy to production / deploy-frontend (push) Successful in 26s
deploy to production / deploy-backend (push) Successful in 1m35s
Build and test FrontEnd / Build-frontend (push) Successful in 24s
Reviewed-on: #150
2024-04-09 17:08:57 +02:00
5bb7606721
signing and commenting
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 2m21s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 25s
2024-04-05 12:54:51 +02:00
b049c46571
Avoid title reseting mid modification
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 3m1s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 27s
2024-04-05 11:45:47 +02:00
7ca5c34afe
adding timestamp
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 2m9s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 25s
2024-04-02 11:08:58 +02:00
2b9bdf8dac
fixup! show sender on message
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 2m8s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 24s
2024-04-02 10:18:50 +02:00
ccb954e348
show sender on message
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 2m9s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 24s
2024-04-02 10:05:17 +02:00
ce56e37a33
redesign send bar
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 2m54s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 27s
2024-03-29 14:31:22 +01:00
1c61a356a4
update when message sent 2024-03-29 14:31:08 +01:00
2bdffe6ab4
remove member of a discussion 2024-03-29 14:30:46 +01:00
729d1ad504
adding members management
All checks were successful
Build and test backend / Build-backend (pull_request) Successful in 3m35s
Build and test FrontEnd / Build-frontend (pull_request) Successful in 26s
2024-03-27 23:54:59 +01:00
1522d74ed3
messsaging on the frontend 2024-03-27 19:52:48 +01:00
b4499e04c7
Managing the message with backend
Using DTO to change the way discussions and message are sent to the
client
2024-03-27 19:50:52 +01:00
914f6bdf36
fix for new discussions not appearing right away 2024-03-25 09:43:45 +01:00
66e7fa24a1
Adding the discussion architectures and creating new discussions 2024-03-25 00:08:44 +01:00
7b9f021c24
first version of the frontend for messages 2024-03-24 22:33:17 +01:00
2dfa0a0ee0
base msg 2024-03-24 22:33:14 +01:00
31 changed files with 968 additions and 192 deletions

View File

@ -16,6 +16,8 @@ repositories {
}
dependencies {
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
implementation("org.springframework.boot:spring-boot-starter-jdbc")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-mail")

View File

@ -0,0 +1,34 @@
package ovh.herisson.Clyde.DTO.Msg;
/******************************************************
* @file DiscussionDTO.java
* @author Anthony Debucquoy
* @scope Extension messagerie
*
* File to format a discussion using messageDTO
******************************************************/
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AllArgsConstructor;
import lombok.Data;
import ovh.herisson.Clyde.Tables.User;
import ovh.herisson.Clyde.Tables.Msg.Discussion;
import ovh.herisson.Clyde.DTO.Msg.MessagesDTO;
@Data
@AllArgsConstructor
public class DiscussionDTO {
private long id;
private String name;
private List<User> members;
private List<MessagesDTO> msgs;
public static DiscussionDTO construct(Discussion d, User u){
List<MessagesDTO> msgsdto = new ArrayList<>();
d.getMsgs().forEach(x -> msgsdto.add(MessagesDTO.construct(x, u)));
return new DiscussionDTO(d.getId(), d.getName(), d.getMembers(), msgsdto);
}
}

View File

@ -0,0 +1,33 @@
package ovh.herisson.Clyde.DTO.Msg;
/******************************************************
* @file MessagesDTO.java
* @author Anthony Debucquoy
* @scope Extension messagerie
*
* File to Format the response adding the sender field
******************************************************/
import lombok.AllArgsConstructor;
import lombok.Data;
import ovh.herisson.Clyde.Tables.User;
import ovh.herisson.Clyde.Tables.Msg.Message;
import java.util.Date;
@Data
@AllArgsConstructor
public class MessagesDTO {
private long id;
private String content;
private User author;
private boolean sender;
private Date created;
//TODO: Attachment
public static MessagesDTO construct(Message m, User user){
boolean sender = false;
if(m.getAuthor().equals(user))
sender = true;
return new MessagesDTO(m.getId(), m.getContent(), m.getAuthor(), sender, m.getCreated());
}
}

View File

@ -41,4 +41,12 @@ public class ExternalCurriculumController {
ArrayList<ExternalCurriculum> toReturn = ecr.getExternalCurriculumByInscriptionRequest(ir);
return new ResponseEntity<>(toReturn, HttpStatus.OK);
}
@PatchMapping("/externalcurriculum/{extcurrid}/{newstate}")
public ResponseEntity<Object> changeExternalCurrState(@PathVariable long extcurrid, @PathVariable RequestState newstate){
ExternalCurriculum externalCurriculum = ecr.getExternalCurriculumById(extcurrid);
externalCurriculum.setState(newstate);
ecr.save(externalCurriculum);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@ -1,5 +1,6 @@
package ovh.herisson.Clyde.EndPoints;
import org.apache.tomcat.util.http.parser.Authorization;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@ -79,4 +80,22 @@ public class InscriptionController {
return new ResponseEntity<>(HttpStatus.OK);
}
//Allow teacher or admin to accept or refuse the equivalence
@PatchMapping("/request/registerequiv/{id}/{newstate}")
public ResponseEntity<Object> editRegisterEquiv(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newstate){
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher}, token))
return new UnauthorizedResponse<>(null);
InscriptionRequest toEdit = inscriptionServ.getById(id);
toEdit.setEquivalenceState(newstate);
inscriptionServ.save(toEdit);
if (toEdit.getState() == RequestState.Accepted && (toEdit.getEquivalenceState() == RequestState.Accepted || toEdit.getEquivalenceState() == RequestState.Unrequired))
{
inscriptionServ.createUser(toEdit);
}
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@ -5,10 +5,15 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ovh.herisson.Clyde.Repositories.CurriculumRepository;
import ovh.herisson.Clyde.Repositories.InscriptionRepository;
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
import ovh.herisson.Clyde.Services.AuthenticatorService;
import ovh.herisson.Clyde.Services.ProtectionService;
import ovh.herisson.Clyde.Tables.Curriculum;
import ovh.herisson.Clyde.Tables.InscriptionRequest;
import ovh.herisson.Clyde.Tables.RequestState;
import java.util.Date;
import java.util.Map;
@ -16,7 +21,7 @@ import java.util.Map;
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
public class LoginController {
private final AuthenticatorService authServ;
private final CurriculumRepository curriculumRepository;
static public class RequestLogin{
private final String identifier;
private final String password;
@ -29,8 +34,9 @@ public class LoginController {
}
}
public LoginController(AuthenticatorService authServ){
public LoginController(AuthenticatorService authServ, CurriculumRepository curriculumRepository){
this.authServ = authServ;
this.curriculumRepository = curriculumRepository;
}
@PostMapping(value = "/login")
@ -48,9 +54,18 @@ public class LoginController {
@PostMapping("/register")
public ResponseEntity<Map<String,Object>> register(@RequestBody InscriptionRequest inscriptionRequest){
//We ensure here that if the targeted cursus year is more than first grade then we need the teacher equivalence approval
Curriculum curr = curriculumRepository.findById(inscriptionRequest.getCurriculumId());
if (curr.getYear() > 1){
inscriptionRequest.setEquivalenceState(RequestState.Pending);
}else{
inscriptionRequest.setEquivalenceState(RequestState.Unrequired);
}
InscriptionRequest returnedInscriptionRequest = authServ.register(inscriptionRequest);
return new ResponseEntity<>(ProtectionService.requestWithoutPassword(returnedInscriptionRequest), HttpStatus.CREATED);
}
}

View File

@ -21,7 +21,7 @@ public class MockController {
public final CurriculumCourseService CurriculumCourseService;
public final CurriculumService curriculumService;
public final CourseService courseService;
public final ExternalCurriculumRepository externalCurriculumRepository;
public final InscriptionService inscriptionService;
ArrayList<User> mockUsers;
@ -31,13 +31,14 @@ public class MockController {
public final ScholarshipRequestRepository scholarshipRequestRepository;
public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository, ScholarshipRequestRepository scholarshipRequestRepository){
public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, ExternalCurriculumRepository externalCurriculumRepository, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository, ScholarshipRequestRepository scholarshipRequestRepository){
this.tokenRepo = tokenRepo;
this.userRepo = userRepo;
this.tokenService = tokenService;
this.CurriculumCourseService = CurriculumCourseService;
this.curriculumService = curriculumService;
this.courseService = courseService;
this.externalCurriculumRepository = externalCurriculumRepository;
this.inscriptionService = inscriptionService;
this.ucr = ucr;
this.minervalRepository = minervalRepository;
@ -114,9 +115,12 @@ public class MockController {
CurriculumCourseService.save(new CurriculumCourse(chemistryBab1,chemistry1));
InscriptionRequest inscriptionRequest = new InscriptionRequest("helen","prenom","non","helen@gmail.com","america",new Date(),(long) 1,RequestState.Pending,"yes.png","password", null, new Date());
InscriptionRequest inscriptionRequest = new InscriptionRequest("helen","prenom","non","helen@gmail.com","america",new Date(),(long) 4,RequestState.Pending,"yes.png","password", null, new Date(), RequestState.Pending);
inscriptionService.save(inscriptionRequest);
ExternalCurriculum externalCurriculum = new ExternalCurriculum(inscriptionRequest, "HEH", "Bachelier en informatique", "Completed", 2015, 2018, null, RequestState.Pending);
externalCurriculumRepository.save(externalCurriculum);
}
}

View File

@ -0,0 +1,126 @@
package ovh.herisson.Clyde.EndPoints.Msg;
/******************************************************
* @file MessagesController.java
* @author Anthony Debucquoy
* @scope Extension messagerie
*
* Entry point for the messages application
******************************************************/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
import lombok.AllArgsConstructor;
import ovh.herisson.Clyde.DTO.Msg.DiscussionDTO;
import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Repositories.Msg.DiscussionRepository;
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
import ovh.herisson.Clyde.Services.AuthenticatorService;
import ovh.herisson.Clyde.Services.UserService;
import ovh.herisson.Clyde.Services.Msg.DiscussionService;
import ovh.herisson.Clyde.Tables.User;
import ovh.herisson.Clyde.Tables.Msg.Discussion;
import ovh.herisson.Clyde.Tables.Msg.Message;
@RestController
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
@AllArgsConstructor
public class MessagesController {
private AuthenticatorService authServ;
private DiscussionService discServ;
private DiscussionRepository discRepo;
private UserService userServ;
@GetMapping("/discussions")
public ResponseEntity<Iterable<Discussion>> getDiscussions(@RequestHeader("Authorization") String token ){
User user = authServ.getUserFromToken(token);
if(user == null){
return new UnauthorizedResponse<>(null);
}
Iterable<Discussion> mock = discServ.getOwned(authServ.getUserFromToken(token));
return new ResponseEntity<>(mock, HttpStatus.OK);
}
@GetMapping("/discussion/{id}")
public ResponseEntity<DiscussionDTO> getDiscussion(@RequestHeader("Authorization") String token, @PathVariable long id){
User user = authServ.getUserFromToken(token);
if(user == null || !discServ.hasDiscussion(user, id) ){
return new UnauthorizedResponse<>(null);
}
return new ResponseEntity<>(DiscussionDTO.construct(discRepo.findById(id).orElse(null), authServ.getUserFromToken(token)), HttpStatus.OK);
}
@PatchMapping("/discussion/{id}")
public ResponseEntity<Discussion> AlterDiscussion(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Discussion data){
User user = authServ.getUserFromToken(token);
if(user == null){
return new UnauthorizedResponse<>(null);
}
Discussion disc = discRepo.findById(id).orElse(null);
disc.setName(data.getName());
discRepo.save(disc);
return new ResponseEntity<>(disc, HttpStatus.OK);
}
@PatchMapping("/discussion/{id}/add")
public ResponseEntity<Discussion> invite(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody User data){
User user = authServ.getUserFromToken(token);
if(user == null){
return new UnauthorizedResponse<>(null);
}
Discussion disc = discRepo.findById(id).orElse(null);
User invited = userServ.getUserById(data.getRegNo());
disc.addMember(invited);
discRepo.save(disc);
return new ResponseEntity<>(disc, HttpStatus.OK);
}
@PatchMapping("/discussion/{id}/remove")
public ResponseEntity<Discussion> removeMember(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody User data){
User user = authServ.getUserFromToken(token);
if(user == null){
return new UnauthorizedResponse<>(null);
}
Discussion disc = discRepo.findById(id).orElse(null);
User member = userServ.getUserById(data.getRegNo());
disc.delMember(member);
discRepo.save(disc);
return new ResponseEntity<>(disc, HttpStatus.OK);
}
@PostMapping("/discussion/{id}")
public ResponseEntity<Discussion> sendMessage(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Message msg){
User user = authServ.getUserFromToken(token);
if(user == null){
return new UnauthorizedResponse<>(null);
}
Discussion disc = discRepo.findById(id).orElse(null);
msg.setAuthor(user);
if(disc != null)
discServ.CreateMessage(disc, msg);
return new ResponseEntity<>(disc, HttpStatus.OK);
}
@PostMapping("/discussion")
public ResponseEntity<Discussion> createDiscussion(@RequestHeader("Authorization") String token, @RequestBody Discussion data){
return new ResponseEntity<>(discServ.create(data.getName(), authServ.getUserFromToken(token)), HttpStatus.OK);
}
}

View File

@ -9,4 +9,6 @@ import java.util.ArrayList;
public interface ExternalCurriculumRepository extends CrudRepository<ExternalCurriculum, Long> {
ArrayList<ExternalCurriculum> getExternalCurriculumByInscriptionRequest(InscriptionRequest ir);
ExternalCurriculum getExternalCurriculumById(long id);
}

View File

@ -0,0 +1,23 @@
package ovh.herisson.Clyde.Repositories.Msg;
/******************************************************
* @file DiscussionRepository.java
* @author Anthony Debucquoy
* @scope Extension messagerie
*
* Repository of Discussion allowing to fetch discussion by user
******************************************************/
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import ovh.herisson.Clyde.Tables.Msg.Discussion;
public interface DiscussionRepository extends CrudRepository<Discussion, Long>{
@Query("SELECT d FROM Discussion d INNER JOIN FETCH d.members dm WHERE dm.id = ?1")
List<Discussion> findByMembership(long userid);
}

View File

@ -0,0 +1,14 @@
package ovh.herisson.Clyde.Repositories.Msg;
/******************************************************
* @file MessageRepository.java
* @author Anthony Debucquoy
* @scope Extension messagerie
******************************************************/
import org.springframework.data.repository.CrudRepository;
import ovh.herisson.Clyde.Tables.Msg.Message;
public interface MessageRepository extends CrudRepository<Message, Long> {}

View File

@ -47,48 +47,43 @@ public class InscriptionService {
if (inscrRequest == null)
return false;
// if th state is the same we don't send an email
if (requestState == inscrRequest.getState())
return false;
/** todo send an email to tell the poster of the inscrRequest (inscrRequest.getEmail())
* to notify them that the state of their request changed
* FooEmailFormat toSend = (String.format("Your request state changed from %s to %s"),
* inscrRequest.getState(), requestState)
* FooEmailSender.send(toSend, inscrRequest.getEmail())
*/
//saves the user from the request if accepted
if (requestState == RequestState.Accepted)
{
if (curriculumRepo.findById(inscrRequest.getCurriculumId()) == null)
return false;
User userFromRequest = new User(
inscrRequest.getLastName(),
inscrRequest.getFirstName(),
inscrRequest.getEmail(),
inscrRequest.getAddress(),
inscrRequest.getCountry(),
inscrRequest.getBirthDate(),
inscrRequest.getProfilePicture(),
inscrRequest.getPassword()
);
userRepo.save(userFromRequest);
userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),0));
//Create a minerval for the new student
Minerval minerval = new Minerval(userFromRequest.getRegNo(), 0, 852, 2023);
minervalRepository.save(minerval);
}
inscrRequest.setState(requestState);
save(inscrRequest);
//saves the user from the request if accepted from teacher and inscription services
if (requestState == RequestState.Accepted && (inscrRequest.getEquivalenceState() == RequestState.Accepted || inscrRequest.getEquivalenceState() == RequestState.Unrequired))
{
return createUser(inscrRequest);
}
return true;
}
public boolean createUser(InscriptionRequest inscrRequest){
//We must send an email here
if (curriculumRepo.findById(inscrRequest.getCurriculumId()) == null)
return false;
User userFromRequest = new User(
inscrRequest.getLastName(),
inscrRequest.getFirstName(),
inscrRequest.getEmail(),
inscrRequest.getAddress(),
inscrRequest.getCountry(),
inscrRequest.getBirthDate(),
inscrRequest.getProfilePicture(),
inscrRequest.getPassword()
);
userRepo.save(userFromRequest);
userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),0));
//Create a minerval for the new student
Minerval minerval = new Minerval(userFromRequest.getRegNo(), 0, 852, 2023);
minervalRepository.save(minerval);
return true;
}
public void delete(InscriptionRequest toDelete) {
inscriptionRepo.delete(toDelete);
}

View File

@ -0,0 +1,57 @@
package ovh.herisson.Clyde.Services.Msg;
import java.util.List;
/******************************************************
* @file DiscussionService.java
* @author Anthony Debucquoy
* @scope Extension messagerie
*
* Various function utilised by the messages application
******************************************************/
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.databind.util.JSONPObject;
import ovh.herisson.Clyde.Repositories.Msg.DiscussionRepository;
import ovh.herisson.Clyde.Tables.User;
import ovh.herisson.Clyde.Tables.Msg.Discussion;
import ovh.herisson.Clyde.Tables.Msg.Message;
@Service
public class DiscussionService {
@Autowired
private DiscussionRepository discRepo;
public Discussion create(String name, User author){
return discRepo.save(new Discussion(name, author));
}
/**
* list discussions owned by a certain user
*/
public Iterable<Discussion> getOwned(User author){
return discRepo.findByMembership(author.getRegNo());
}
/**
* Create a message and link it to it's discussion
*/
public Discussion CreateMessage(Discussion disc, Message msg){
disc.addMessage(msg);
return discRepo.save(disc);
}
/**
* Check if a user is in a discussion
*/
public boolean hasDiscussion(User user, long id) {
Discussion disc = discRepo.findById(id).orElse(null);
List<User> members = disc.getMembers();
return members.contains(user);
}
}

View File

@ -89,6 +89,7 @@ public class ProtectionService {
toReturn.put("profilePictureUrl", inscriptionRequest.getProfilePicture());
toReturn.put("identityCard", inscriptionRequest.getIdentityCard());
toReturn.put("submissionDate", inscriptionRequest.getSubmissionDate());
toReturn.put("equivalenceState", inscriptionRequest.getEquivalenceState());
return toReturn;
}

View File

@ -21,9 +21,10 @@ public class InscriptionRequest {
private String password;
private String identityCard;
private Date submissionDate;
private RequestState equivalenceState;
public InscriptionRequest(){}
public InscriptionRequest(String lastName, String firstName, String address, String email, String country, Date birthDate,Long curriculumId, RequestState state, String profilePicture, String password, String identityCard, Date submissionDate){
public InscriptionRequest(String lastName, String firstName, String address, String email, String country, Date birthDate,Long curriculumId, RequestState state, String profilePicture, String password, String identityCard, Date submissionDate, RequestState equivalenceState){
this.lastName = lastName;
this.firstName = firstName;
this.address = address;
@ -36,6 +37,7 @@ public class InscriptionRequest {
this.password = password;
this.identityCard = identityCard;
this.submissionDate = submissionDate;
this.equivalenceState = equivalenceState;
}
public int getId() {
@ -137,4 +139,12 @@ public class InscriptionRequest {
public void setSubmissionDate(Date submissionDate) {
this.submissionDate = submissionDate;
}
public RequestState getEquivalenceState() {
return equivalenceState;
}
public void setEquivalenceState(RequestState equivalenceState) {
this.equivalenceState = equivalenceState;
}
}

View File

@ -0,0 +1,72 @@
package ovh.herisson.Clyde.Tables.Msg;
/******************************************************
* @file Discussion.java
* @author Anthony Debucquoy
* @scope Extension messagerie
*
* Discussion allow to regroupe multiple user in and message together
* for the messages application to work
******************************************************/
import java.util.List;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.OneToMany;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import ovh.herisson.Clyde.Tables.User;
@Entity
@Getter
@Setter
@NoArgsConstructor
public class Discussion{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String name;
@ManyToMany
@JoinTable(
name = "discussion_members",
joinColumns = @JoinColumn(name = "discussion_id"),
inverseJoinColumns = @JoinColumn(name = "user_id")
)
private List<User> members;
@OneToMany(mappedBy="discussion", orphanRemoval = true, cascade = CascadeType.ALL)
private List<Message> msgs;
public Discussion(String name){
this.name = name;
}
public Discussion(String name, User user){
this.name = name;
this.members = List.of(user);
}
public void addMessage(Message msg){
msg.setDiscussion(this);
msgs.add(msg);
}
public void addMember(User user) {
members.add(user);
}
public void delMember(User user) {
members.remove(user);
}
}

View File

@ -0,0 +1,66 @@
package ovh.herisson.Clyde.Tables.Msg;
/******************************************************
* @file Message.java
* @author Anthony Debucquoy
* @scope Extension messagerie
*
* Represent a message sent to a discussion
******************************************************/
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Date;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.PrePersist;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import ovh.herisson.Clyde.Tables.User;
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
public class Message {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
private String content;
@CreationTimestamp
@Column(nullable = false)
private Date created;
@ManyToOne
private User author;
public User getAuthor() {
return author;
}
@OneToOne
private Message response;
@ManyToOne(optional = false)
@JsonIgnore
private Discussion discussion;
}

View File

@ -3,5 +3,6 @@ package ovh.herisson.Clyde.Tables;
public enum RequestState {
Accepted,
Refused,
Pending
Pending,
Unrequired
}

View File

@ -1,27 +0,0 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*;
@Entity
public class University {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String name;
public University(){}
public University(String name){
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -1,7 +1,11 @@
package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*;
import ovh.herisson.Clyde.Tables.Msg.Discussion;
import ovh.herisson.Clyde.Tables.Msg.Message;
import java.util.Date;
import java.util.List;
@Entity
@ -20,6 +24,15 @@ public class User {
private String profilePictureUrl;
private ovh.herisson.Clyde.Tables.Role role;
private String password;
////// Extension Messagerie /////
@OneToMany(mappedBy = "author", cascade = CascadeType.ALL)
private List<Message> msgs;
/////////////////////////////////
@ManyToMany( mappedBy = "members" )
private List<Discussion> discussions;
public User(String lastName, String firstName, String email, String address,
String country, Date birthDate, String profilePictureUrl, Role role, String password)
{

View File

@ -1,27 +1,35 @@
<script setup>
import i18n from "@/i18n.js"
import {getUser} from '../rest/Users.js'
import {getSelf, getUser} from '../rest/Users.js'
import {getcurriculum,getSomeonesCurriculumList} from "@/rest/curriculum.js";
import {getRegisters} from "@/rest/ServiceInscription.js";
import {get} from "jsdom/lib/jsdom/named-properties-tracker.js";
import {getExternalCurriculumByInscrReq} from "@/rest/externalCurriculum.js";
import {ref} from "vue";
import ExternalCurriculumList from "@/Apps/ExternalCurriculumList.vue";
import {editEquivalenceState} from "@/rest/requests.js";
const props = defineProps(['target']);
let request = await getRegisters(props.target);
const request = await getRegisters(props.target);
const cursus = await getcurriculum(request.curriculum);
const user = await getSelf();
const list = ref(false);
const externalCurriculum = await getExternalCurriculumByInscrReq(request.id)
console.log(externalCurriculum)
function getPP(){
if(request.profilePictureUrl === null){
return "/Clyde.png"
}
return request.profilePictureUrl;
}
async function editEquivalence(id, newstate){
await editEquivalenceState(id, newstate)
}
</script>
<template>
<div class="body">
<div class="body" v-if="list == false">
<div class="container">
<div class="profilPic">
<img class="subContainter" :src=getPP()>
@ -46,24 +54,20 @@ function getPP(){
<div>
Cursus voulu : BAB {{cursus.year}} {{cursus.option}}
</div>
</div>
</div>
<div class="moreInfos">
<div class = "oldcursus">
<div class="listTitle">
Cursus extérieurs a l'univesité
</div>
<div class="listElement">
<div class=" containerElement" v-for="item in externalCurriculum">
<div class="formation">item.formation</div>
<div class="school">item.school</div>
</div>
<div v-if="cursus.year > 1">
<button style="background-color:rgb(105,05,105);margin-left: 5%" @click="list=!list" v-if="(user.role == 'Teacher' || user.role == 'Admin')&& request.equivalenceState == 'Pending'">See external curriculums</button>
</div>
</div>
</div>
</div>
</div>
<div v-if="list==true">
<ExternalCurriculumList :ext-curr-list="externalCurriculum" :inscr-req-id="request.id"></ExternalCurriculumList>
<div>
<button @click="editEquivalence(request.id, 'Accepted'); request.equivalenceState='Accepted'">Accept Equivalence</button>
<button @click="editEquivalence(request.id, 'Refused'); request.equivalenceState='Refused'">Refuse Equivalence</button>
</div>
</div>
</template>
@ -117,50 +121,6 @@ function getPP(){
border-radius:20px;
}
.moreInfos {
display:grid;
grid-template-rows:200px auto;
column-gap:50px;
row-gap:45px;
grid-template-areas:
"minfos minfos";
grid-template-columns:600px 600px;
}
.listTitle{
display: flex;
justify-content: center;
align-items: center;
width:250px;
margin-left:auto;
margin-right:auto;
border:2px solid black;
font-size:25px;
color:white;
padding:20px;
background-color:rgb(50,50,50);
border-radius:20px;margin-bottom:10px;
}
.listElement{
border:2px solid black;
font-size:25px;
color:white;
padding:20px;
background-color:rgb(50,50,50);
border-radius:20px;
margin-bottom:10px;
}
.containerElement{
justify-content:center;
display:grid;
grid-template-columns:100px 100px 300px;
grid-template-areas:
"year option dateyear";
column-gap:40px;
padding-left: 25px;
}
button{
font-size:15px;
height:50px;
@ -169,42 +129,4 @@ button{
border-radius:20px;
}
.moreInfos {
display:grid;
grid-template-rows:200px auto;
column-gap:50px;
row-gap:45px;
grid-template-areas:
"minfos minfos";
grid-template-columns:600px 600px;
align-items:center;
justify-content:center;
margin-left: 320%;
}
.listTitle{
display: flex;
justify-content: center;
align-items: center;
width:250px;
margin-left:auto;
margin-right:auto;
border:2px solid black;
font-size:25px;
color:white;
padding:20px;
background-color:rgb(50,50,50);
border-radius:20px;margin-bottom:10px;
}
.listElement{
border:2px solid black;
font-size:25px;
color:white;
padding:20px;
background-color:rgb(50,50,50);
border-radius:20px;
margin-bottom:10px;
}
</style>

View File

@ -0,0 +1,103 @@
<script setup>
import i18n from "@/i18n.js";
import {editExternalCurriculum} from "@/rest/externalCurriculum.js";
import {ref} from "vue";
import {editEquivalenceState} from "@/rest/requests.js";
const props = defineProps(["extCurrList","inscrReqId"])
const extCurrList = ref(props.extCurrList)
</script>
<template style="margin-top:5%;">
<div style="display:flex; justify-content:center; " v-for="item in extCurrList">
<div class="bodu">
<div class="container">
<div class="status"><a style="margin-left:30px">{{item.state}}</a></div>
<div class="school"><a>{{item.school}}</a></div>
<div class="formation"><a>{{item.formation}}</a></div>
<div class="completion"><a>{{item.completion}}</a></div>
<div class="download"><button>Download document</button></div>
</div>
</div>
</div>
</template>
<style scoped>
.container{
color:white;
height:100px;
font-size:30px;
display:grid;
grid-template-columns:15% 10% 20% 15% 13.1%;
grid-template-areas:
"status school formation completion download";
column-gap:10px;
}
.status {
grid-area:status;
align-self:center;
font-size: 70%;
}
.school{
grid-area:school;
align-self:center;
font-size: 70%;
}
.formation{
grid-area:formation;
align-self:center;
font-size: 70%;
}
.completion{
grid-area:completion;
align-self:center;
white-space: nowrap;
overflow: hidden;
text-overflow:ellipsis;
font-size: 70%;
}
.accept{
grid-area:accept;
align-self:center;
white-space: nowrap;
overflow: hidden;
text-overflow:ellipsis;
}
.refuse{
grid-area: refuse;
align-self:center;
}
.download{
grid-area: download;
align-self:center;
}
button{
font-size:15px;
height:50px;
width:75%;
border:none;
border-radius:20px;
}
.bodu {
margin-top:2%;
width:66%;
border:2px solid black;
border-radius:9px;
background-color:rgb(50,50,50);
}
</style>

View File

@ -16,9 +16,7 @@
async function upPage(id,review){
await validateRegister(id,review);
if (review == "Accepted"){
}
requests.value = await getAllRegisters();
}
@ -40,7 +38,7 @@
<template>
<div v-if="windowsState === 1">
<AboutRequest :target="targetId"></AboutRequest>
<button style="background-color:rgb(105,05,105);margin-left: 30%" @click="windowsState=0;">Retour</button>
<button style="background-color:rgb(105,05,105);margin-left: 30%; margin-top: 5%" @click="windowsState=0;loadRequests()">Retour</button>
</div>
<div v-if="windowsState === 0">
<div style="margin-top: 2%;margin-left: 2%">
@ -61,15 +59,16 @@
</span>
</div>
<div style='display:flex; justify-content:center; min-width:1140px;' v-for="item of requests">
<div class="bodu" v-if="filterType == 'None' || filterType == item.state">
<div class="container" style="grid-template-columns:15% 15% 10% 14.2% 14.2% 14.2% 14.2%;grid-template-areas:'date state surname firstname accept refuse infos';" v-if="requestType === 'inscription'">
<div class="bodu" style="width: 95%" v-if="filterType == 'None' || filterType == item.state">
<div class="container" style="grid-template-columns:11% 15% 20% 10% 10% 9% 9%;grid-template-areas:'date state equivalencestate surname firstname accept refuse infos';" v-if="requestType === 'inscription'">
<!--
The condition below avoids an error occuring because loadRequests() finishes after the vue refresh
then submissionDate is undefined an it triggers an error in the console despite the fact that it is working
properly at the end.
-->
<div class="date" v-if="item.submissionDate !== undefined">{{item.submissionDate.slice(0, 10)}}</div>
<div class="state">{{item.state}}</div>
<div class="state" style="font-size: 80%">Approval : {{item.state}}</div>
<div class="equivalencestate" style="font-size: 80%">Teacher approval : {{item.equivalenceState}}</div>
<div class="surname">{{item.lastName}}</div>
<div class="firstname">{{item.firstName}}</div>
<div class="accept" v-if="item.state === 'Pending'"><button @click="windowsState=2;targetId=item.id;" style="background-color:rgb(0,105,50);">{{i18n("request.accept")}}</button></div>
@ -110,6 +109,10 @@
column-gap:10px;
}
.equivalencestate{
grid-area: equivalencestate;
align-self: center;
}
.studentfirstname{
grid-area: studentfirstname;
align-self: center;

View File

@ -20,6 +20,7 @@
address:null,
country:null,
curriculum:null,
equivalenceState: "Unrequired"
})
const notcompletedCheck = ref(false);
@ -76,18 +77,12 @@
//This functions makes the distinction between a master cursus (year 4 or more) and a bachelor cursus (year 3 or less)
function getCursusDisplay(cursus){
if (cursus.year <= 3){
return cursus.curriculumId + " BAB " + cursus.year + " " + cursus.option;
return "BAB " + cursus.year + " " + cursus.option;
}else{
return cursus.curriculumId + " MA" + (parseInt(cursus.year)-3).toString() + " " + cursus.option;
return "MA" + (parseInt(cursus.year)-3).toString() + " " + cursus.option;
}
}
//This function return the id of a decorated cursus (decorated by the function up)
function parseDecoratedCursus(cursus){
let id = cursus.substring(0, cursus.indexOf(" ")+1);
return id;
}
async function getCurriculumYear(curriculumId){
const curriculum = await getcurriculum(curriculumId);
return parseInt(curriculum.year);
@ -97,7 +92,7 @@
//Post the register request and return the id of the newly created request and also post the external curriculum list in the database
async function postRegisterReq(){
const val = await register(outputs.firstname, outputs.surname, outputs.birthday, outputs.password, outputs.email, outputs.address, outputs.country, parseDecoratedCursus(outputs.curriculum), ppData, null, new Date());
const val = await register(outputs.firstname, outputs.surname, outputs.birthday, outputs.password, outputs.email, outputs.address, outputs.country, outputs.curriculum, ppData, null, new Date(), outputs.equivalenceState);
for (let item in externalCurrTab.value){
await createExternalCurriculum(val.id, externalCurrTab.value[item].school, externalCurrTab.value[item].formation, externalCurrTab.value[item].completion, externalCurrTab.value[item].startYear, externalCurrTab.value[item].endYear, externalCurrTab.value[item].justifdocUrl);
}
@ -198,7 +193,7 @@
<div class="inputBox">
<p>{{i18n("Curriculum").toUpperCase()}}</p>
<select v-model="outputs.curriculum">
<option v-for="item in curricula">{{getCursusDisplay(item)}}</option>
<option v-for="item in curricula" :value="item.curriculumId">{{getCursusDisplay(item)}}</option>
</select>
</div>
<p style="color:rgb(239,60,168);">

213
frontend/src/Apps/Msg.vue Normal file
View File

@ -0,0 +1,213 @@
<!----------------------------------------------------
File: Msg.vue
Author: Anthony Debucquoy
Scope: Extension messagerie
Description: Main msg page
----------------------------------------------------->
<script setup>
import { ref, reactive } from 'vue'
import { discussionsList, currentDiscussion, fetchDiscussion, createDiscussion, sendMessage, updateDiscussionName, invite, removeMember} from '@/rest/msg.js'
const msgContent = ref("");
const addMember = ref(false);
const currentTitle = ref("");
function formatTime(date){
return date.getHours() + ":" + date.getMinutes() + " " + date.getDate() + "/" + date.getMonth();
}
</script>
<template>
<div id="msg">
<div id="discList">
<div @click="fetchDiscussion(discussion.id).then(e => currentTitle = currentDiscussion.name)" class="discItem" v-for="discussion in discussionsList" :key="discussion.id">{{ discussion.name }}</div>
<button id="createDiscussion" @click="createDiscussion('New Discussion')">+</button>
</div>
<div id="discussion" v-if="currentDiscussion.length != 0">
<h1 id=msgName ><input class="InputTitle" type="text" @change="updateDiscussionName(currentDiscussion.id, currentTitle)" v-model="currentTitle"></h1>
<div id=msgs>
<div class="msg" v-for="msg in currentDiscussion.msgs" :sender="msg.sender" :key="msg.id">
{{ msg.content }}<br/>
<span class="sender"><span v-if="!msg.sender">{{ msg.author.firstName }} {{ msg.author.lastName.toUpperCase() }}</span> {{formatTime(new Date(msg.created))}}</span>
</div>
</div>
<div id=messageBox>
<input type="text" @keyup.enter="sendMessage(currentDiscussion.id, msgContent, null); msgContent = ''" v-model="msgContent">
<input type="submit" @click="sendMessage(currentDiscussion.id, msgContent, null); msgContent = ''" value="send">
</div>
</div>
<div id="members" v-if="currentDiscussion.length != 0">
<div class="memberItem" v-for="member in currentDiscussion.members" @click="removeMember(currentDiscussion.id, member.regNo)" :key="member.id"><span>{{ member.firstName }} {{ member.lastName.toUpperCase() }}</span></div>
<input type=text id="addMembers" @focus="addMember = true" @blur="addMember = false;$event.target.value = ''" @change="invite(currentDiscussion.id, $event.target.value)" :placeholder="addMember ? 'Regno' : '+'"/>
</div>
</div>
</template>
<style scoped>
div#msg{
position: relative;
width: 100%;
height: 100%;
display: grid;
grid-template-columns: 20% auto 10%;
}
div#discList{
margin: 30px 0 30px 30px;
background-color: rgba(255, 255, 255, 0.05);
border-radius: 10px;
overflow: hidden;
padding: 10px;
display: flex;
flex-direction: column;
}
div#members{
margin: 30px 0;
border-radius: 10px 0 0 10px;
background-color: red;
background-color: rgba(255, 255, 255, 0.05);
overflow: hidden;
display: flex;
padding: 10px 0 0 10px;
flex-direction: column;
}
.InputTitle{
all: inherit;
margin: auto;
}
.discItem{
color: darkorange;
display: flex;
font-family: sans-serif;
font-weight: bold;
height: 4vh;
margin: 5px;
border-radius: 0 30px 30px 0;
align-items: center;
justify-content: center;
border: 1px solid darkorange;
}
.memberItem{
color: darkorange;
display: flex;
font-family: sans-serif;
font-weight: bold;
height: 4vh;
margin: 5px;
border-radius: 30px 0 0 30px;
align-items: center;
justify-content: center;
border: 1px solid darkorange;
}
.memberItem:hover span{
display: none;
}
.memberItem:hover{
background-color: red;
}
.memberItem:hover:before{
color: white;
content: "X"
}
#createDiscussion{
height: 4vh;
margin: 5px;
color: white;
background-color: green;
border-radius: 0 30px 30px 0;
border: none;
font-weight: 900;
font-size: 2em;
}
#addMembers{
height: 4vh;
margin: 5px;
text-align: center;
color: white;
background-color: green;
border-radius: 30px 0 0 30px;
border: none;
font-weight: 900;
font-size: 2em;
}
div#discussion{
display: flex;
flex-direction: column;
margin: 30px;
background-color: rgba(255, 255, 255, 0.05);
border-radius: 10px;
overflow: hidden;
}
#msgName{
text-align: center;
display: block;
background-color: #2a1981;
border-radius: 5px;
color: white;
width: 75%;
margin: 30px auto;
}
.discItem:hover{
background-color: gray;
}
#msgs{
display: flex;
flex-grow: 1;
flex-direction: column;
}
.msg {
background-color: aliceblue;
font-family: sans-serif;
margin: 10px;
padding: 5px;
border-radius: 3px;
max-width: 50%;
align-self: start;
}
.sender{
display: inline-block;
color: gray;
font-size: 0.5em;
}
.msg[sender=true]{
background-color: darkorange;
align-self: end;
}
#messageBox{
width: 100%;
height: 30px;
background-color: white;
display: flex;
}
#messageBox input[type="text"]{
all: inherit;
padding: 0 10px;
}
#messageBox input[type="submit"]{
border: inherit;
padding: 0 10px;
}
</style>

View File

@ -43,3 +43,4 @@ export async function getAllRegisters(){
export async function validateRegister(id, state){
return restPatch("/request/register/" + id, state);
}

View File

@ -26,7 +26,7 @@ export function disconnect(){
* @param curriculum
* @param imageId id of the image in database returned when uploaded
*/
export async function register(firstname, lastname, birthDate, password, email, address, country, curriculumId, imageId, identityCardId, submissionDate){
export async function register(firstname, lastname, birthDate, password, email, address, country, curriculumId, imageId, identityCardId, submissionDate, equivalence){
return restPost("/register", {
firstName: firstname,
lastName: lastname,
@ -38,7 +38,8 @@ export async function register(firstname, lastname, birthDate, password, email,
curriculumId: curriculumId,
profilePicture: imageId,
identityCard : identityCardId,
submissionDate : submissionDate
submissionDate : submissionDate,
equivalenceState : equivalence
});
}

View File

@ -10,6 +10,7 @@ import Courses from "@/Apps/ManageCourses.vue"
import Users from "@/Apps/UsersList.vue"
import Students from "@/Apps/StudentsList.vue"
import AboutStudent from "@/Apps/AboutStudent.vue";
import Msg from "@/Apps/Msg.vue"
const apps = {
'/login': LoginPage,
@ -18,6 +19,7 @@ const apps = {
'/manage-courses' : Courses,
'/users-list' : Users,
'/students-list' : Students,
'/msg' : Msg,
}
const appsList = {

View File

@ -1,4 +1,4 @@
import {restGet, restPost} from "@/rest/restConsumer.js";
import {restGet, restPatch, restPost} from "@/rest/restConsumer.js";
import {parseInteger} from "jsdom/lib/jsdom/living/helpers/strings.js";
export async function createExternalCurriculum(inscriptionRequestId,school, formation, completion, startYear, endYear, justifdocUrl){
@ -14,5 +14,9 @@ export async function createExternalCurriculum(inscriptionRequestId,school, form
}
export async function getExternalCurriculumByInscrReq(inscrReqId){
return restGet("/externalcurriculum/"+inscrReqId);
return restGet("/externalcurriculum/"+inscrReqId)
}
export async function editExternalCurriculum(extReqId, newState){
return restPatch("/externalcurriculum/"+extReqId+"/"+newState)
}

60
frontend/src/rest/msg.js Normal file
View File

@ -0,0 +1,60 @@
/*******************************************************
* File: msg.js
* Author: Anthony Debucquoy
* Scope: Extension messagerie
* Description: Messages frontend api consumer
*******************************************************/
import { restGet, restPost, restPatch } from './restConsumer.js'
import { ref } from 'vue'
/**
* - id
* - name
* - members
*/
export const discussionsList = ref();
export const currentDiscussion = ref([]);
let timerSet = false
export async function createDiscussion(name){
let disc = await restPost("/discussion", {name: name});
discussionsList.value.push(disc);
}
export async function invite(id, regNo){
restPatch("/discussion/"+ id+ "/add", {regNo: parseInt(regNo)}).then(() => fetchDiscussion(id))
}
export async function removeMember(id, regNo){
restPatch("/discussion/"+ id+ "/remove", {regNo: parseInt(regNo)}).then(() => fetchDiscussion(id))
}
export async function sendMessage(id, content, responseId){
let data = {
content: content,
response: responseId,
}
restPost("/discussion/" + id, data).then(() => fetchDiscussion(id));
}
export async function updateDiscussionName(id, name){
restPatch("/discussion/" + id, {name: name}).then(() => fetchDiscussions());
}
async function fetchDiscussions(){
discussionsList.value = await restGet("/discussions");
}
export async function fetchDiscussion(id){
currentDiscussion.value = await restGet("/discussion/" + id);
if(!timerSet){
timerSet = true;
setTimeout(() => {timerSet = false;fetchDiscussion(currentDiscussion.value.id)} , 5000);
}
}
await fetchDiscussions();

View File

@ -1,4 +1,4 @@
import {restGet, restPost} from "@/rest/restConsumer.js";
import {restGet, restPatch, restPost} from "@/rest/restConsumer.js";
export async function createExemptionsRequest(exempReq){
return restPost("/exemptionreq", exempReq)
@ -15,3 +15,7 @@ export async function getAllScholarShipsRequest(){
export async function getAllExemptionsRequest(){
return restGet("/exemptionsreq")
}
export async function editEquivalenceState(id, newstate){
return restPatch("/request/registerequiv/"+id+"/"+newstate)
}