Compare commits
394 Commits
d5e4387303
...
master
Author | SHA1 | Date | |
---|---|---|---|
c1b8c39e92
|
|||
3825565b16 | |||
48640dfa8b | |||
3acfd02bfb
|
|||
a3fe6ce6bd
|
|||
96965bde97 | |||
302e0b555c | |||
84a408298d | |||
3b48e5adfb | |||
78da7b23d2
|
|||
1831cc7eb2
|
|||
cc51510dac | |||
44bb04f21b | |||
1ed61c8c7b | |||
59c82d7482 | |||
772fa09e28 | |||
672fcd099f | |||
3198a7ade0 | |||
5516f75346 | |||
1f66ac5a4d | |||
59b82abf71 | |||
cf0c465248 | |||
2917d645fa | |||
730a72dba3 | |||
47eb98da57 | |||
eafcf6b265 | |||
34e537ff02 | |||
364f39c4bc | |||
f2675ed764 | |||
85c1282f48 | |||
4d6387ca8b | |||
fa2deca1b9 | |||
490bf403f0 | |||
c61a092809 | |||
2cffe28720
|
|||
060526c20d
|
|||
af8bc8872d | |||
12ff43e970 | |||
82cf7cbfaf
|
|||
3b63896439 | |||
bd3b03dfea | |||
b38b1ab6b8 | |||
6e0a9a46e5 | |||
2d8fcb4712 | |||
fcb48ac71a | |||
043f5c87d2
|
|||
a03983d625
|
|||
b382bf957f | |||
bbddcb26ad
|
|||
22665f0565 | |||
d324d7447d | |||
71c2af7fcb | |||
c717205764 | |||
4d007534b3 | |||
8ac1f7ed8b
|
|||
1a266cdfbd | |||
32810a9b01 | |||
217ad7f0d1 | |||
2d20b45c3a | |||
9cbdaac09d | |||
a90243f4b9
|
|||
636e17b4bf | |||
9cd54bdae9 | |||
69be9681ff | |||
98082f34b7 | |||
43883caef0
|
|||
88b057e19d
|
|||
260191d790
|
|||
608b6e4893 | |||
05ed28626a | |||
ca10084400 | |||
fa1a2c6d3b | |||
4485dbf803 | |||
b52c50fd76 | |||
172837d6d1 | |||
9a5115f7fe | |||
0d6b4ec57c | |||
e0a3a618a1 | |||
0b9227a822
|
|||
f14d41f04d
|
|||
76dcea186c | |||
a79f23fed0 | |||
43f3d66eb9 | |||
e25ead6230 | |||
70bec1a934 | |||
0837cc800a | |||
30f04b736b | |||
f83e689e4d | |||
29f13c3a3b | |||
33eb5c0f0c | |||
0621c6fe68 | |||
ecaf5e3df8 | |||
846cdedc4b | |||
881c935c00 | |||
e8bf0d953d | |||
219165aacf | |||
bc87748b31 | |||
8097f5314f | |||
1e2efac5bc | |||
061f329020 | |||
892d4f0651 | |||
9e45e6a9c9 | |||
ef03a6bdca | |||
f081b7206f | |||
7cdbf6de74 | |||
be23c3ab91 | |||
54d19eb888 | |||
e8917cd69e | |||
cdc3772384 | |||
e8fea7625f | |||
041fe7f95d | |||
0ffc8077db | |||
bd1c236635 | |||
c15ddccbb0 | |||
211bf77322 | |||
3ca074a3ba
|
|||
7bb1df123f
|
|||
6077e65b50 | |||
92cdeaebba | |||
4e14370d4f | |||
10c1c6096d
|
|||
be7f42aafe | |||
e998fb2ab4 | |||
69fb4e881e | |||
a168d41aee | |||
25575fa4e0 | |||
5a57fc78f3 | |||
70a8e98a0e | |||
a9e52d34d4 | |||
3f4f6ed49a | |||
fed567e9ab | |||
14c5423328 | |||
7394a23b45 | |||
939b4f5492 | |||
da2c0f472d | |||
8a5a26e2ab | |||
c9556e1eea | |||
78507f798f | |||
f9b12a5061 | |||
8724748642 | |||
dff225b0f5
|
|||
f8d60f40fc
|
|||
3281bf1d7e | |||
47f1bffb24 | |||
f19236b3f7 | |||
cba11d54ff | |||
a27cf63daf | |||
8fa29460ef
|
|||
1be7b4cdbe | |||
3ea48c20aa | |||
8c70108a1c | |||
e303048f7e | |||
6116cbdaa4 | |||
bdfa2e6389 | |||
d4c442c64a | |||
94be706226
|
|||
5c0dfa3596 | |||
24f82812f4 | |||
881b30e5c9
|
|||
058c53dbbc | |||
caa39696d2 | |||
b9d7950e12 | |||
f269e24bb4 | |||
7a05fc1316 | |||
c0233fce57 | |||
821377a72f | |||
a2be04bfb3 | |||
388c53e47b | |||
87b02af68e | |||
f184de21a8 | |||
63d0087d0c | |||
451944e4fb | |||
c434b28fe3 | |||
a89d1b192c | |||
eacdf8d47a | |||
61eac8959a | |||
05bff0fa77 | |||
9112004326 | |||
1498cfa11e | |||
c6ce6d3e5b
|
|||
2e02cd8870
|
|||
98c9d2d754 | |||
17cb969160 | |||
8ebedec689 | |||
4199663d64 | |||
adaa828810 | |||
4720669c2c | |||
5e9eccc4f6 | |||
34c0a2bfe8 | |||
706481ed1a | |||
0c04bed799 | |||
95ef4023d6 | |||
9d0b3da9d3 | |||
8650482d11 | |||
783cd8fa9f | |||
40186f9898 | |||
106bf96a98
|
|||
b7a729c899 | |||
fdf4993def | |||
dad6953f99 | |||
f99ed470f8 | |||
9a83d14aea | |||
7b0d76dae8
|
|||
61e269eb27
|
|||
76c3b76153 | |||
21a5dbdb22 | |||
142ea996d8 | |||
0cbe0dd82b | |||
3167d1f2fc | |||
e6e147af26 | |||
a94167c8a0 | |||
194b14f02b | |||
5f483216b9
|
|||
5a4d066c45
|
|||
d31547c4cc | |||
ec2b975467 | |||
f9bcff6d4f
|
|||
aa3e1cb868 | |||
3c721de18b | |||
5bb7606721
|
|||
b049c46571
|
|||
b8b193f344
|
|||
05359d64ac | |||
7bd745fd5e
|
|||
3d78851b29 | |||
648b73b585 | |||
dbe28a7fed | |||
bd7d2c2d51 | |||
9937a7db39 | |||
a96609d2ef
|
|||
cb750b8505
|
|||
91c7f42521 | |||
443cf55784 | |||
7ca5c34afe
|
|||
2b9bdf8dac
|
|||
ccb954e348
|
|||
3761fa6f49
|
|||
cb36aa8a30
|
|||
bd27ffd3cb | |||
2b9493422d | |||
8442101c40 | |||
bce53305b3 | |||
47e4fb2f8c | |||
2e2837fec4 | |||
0e26e1a0db | |||
91ee3adbcd | |||
c1b2742a8f | |||
2805fede4b | |||
951feed3c8 | |||
95054fa973 | |||
3af83a58d3 | |||
47c5c14862 | |||
4a314449ad | |||
ce56e37a33
|
|||
1c61a356a4
|
|||
2bdffe6ab4
|
|||
a3c9d6a7c0 | |||
729d1ad504
|
|||
1522d74ed3
|
|||
b4499e04c7
|
|||
94f12f0a86 | |||
839ca414ce | |||
eafff6ec2d | |||
914f6bdf36
|
|||
66e7fa24a1
|
|||
7b9f021c24
|
|||
2dfa0a0ee0
|
|||
9e0db361b8 | |||
621f568ba2 | |||
972d08a54d | |||
7a13d412f1 | |||
67fa630ecf | |||
db895a6091 | |||
ad0e7b3e35 | |||
9de4b06e75 | |||
123fa97611 | |||
1fad792be7 | |||
acd1262955
|
|||
3d6941ab93
|
|||
de72bd800c
|
|||
b465dcfa92 | |||
73f3df0bc6 | |||
90a7b7b70e | |||
4f002a29e1 | |||
66d090d045 | |||
4715441afd | |||
77ac771b8f | |||
3762750968 | |||
a276c24f8f | |||
25c5c1b018 | |||
c7f37b0854 | |||
c35f675a11 | |||
a9e5e45872 | |||
73d50f3f50 | |||
0871d2971d | |||
9744bd973f | |||
ecaa0af24a | |||
a762b6875d
|
|||
4e6c4ecf38 | |||
ec3c912847
|
|||
5636d96478 | |||
d40ceff2ba
|
|||
fd357ba938 | |||
92079c5a47 | |||
753af3874e | |||
e03a01ec89 | |||
fd18df7c3a | |||
93c161be4c | |||
853a3a42d2
|
|||
a80fb2b297 | |||
f484fb095e | |||
8ff29ca34e | |||
611e7167f9
|
|||
ee37dc79a7
|
|||
2fb6aef67c | |||
7e7cec2f6c | |||
345599888d | |||
19b4950be4 | |||
d9307753c4 | |||
7a23dcc96a | |||
f2b80ba89f | |||
114116b97c | |||
924faca13f | |||
ea4a0745e0 | |||
76f5a39a8f | |||
37f8a3ac4e | |||
ea46dd664c | |||
b2d0be014c | |||
571d27c230 | |||
37a9eb46ae | |||
bfc4f6567b | |||
d423a57fa0 | |||
210fda0401 | |||
b67b25b4a4 | |||
385290d1a2 | |||
cf2deb983d | |||
dcec45acf5 | |||
008af10d0e | |||
f7df234312 | |||
d855bbe911 | |||
f2507ddcdd | |||
a70b05a0ef | |||
1d793cef4e | |||
4cf2ac1aa8 | |||
6e6bd285af | |||
474a8d3f31 | |||
4379794dba | |||
c5d7ce4178 | |||
382d3c203a | |||
5a7934b2a3 | |||
8476563678 | |||
97b57b361d | |||
069466ef5f | |||
d5f6656e2b | |||
32e26f35cb | |||
36fc33c3e9 | |||
17ab241250
|
|||
36ce5a553b | |||
a5807148e1 | |||
53e478b05c | |||
182be8ac7b
|
|||
beba199f60 | |||
767a83d1d6 | |||
da3f8c47f9
|
|||
8d1235be92 | |||
1546fc6d47
|
|||
04f64f505e
|
|||
e84e34d735 | |||
c955fbf5f8 | |||
847936b799
|
|||
0b27d2e8d8
|
|||
45fbef52ed
|
|||
ca6f676fb7 | |||
cc8530621d
|
|||
abff9aef3a | |||
41288258c9 | |||
47a0c97f3d | |||
3ea6c7886a | |||
17d0ae7ccc
|
|||
8f2fb04112 | |||
c6198b7220 | |||
13fd048cd2 | |||
b7b2eafb93 | |||
0860567e1b | |||
25009ba149 | |||
208c6c63e8 | |||
e2da7271af | |||
77a170be6d
|
|||
ae4ad036a8
|
|||
3996765c8a
|
|||
1f14890d43 | |||
189e664f37 | |||
c8b7930a8e | |||
160cfb0bbf |
@ -17,15 +17,4 @@ jobs:
|
||||
distribution: 'temurin'
|
||||
- uses: gradle/gradle-build-action@v3
|
||||
- name: building
|
||||
run: ./gradlew backend:build
|
||||
Test-backend:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
- uses: gradle/gradle-build-action@v3
|
||||
- name: building
|
||||
run: ./gradlew backend:test
|
||||
run: ./gradlew backend:build -x test
|
||||
|
@ -14,38 +14,31 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
deploy-frontend:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v3
|
||||
working-directory: ./frontend
|
||||
- run: npm ci
|
||||
name: clean install
|
||||
working-directory: ./frontend
|
||||
- name: building
|
||||
working-directory: ./frontend
|
||||
run: npm run build
|
||||
- name: pushing to the server
|
||||
working-directory: ./frontend
|
||||
run: |
|
||||
echo "${{ secrets.SSH_KEY }}" > key
|
||||
chmod 0600 key
|
||||
scp -o "StrictHostKeyChecking=no" -o "LogLevel=ERROR" -i key -r dist/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:
|
||||
- run: echo "The website has been deployed. visit https://clyde.herisson.ovh/"
|
||||
# deploy-frontend:
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - uses: actions/checkout@v4
|
||||
# - name: Use Node.js ${{ matrix.node-version }}
|
||||
# uses: actions/setup-node@v3
|
||||
# working-directory: ./frontend
|
||||
# - run: npm ci
|
||||
# name: clean install
|
||||
# working-directory: ./frontend
|
||||
# - name: building
|
||||
# working-directory: ./frontend
|
||||
# run: npm run build
|
||||
# - name: pushing to the server
|
||||
# working-directory: ./frontend
|
||||
# run: |
|
||||
# echo "${{ secrets.SSH_KEY }}" > key
|
||||
# chmod 0600 key
|
||||
# scp -o "StrictHostKeyChecking=no" -o "LogLevel=ERROR" -i key -r dist/ ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:
|
||||
# - run: echo "The website has been deployed. visit https://clyde.herisson.ovh/"
|
||||
|
||||
deploy-backend:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-java@v3
|
||||
with:
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
- uses: gradle/gradle-build-action@v3
|
||||
- name: building
|
||||
run: ./gradlew backend:build
|
||||
- name: pushing to the server
|
||||
run: |
|
||||
echo "${{ secrets.SSH_KEY }}" > key
|
||||
@ -53,5 +46,5 @@ jobs:
|
||||
scp -o "StrictHostKeyChecking=no" -o "LogLevel=ERROR" -i key -r * ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:api/
|
||||
- name: restarting the backend
|
||||
run: |
|
||||
ssh -o "StrictHostKeyChecking=no" -o "LogLevel=ERROR" -i key ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} 'cd api/backend && docker build -t clyde/backend . && docker rm clyde_backend_prod -f || true && docker run --rm -d -u $(id -u clyde):$(id -g clyde) -v /var/run/postgresql:/var/run/postgresql --name clyde_backend_prod -p 4000:8080 clyde/backend && docker image prune -f'
|
||||
ssh -o "StrictHostKeyChecking=no" -o "LogLevel=ERROR" -i key ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} 'cd api/ && sed -i compose.yaml -e "s/8080:8080/4001:8080/" -e "s/8000:8080/4000:8080/" && sed -e "8d" -i frontend/Dockerfile && docker-compose up --force-recreate --build -d'
|
||||
- run: echo "The backend has been deployed. running at https://clyde.herisson.ovh/api"
|
||||
|
37
README.md
37
README.md
@ -1,5 +1,7 @@
|
||||
# Clyde project
|
||||
|
||||
Système de gestion d'universitée (dévelopé dans le cadre du cours de projet de génie logiciel de l'Umons 2024)
|
||||
|
||||
## Signature
|
||||
|
||||
Projet du groupe 01:
|
||||
@ -9,10 +11,39 @@ Projet du groupe 01:
|
||||
- William Karpinski: Extension gestion des horaires
|
||||
- Léo Moulin: Extension inscription des étudiants
|
||||
|
||||
## Running
|
||||
|
||||
**Attention**: Vous devez avoir installé docker-compose pour lancer ce projet.
|
||||
|
||||
Le projet peut être lancé grace à docker compose.
|
||||
|
||||
```sh
|
||||
$ docker compose up
|
||||
```
|
||||
|
||||
Dans le cas ou vous modifiez des fichiers, pour éviter que les images de docker ne soient réutilisés sans les
|
||||
changements.
|
||||
|
||||
```sh
|
||||
$ docker compose up --force-recreate --build
|
||||
```
|
||||
Vous pouvez alors accéder au frontend à l'adresse [http://localhost:5173](http://localhost:5173)
|
||||
|
||||
Une version finie du site construite automatiquement à l'aide de gitea actions tourne à l'adresse
|
||||
[https://clyde.herisson.ovh/](https://clyde.herisson.ovh/)
|
||||
|
||||
## Dévelopement
|
||||
|
||||
```
|
||||
$ ./gradlew backend:run frontend:run --parallel
|
||||
```
|
||||
Dans le cas ou vous êtes dans une phase de développement, il est plus simple d'utiliser gradle pour lancer le backend et frontend.
|
||||
**Attention**: Ce mode n'est pas fait pour être utilisé en production!
|
||||
|
||||
```sh
|
||||
$ ./gradlew run --parallel
|
||||
```
|
||||
permet de lancer le frontend sur [http://localhost:5173](http://localhost:5173) ansi que le frontend sur [http://localhost:8080](http://localhost:8080)
|
||||
|
||||
Ceci requière également docker pour lancer une instance de postgresql pris en charge par spring.
|
||||
|
||||
Il est possible de se passer entièrement de docker en supprimant la dépendance dans le fichier `backend/build.gradle.kts`: ~~`developmentOnly("org.springframework.boot:spring-boot-docker-compose")`~~
|
||||
Il est alors nécéssaire d'avoir une instance de postgresql tournant sur `localhost:5432` avec une table `clyde`, utilisateur: `devel` et password: `devel`
|
||||
(cette configuration peut également être changée dans le fichier resources/application.properties de spring)
|
||||
|
2
backend/.gitignore
vendored
2
backend/.gitignore
vendored
@ -35,3 +35,5 @@ out/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
/cdn
|
||||
|
@ -1,5 +1,15 @@
|
||||
## Building phase
|
||||
FROM gradle:jdk21-alpine AS BUILD
|
||||
WORKDIR /backend
|
||||
|
||||
COPY . .
|
||||
RUN gradle build -x test
|
||||
|
||||
## Running Phase
|
||||
FROM eclipse-temurin:21-jdk-alpine
|
||||
VOLUME /tmp
|
||||
ENV SPRING_PROFILES_ACTIVE=prod
|
||||
COPY build/libs/backend-0.0.1-SNAPSHOT.jar /app.jar
|
||||
ENTRYPOINT ["java", "-jar", "/app.jar"]
|
||||
WORKDIR /backend
|
||||
VOLUME /cdn
|
||||
# ENV SPRING_PROFILES_ACTIVE=prod
|
||||
COPY --from=BUILD /backend/build/libs/Clyde-0.0.1-SNAPSHOT.jar /backend/app.jar
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["java", "-jar", "/backend/app.jar"]
|
||||
|
@ -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")
|
||||
@ -31,8 +33,11 @@ dependencies {
|
||||
testImplementation("org.springframework.boot:spring-boot-testcontainers")
|
||||
testImplementation("org.testcontainers:junit-jupiter")
|
||||
testImplementation("org.testcontainers:postgresql")
|
||||
testImplementation("io.rest-assured:rest-assured")
|
||||
testImplementation("org.hamcrest:hamcrest")
|
||||
}
|
||||
|
||||
|
||||
tasks.register("run") {
|
||||
dependsOn(tasks.bootRun)
|
||||
}
|
||||
|
@ -6,4 +6,4 @@ services:
|
||||
- 'POSTGRES_USER=devel'
|
||||
- 'POSTGRES_PASSWORD=devel'
|
||||
ports:
|
||||
- '5432:5432'
|
||||
- '5442:5432'
|
||||
|
13
backend/settings.gradle.kts
Normal file
13
backend/settings.gradle.kts
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* The settings file is used to specify which projects to include in your build.
|
||||
* For more detailed information on multi-project builds, please refer to https://docs.gradle.org/8.6/userguide/multi_project_builds.html in the Gradle documentation.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
// Apply the foojay-resolver plugin to allow automatic download of JDKs
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
|
||||
}
|
||||
|
||||
rootProject.name = "Clyde"
|
@ -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);
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package ovh.herisson.Clyde.DTO.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file ResearchDTO.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Research format to return to front (without author's password)
|
||||
******************************************************/
|
||||
|
||||
import lombok.Data;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Access;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.PaperType;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Data
|
||||
public class ResearchDTO {
|
||||
|
||||
private long id;
|
||||
private String title;
|
||||
private ResearcherDTO researcher;
|
||||
private final Set<ResearcherDTO> coAuthors;
|
||||
private Date releaseDate;
|
||||
private PaperType paperType;
|
||||
private String pdfLocation;
|
||||
private String bibTexLocation;
|
||||
private String language;
|
||||
private Access access;
|
||||
private String domain;
|
||||
private String summary;
|
||||
private long views;
|
||||
|
||||
private ResearchDTO(String title, ResearcherDTO researcherDTO, Date releaseDate, PaperType paperType, String pdfLocation, String language, Access access, String domain, String bibTexLocation, String summary, Set<Researcher> coAuthors, long id, long views) {
|
||||
this.title = title;
|
||||
this.researcher = researcherDTO;
|
||||
this.releaseDate = releaseDate;
|
||||
this.paperType = paperType;
|
||||
this.pdfLocation = pdfLocation;
|
||||
this.language = language;
|
||||
this.access = access;
|
||||
this.domain = domain;
|
||||
this.summary = summary;
|
||||
this.id = id;
|
||||
this.bibTexLocation = bibTexLocation;
|
||||
this.coAuthors = new HashSet<>();
|
||||
for (Researcher coAuthor: coAuthors) {
|
||||
this.coAuthors.add(ResearcherDTO.construct(coAuthor));
|
||||
}
|
||||
this.views = views;
|
||||
}
|
||||
|
||||
|
||||
public static ResearchDTO construct(Research research){
|
||||
return new ResearchDTO(research.getTitle(), ResearcherDTO.construct(research.getAuthor()), research.getReleaseDate(),
|
||||
research.getPaperType(),research.getPdfLocation(),research.getLanguage(),research.getAccess(),
|
||||
research.getDomain(),research.getBibTexLocation(), research.getSummary(), research.getCoAuthors(),research.getId(), research.getViews());
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package ovh.herisson.Clyde.DTO.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file ResearcherDTO.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Researcher Format to return to front (without user password)
|
||||
******************************************************/
|
||||
import lombok.Data;
|
||||
import ovh.herisson.Clyde.Services.ProtectionService;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class ResearcherDTO {
|
||||
|
||||
private long id;
|
||||
private Map<String,Object> user;
|
||||
private String site;
|
||||
private String domain;
|
||||
private String orcidId;
|
||||
|
||||
|
||||
private ResearcherDTO(long id, Map<String ,Object> user, String site,String domain,String orcidId){
|
||||
this.domain = domain;
|
||||
this.orcidId = orcidId;
|
||||
this.site = site;
|
||||
this.user = user;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static ResearcherDTO construct(Researcher researcher){
|
||||
return new ResearcherDTO(researcher.getId(), ProtectionService.userWithoutPassword(researcher.getUser()),researcher.getSite(),
|
||||
researcher.getDomain(),researcher.getOrcidId());
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
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.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.ScientificPublications.ResearchesService;
|
||||
import ovh.herisson.Clyde.Tables.Applications;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
public class ApplicationsController {
|
||||
|
||||
AuthenticatorService authServ;
|
||||
|
||||
ResearchesService researchesServ;
|
||||
|
||||
public ApplicationsController(AuthenticatorService authServ, ResearchesService researchesServ){
|
||||
this.researchesServ = researchesServ;
|
||||
this.authServ = authServ;
|
||||
}
|
||||
|
||||
|
||||
/** return a list of authorized applications.
|
||||
* depends on the token
|
||||
*/
|
||||
@GetMapping("/apps")
|
||||
public ResponseEntity<Iterable<Applications>> getAuthorizedApps(@RequestHeader("Authorization") String token){
|
||||
return new ResponseEntity<>(getAuthorizedApplications(token), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/apps/{identifier}")
|
||||
public ResponseEntity<Boolean> getAppAuthorization(@PathVariable Applications identifier, @RequestHeader("Authorization") String token){
|
||||
|
||||
if (getAuthorizedApplications(token).contains(identifier)){
|
||||
return new ResponseEntity<>(true, HttpStatus.OK);
|
||||
}
|
||||
return new ResponseEntity<>(false, HttpStatus.OK);
|
||||
}
|
||||
|
||||
public ArrayList<Applications> getAuthorizedApplications(String token){
|
||||
ArrayList<Applications> authorizedApps = new ArrayList<>();
|
||||
|
||||
//if unAuthed
|
||||
authorizedApps.add(Applications.Login);
|
||||
authorizedApps.add(Applications.ListResearches);
|
||||
authorizedApps.add(Applications.Schedule);
|
||||
|
||||
User user = authServ.getUserFromToken(token);
|
||||
if(user == null)
|
||||
return authorizedApps;
|
||||
// if authed
|
||||
authorizedApps.add(Applications.Profile);
|
||||
|
||||
if (!authServ.isNotIn(new Role[]{Role.Teacher,Role.Student,Role.Admin},token)) {
|
||||
authorizedApps.add(Applications.Msg);
|
||||
authorizedApps.add(Applications.Forum);
|
||||
authorizedApps.add(Applications.Rdv);
|
||||
}
|
||||
|
||||
if(!authServ.isNotIn(new Role[]{Role.Teacher,Role.Admin},token))
|
||||
authorizedApps.add(Applications.ManageOwnedLessons);
|
||||
//if Teacher or Secretary or Admin add ManageCourses App
|
||||
if (!authServ.isNotIn(new Role[]{Role.Teacher,Role.Secretary,Role.Admin},token))
|
||||
authorizedApps.add(Applications.ManageCourses);
|
||||
|
||||
if (!authServ.isNotIn(new Role[]{Role.InscriptionService,Role.Admin, Role.Teacher},token)){
|
||||
authorizedApps.add(Applications.Requests);
|
||||
authorizedApps.add(Applications.StudentsList);}
|
||||
|
||||
if (researchesServ.getResearcherByUser(user) != null)
|
||||
authorizedApps.add(Applications.ManageResearcherProfile);
|
||||
|
||||
if (!authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token)){
|
||||
authorizedApps.add(Applications.UsersList);
|
||||
authorizedApps.add(Applications.ManageSchedules);
|
||||
authorizedApps.add(Applications.LessonRequests);
|
||||
authorizedApps.add(Applications.CreateUser);
|
||||
}
|
||||
|
||||
if (!authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin, Role.InscriptionService},token)){
|
||||
authorizedApps.add(Applications.Payments);}
|
||||
return authorizedApps;
|
||||
}
|
||||
}
|
@ -0,0 +1,174 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Repositories.CurriculumCourseRepository;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.*;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
public class CourseController {
|
||||
|
||||
private final CourseService courseServ;
|
||||
|
||||
private final TeacherCourseService teacherCourseServ;
|
||||
|
||||
private final AuthenticatorService authServ;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
private final CurriculumService curriculumService;
|
||||
|
||||
private final UserCurriculumService userCurriculumService;
|
||||
|
||||
private final CurriculumCourseRepository curriculumCourseRepository;
|
||||
private final CurriculumCourseService curriculumCourseService;
|
||||
public CourseController(CourseService courseServ, TeacherCourseService teacherCourseServ, AuthenticatorService authServ, UserService userService, CurriculumService curriculumService, UserCurriculumService userCurriculumService, CurriculumCourseRepository curriculumCourseRepository, CurriculumCourseService curriculumCourseService) {
|
||||
this.courseServ = courseServ;
|
||||
this.teacherCourseServ = teacherCourseServ;
|
||||
this.authServ = authServ;
|
||||
this.userService = userService;
|
||||
this.curriculumService = curriculumService;
|
||||
this.userCurriculumService = userCurriculumService;
|
||||
this.curriculumCourseRepository = curriculumCourseRepository;
|
||||
this.curriculumCourseService = curriculumCourseService;
|
||||
}
|
||||
|
||||
@GetMapping("/course/{id}")
|
||||
public ResponseEntity<HashMap<String,Object>> getCourse(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
if (authServ.getUserFromToken(token) == null)
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
Course foundCourse = courseServ.findById(id);
|
||||
|
||||
if (foundCourse == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.courseWithoutPassword(foundCourse), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/courses")
|
||||
public ResponseEntity<Iterable<HashMap<String,Object>>> getAllCourses(@RequestHeader("Authorization") String token){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.coursesWithoutPasswords(courseServ.findAll()),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/courses/owned")
|
||||
public ResponseEntity<Iterable<HashMap<String ,Object>>> getOwnedCourses(@RequestHeader("Authorization") String token){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.coursesWithoutPasswords(courseServ.findOwnedCourses(authServ.getUserFromToken(token))),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/course/{id}/assistants")
|
||||
public ResponseEntity<Iterable<HashMap<String,Object>>> getCourseAssistants(@RequestHeader("Authorization")String token, @PathVariable long id){
|
||||
if (authServ.getUserFromToken(token) == null)
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
Iterable<User> assistants = teacherCourseServ.findCourseAssistants(courseServ.findById(id));
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.usersWithoutPasswords(assistants),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/course/curriculum/{id}")
|
||||
public ResponseEntity<Map<String ,Object>> postCourse(@RequestHeader("Authorization") String token,
|
||||
@RequestBody Course course,@PathVariable long id)
|
||||
{
|
||||
if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
Course createdCourse = courseServ.save(course);
|
||||
Curriculum curriculum = curriculumService.findById(id);
|
||||
if (createdCourse == null || curriculum == null)
|
||||
return new ResponseEntity<>(null,HttpStatus.BAD_REQUEST);
|
||||
CurriculumCourse curriculumCourse = new CurriculumCourse(curriculum,course);
|
||||
curriculumCourseService.save(curriculumCourse);
|
||||
return new ResponseEntity<>(ProtectionService.courseWithoutPassword(createdCourse), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
|
||||
@PatchMapping("/course/{id}")
|
||||
public ResponseEntity<Course> patchCourse(@RequestHeader("Authorization") String token,
|
||||
@RequestBody Map<String,Object> updates,
|
||||
@PathVariable long id)
|
||||
{
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher,Role.Secretary}, token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
|
||||
|
||||
if (!courseServ.modifyData(id, updates, authServ.getUserFromToken(token).getRole()))
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/course/{id}")
|
||||
public ResponseEntity<String> postTeachers(@RequestHeader("Authorization") String token,
|
||||
@RequestBody Iterable<Long> teacherIds,
|
||||
@PathVariable Long id)
|
||||
{
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary}, token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
|
||||
if (!teacherCourseServ.saveAll(teacherIds,courseServ.findById(id)))
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("course/{id}")
|
||||
public ResponseEntity<String> deleteUser(@RequestHeader("Authorization") String token, @PathVariable Long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary}, token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
Course toDelete = courseServ.findById(id);
|
||||
|
||||
if (toDelete == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
|
||||
courseServ.delete(courseServ.findById(id));
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
//Get all the courses followed by an user
|
||||
@GetMapping("/usercourses")
|
||||
public ResponseEntity<List<Course>> getAllUserCourses(@RequestHeader("Authorization") String token){
|
||||
User u = authServ.getUserFromToken(token);
|
||||
|
||||
//We get all the actual curriculums of the user
|
||||
List<UserCurriculum> userCurricula = userCurriculumService.findByStudentAndActual(u, true);
|
||||
List<Course> toReturn = new ArrayList<>();
|
||||
|
||||
//We iterate through all the curriculums and we extract the courses
|
||||
for (int i = 0; i < userCurricula.size(); i++){
|
||||
curriculumCourseRepository.findCoursesByCurriculum(userCurricula.get(i).getCurriculum()).forEach((item) -> {
|
||||
//We need this to eliminate clones because a course can belong to several curriculums
|
||||
if(!toReturn.contains(item)){
|
||||
toReturn.add(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(toReturn, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.InscriptionRepository;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.*;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
public class CurriculumController {
|
||||
|
||||
|
||||
private final CurriculumService curriculumServ;
|
||||
private final CourseService courseServ;
|
||||
private final AuthenticatorService authServ;
|
||||
|
||||
private final UserCurriculumService userCurriculumServ;
|
||||
private final CurriculumCourseService curriculumCourseServ;
|
||||
private final InscriptionRepository ir;
|
||||
private final UserService userServ;
|
||||
|
||||
private final ExternalCurriculumRepository ecr;
|
||||
public CurriculumController(CurriculumService curriculumServ, CourseService courseServ, AuthenticatorService authServ, UserCurriculumService userCurriculumServ, CurriculumCourseService curriculumCourseServ, InscriptionRepository ir, UserService userServ, ExternalCurriculumRepository ecr){
|
||||
this.curriculumServ = curriculumServ;
|
||||
this.courseServ = courseServ;
|
||||
this.authServ = authServ;
|
||||
this.userCurriculumServ = userCurriculumServ;
|
||||
this.curriculumCourseServ = curriculumCourseServ;
|
||||
this.ir = ir;
|
||||
this.userServ = userServ;
|
||||
this.ecr = ecr;
|
||||
}
|
||||
|
||||
@GetMapping("/curriculum/{id}")
|
||||
public ResponseEntity<Map<String,Object>> findById(@PathVariable long id){
|
||||
Curriculum foundCurriculum = curriculumServ.findById(id);
|
||||
|
||||
if (foundCurriculum == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(curriculumCourseServ.getDepthCurriculum(foundCurriculum), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/curriculum")
|
||||
public ResponseEntity<Map<String ,Object>> findSelfCurriculum(@RequestHeader("Authorization") String token){
|
||||
if (authServ.getUserFromToken(token) == null)
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
Curriculum curriculum = userCurriculumServ.findByUser(authServ.getUserFromToken(token));
|
||||
|
||||
if (curriculum == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(curriculumCourseServ.getDepthCurriculum(curriculum),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/course/curriculum/{id}")
|
||||
public ResponseEntity<Iterable<Curriculum>> getCurriculumsByCourse(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
if(authServ.isNotIn(new Role[]{Role.Admin, Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
Course course = courseServ.findById(id);
|
||||
if(course == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
Iterable<Curriculum> curriculum = curriculumCourseServ.findCurriculumByCourses(course);
|
||||
return new ResponseEntity<>(curriculum, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Return the list of all curicullums of an user
|
||||
@GetMapping("/onescurriculum/{userId}")
|
||||
public ResponseEntity<Map<String ,Object>> findOnesCurriculum(@RequestHeader("Authorization") String token, @PathVariable String userId){
|
||||
if (authServ.getUserFromToken(token) == null)
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
User u = userServ.getUserById(Long.parseLong(userId));
|
||||
HashMap<String,Object> toReturn = userCurriculumServ.findAllCurriculumByStudent(u);
|
||||
|
||||
if (toReturn == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(toReturn,HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/curriculums")
|
||||
public ResponseEntity<Iterable<Map<String, Object>>> findAllIndDepth(){
|
||||
return new ResponseEntity<>(curriculumCourseServ.getAllDepthCurriculum(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/curriculum")
|
||||
public ResponseEntity<Curriculum> postCurriculum(@RequestHeader("Authorization") String token,@RequestBody Curriculum curriculum){
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
return new ResponseEntity<>(curriculumServ.save(curriculum),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PostMapping("/curriculum/{id}")
|
||||
public ResponseEntity<String> postCourseToCurriculum(@RequestHeader("Authorization") String token,
|
||||
@RequestBody long coursesId,
|
||||
@PathVariable long id){
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
CurriculumCourse curriculumCourse = new CurriculumCourse(curriculumServ.findById(id), courseServ.findById(coursesId));
|
||||
if(curriculumCourse.getCourse() == null || curriculumCourse.getCurriculum() == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
|
||||
curriculumCourseServ.save(curriculumCourse);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping("/curriculum/{id}")
|
||||
public ResponseEntity<String > deleteCurriculum(@RequestHeader("Authorization") String token, @PathVariable Long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary}, token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
Curriculum toDelete = curriculumServ.findById(id);
|
||||
|
||||
if (toDelete == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
curriculumServ.delete(toDelete);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.CursusCourseService;
|
||||
import ovh.herisson.Clyde.Services.CursusService;
|
||||
import ovh.herisson.Clyde.Tables.Cursus;
|
||||
import ovh.herisson.Clyde.Tables.CursusCourse;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
public class CursusController {
|
||||
|
||||
|
||||
private final CursusService cursusServ;
|
||||
private final AuthenticatorService authServ;
|
||||
|
||||
private final CursusCourseService cursusCourseServ;
|
||||
|
||||
public CursusController(CursusService cursusServ, AuthenticatorService authServ, CursusCourseService cursusCourseServ){
|
||||
this.cursusServ = cursusServ;
|
||||
this.authServ = authServ;
|
||||
this.cursusCourseServ = cursusCourseServ;
|
||||
}
|
||||
|
||||
@GetMapping("/cursus/{id}")
|
||||
public ResponseEntity<Cursus> findById(@PathVariable long id){
|
||||
return new ResponseEntity<>(cursusServ.findById(id), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/curriculums")
|
||||
public ResponseEntity<Iterable<Map<String, Object>>> findAllindDepth(){
|
||||
return new ResponseEntity<>(cursusCourseServ.getAllDepthCursus(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/curriculum")
|
||||
public ResponseEntity<Iterable<CursusCourse>> findAll(){
|
||||
return new ResponseEntity<>(cursusCourseServ.findAll(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**@PostMapping("/cursus")
|
||||
public ResponseEntity<String> postCursus(@RequestHeader("Authorization") String token,@RequestBody Cursus cursus){
|
||||
|
||||
if (!isSecretaryOrAdmin(token)){
|
||||
return new UnauthorizedResponse<>("you're not allowed to post a cursus");
|
||||
}
|
||||
|
||||
cursusServ.save(cursus);
|
||||
|
||||
return new ResponseEntity<>("created !",HttpStatus.CREATED);
|
||||
}**/
|
||||
|
||||
|
||||
|
||||
private boolean isSecretaryOrAdmin(String authorization){
|
||||
if (authorization ==null)
|
||||
return false;
|
||||
|
||||
User poster = authServ.getUserFromToken(authorization);
|
||||
if (poster == null) return false;
|
||||
|
||||
return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin;
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package ovh.herisson.Clyde.EndPoints.Inscription;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.InscriptionRepository;
|
||||
import ovh.herisson.Clyde.Repositories.UserRepository;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.ExternalCurriculum;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
public class ExternalCurriculumController {
|
||||
|
||||
public final ExternalCurriculumRepository ecr;
|
||||
public final InscriptionRepository inscriptionRepository;
|
||||
public final UserRepository userRepository;
|
||||
|
||||
public ExternalCurriculumController(ExternalCurriculumRepository ecr, InscriptionRepository inscriptionRepository, UserRepository userRepository) {
|
||||
this.ecr = ecr;
|
||||
this.inscriptionRepository = inscriptionRepository;
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
//everyone can post some externalcurriculums (the validity of the elements is assured by the inscription service)
|
||||
@PostMapping("/externalcurriculum")
|
||||
public ResponseEntity<ExternalCurriculum> postExternalCurriculum(@RequestBody Map<String, Object> externalCurrInfos){
|
||||
//An external curriculum can either be linked to an User or to an InscriptionRequest
|
||||
InscriptionRequest ir = null;
|
||||
User user = null;
|
||||
if (externalCurrInfos.get("inscriptionRequestId") != null){
|
||||
ir = inscriptionRepository.findById((Integer) externalCurrInfos.get("inscriptionRequestId"));
|
||||
}else{
|
||||
user = userRepository.findById((Integer) externalCurrInfos.get("userRegNo"));
|
||||
}
|
||||
|
||||
ExternalCurriculum toSave = new ExternalCurriculum(ir, (String) externalCurrInfos.get("school"),(String) externalCurrInfos.get("formation"),(String) externalCurrInfos.get("completion"), (Integer)externalCurrInfos.get("startYear"), (Integer)externalCurrInfos.get("endYear"), (String)externalCurrInfos.get("justifdocUrl"), user);
|
||||
|
||||
return new ResponseEntity<>(ecr.save(toSave), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/externalcurriculum/{inscReqId}")
|
||||
public ResponseEntity<ArrayList<ExternalCurriculum>> getExternalCurrListByInscrReq(@PathVariable long inscReqId){
|
||||
InscriptionRequest ir = inscriptionRepository.findById(inscReqId);
|
||||
|
||||
ArrayList<ExternalCurriculum> toReturn = ecr.getExternalCurriculumByInscriptionRequest(ir);
|
||||
return new ResponseEntity<>(toReturn, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/externalcurriculumbyuser/{userId}")
|
||||
public ResponseEntity<ArrayList<ExternalCurriculum>> getExternalCurrByUser(@PathVariable long userId){
|
||||
User user = userRepository.findById(userId);
|
||||
|
||||
ArrayList<ExternalCurriculum> toReturn = ecr.getExternalCurriculumByUser(user);
|
||||
return new ResponseEntity<>(toReturn, HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
package ovh.herisson.Clyde.EndPoints.Inscription;
|
||||
|
||||
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.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.Inscription.InscriptionService;
|
||||
import ovh.herisson.Clyde.Services.ProtectionService;
|
||||
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.RequestState;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
public class InscriptionController {
|
||||
|
||||
|
||||
private final InscriptionService inscriptionServ;
|
||||
private final AuthenticatorService authServ;
|
||||
private final CurriculumRepository curriculumRepository;
|
||||
public InscriptionController(InscriptionService inscriptionServ, AuthenticatorService authServ, CurriculumRepository curriculumRepository){
|
||||
this.inscriptionServ = inscriptionServ;
|
||||
this.authServ = authServ;
|
||||
this.curriculumRepository = curriculumRepository;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/requests/register")
|
||||
public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService, Role.Teacher},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
Iterable<InscriptionRequest> inscriptionRequests = inscriptionServ.getAll();
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.requestsWithoutPasswords(inscriptionRequests), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/request/register/{id}")
|
||||
public ResponseEntity<Map<String,Object>> getById(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService, Role.Teacher},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
InscriptionRequest foundInscriptionRequest = inscriptionServ.getById(id);
|
||||
|
||||
if (foundInscriptionRequest == null)
|
||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.requestWithoutPassword(foundInscriptionRequest), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PatchMapping("/request/register/{id}")
|
||||
public ResponseEntity<InscriptionRequest> changeRequestState(@PathVariable long id,
|
||||
@RequestHeader("Authorization") String token,
|
||||
@RequestBody RequestState state)
|
||||
{
|
||||
if (authServ.isNotIn(new Role[]{Role.InscriptionService,Role.Admin},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
if (!inscriptionServ.modifyState(id, state))
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
@DeleteMapping("/request/register/{id}")
|
||||
public ResponseEntity<String > deleteRequest(@RequestHeader("Authorization") String token, @PathVariable Long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService}, token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
InscriptionRequest toDelete = inscriptionServ.getById(id);
|
||||
|
||||
if (toDelete == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
inscriptionServ.delete(toDelete);
|
||||
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);
|
||||
|
||||
//If the request is already accepted we just return ok (otherwise we would duplicate the procedure below)
|
||||
if (toEdit.getEquivalenceState() == RequestState.Accepted){
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@PatchMapping("/request/registerequivimpose/{id}/{cursusid}")
|
||||
public ResponseEntity<Object> editRegisterEquiv(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable long cursusid){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher}, token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
InscriptionRequest toEdit = inscriptionServ.getById(id);
|
||||
|
||||
//If the request is already accepted we just return ok (otherwise we would duplicate the procedure below)
|
||||
if (toEdit.getEquivalenceState() == RequestState.Accepted){
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
//We impose a curriculum
|
||||
Curriculum curriculum = curriculumRepository.findById(cursusid);
|
||||
|
||||
toEdit.setCurriculumId(curriculum.getCurriculumId());
|
||||
toEdit.setEquivalenceState(RequestState.Accepted);
|
||||
|
||||
inscriptionServ.save(toEdit);
|
||||
|
||||
if (toEdit.getState() == RequestState.Accepted && (toEdit.getEquivalenceState() == RequestState.Accepted || toEdit.getEquivalenceState() == RequestState.Unrequired))
|
||||
{
|
||||
inscriptionServ.createUser(toEdit);
|
||||
}
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package ovh.herisson.Clyde.EndPoints.Inscription;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.MinervalRepository;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.Minerval;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
public class MinervalController {
|
||||
private final AuthenticatorService authServ;
|
||||
private final MinervalRepository mr;
|
||||
|
||||
public MinervalController(AuthenticatorService authServ, MinervalRepository mr) {
|
||||
this.authServ = authServ;
|
||||
this.mr = mr;
|
||||
}
|
||||
|
||||
//A new minerval entry is posted when the inscription service accept a registration request
|
||||
@PostMapping("/minerval/{studentRegNo}")
|
||||
public ResponseEntity<Object> postMinerval(@RequestHeader("Authorization") String token, @PathVariable long studentRegNo){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
Calendar c = new GregorianCalendar();
|
||||
|
||||
mr.save(new Minerval(studentRegNo, 0, 835, c.get(Calendar.YEAR)));
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/minerval/{studentRegNo}")
|
||||
public ResponseEntity<Minerval> getCurrentMinervalbyRegNo(@PathVariable long studentRegNo){
|
||||
ArrayList<Minerval> mlist = mr.getMinervalsByStudentRegNoOrderByYearDesc(studentRegNo);
|
||||
|
||||
//The list is ordered by year in descending order then the index 0 contains the actual minerval (for this year)
|
||||
Minerval m = mlist.get(0);
|
||||
return new ResponseEntity<>(m, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PatchMapping("/minerval")
|
||||
public ResponseEntity<Object> updateMinerval(@RequestBody Minerval updatedMinerval){
|
||||
Minerval minerval = mr.findById(updatedMinerval.getId());
|
||||
|
||||
minerval.setPaidAmount(updatedMinerval.getPaidAmount());
|
||||
minerval.setToPay(updatedMinerval.getToPay());
|
||||
mr.save(minerval);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package ovh.herisson.Clyde.EndPoints.Inscription;
|
||||
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.PaymentRepository;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.Payment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
public class PaymentController {
|
||||
|
||||
private final PaymentRepository paymentRepository;
|
||||
|
||||
public PaymentController(PaymentRepository paymentRepository){
|
||||
this.paymentRepository = paymentRepository;
|
||||
}
|
||||
|
||||
//Post a payment record
|
||||
@PostMapping("/payment")
|
||||
public ResponseEntity<Object> postPayment(@RequestBody Payment payment){
|
||||
paymentRepository.save(payment);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
//Get all payment records of a student
|
||||
@GetMapping("/payment/{studentRegNo}")
|
||||
public ResponseEntity<ArrayList<Payment>> getPaymentsByUser(@PathVariable long studentRegNo){
|
||||
ArrayList<Payment> toReturn = paymentRepository.getPaymentsByStudentRegNo(studentRegNo);
|
||||
return new ResponseEntity<>(toReturn, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/payment")
|
||||
public ResponseEntity<ArrayList<Payment>> getAllPayments(){
|
||||
ArrayList<Payment> toReturn = new ArrayList<Payment>();
|
||||
|
||||
|
||||
paymentRepository.findAll().forEach(toReturn::add);
|
||||
return new ResponseEntity<>(toReturn, HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,370 @@
|
||||
package ovh.herisson.Clyde.EndPoints.Inscription;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
||||
import ovh.herisson.Clyde.Repositories.CurriculumRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.*;
|
||||
import ovh.herisson.Clyde.Repositories.UserCurriculumRepository;
|
||||
import ovh.herisson.Clyde.Repositories.UserRepository;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.TokenService;
|
||||
import ovh.herisson.Clyde.Services.UserService;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
public class RequestsController {
|
||||
|
||||
public final TokenService tokenService;
|
||||
public final ExemptionsRequestRepository err;
|
||||
public final ScholarshipRequestRepository srr;
|
||||
public final UserRepository userRepository;
|
||||
public final AuthenticatorService authServ;
|
||||
public final UnregisterRequestRepository unregisterRequestRepository;
|
||||
public final CourseRepository courseRepository;
|
||||
public final UserService userService;
|
||||
public final UserCurriculumRepository userCurriculumRepository;
|
||||
public final CurriculumRepository curriculumRepository;
|
||||
public final MinervalRepository minervalRepository;
|
||||
public final ChangeCurriculumRequestRepository changeCurriculumRequestRepository;
|
||||
|
||||
public RequestsController(TokenService tokenService, ExemptionsRequestRepository err, ScholarshipRequestRepository srr, UserRepository userRepository, AuthenticatorService authServ, UnregisterRequestRepository unregisterRequestRepository, CourseRepository courseRepository, UserService userService, UserCurriculumRepository userCurriculumRepository, CurriculumRepository curriculumRepository, MinervalRepository minervalRepository, ChangeCurriculumRequestRepository changeCurriculumRequestRepository) {
|
||||
this.tokenService = tokenService;
|
||||
this.err = err;
|
||||
this.srr = srr;
|
||||
this.userRepository = userRepository;
|
||||
this.authServ = authServ;
|
||||
this.unregisterRequestRepository = unregisterRequestRepository;
|
||||
this.courseRepository = courseRepository;
|
||||
this.userService = userService;
|
||||
this.userCurriculumRepository = userCurriculumRepository;
|
||||
this.curriculumRepository = curriculumRepository;
|
||||
this.minervalRepository = minervalRepository;
|
||||
this.changeCurriculumRequestRepository = changeCurriculumRequestRepository;
|
||||
}
|
||||
|
||||
@PostMapping(value="/exemptionreq")
|
||||
public ResponseEntity<String> createExemptionReq(@RequestBody Map<String, Object> exemptionsRequestInfo){
|
||||
User user = userRepository.findById((Integer) exemptionsRequestInfo.get("userRegNo"));
|
||||
Course course = courseRepository.findById((Integer) exemptionsRequestInfo.get("courseId"));
|
||||
|
||||
ExemptionsRequest exemptionsRequest = new ExemptionsRequest(user, course, (String) exemptionsRequestInfo.get("justifDocument"), RequestState.Pending, new Date());
|
||||
|
||||
err.save(exemptionsRequest);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PostMapping(value="/scholarshipreq")
|
||||
public ResponseEntity<String> createScholarshipReq(@RequestBody Map<String, Object> scholarshipRequestInfo){
|
||||
User user = userRepository.findById((Integer)scholarshipRequestInfo.get("userId"));
|
||||
ScholarshipRequest toCreate = new ScholarshipRequest(user, RequestState.Pending, 0, new Date(), (String) scholarshipRequestInfo.get("taxDocUrl"), (String) scholarshipRequestInfo.get("residencyDocUrl"));
|
||||
|
||||
srr.save(toCreate);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
//Get all the exemptions Request
|
||||
@GetMapping(value = "/exemptionsreq")
|
||||
public ResponseEntity<ArrayList<ExemptionsRequest>> getAllExemptionsRequests(@RequestHeader("Authorization") String token){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService, Role.Teacher},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
ArrayList<ExemptionsRequest> toReturn = new ArrayList<>();
|
||||
|
||||
err.findAll().forEach(toReturn::add);
|
||||
|
||||
return new ResponseEntity<>(toReturn, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/exemptionsreq/{id}")
|
||||
public ResponseEntity<ExemptionsRequest> getExemptionRequestbyId(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher,Role.InscriptionService},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
ExemptionsRequest exemptionsRequest = err.findById(id);
|
||||
|
||||
return new ResponseEntity<>(exemptionsRequest, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PatchMapping(value = "/exemptionsreq/{id}/{newstate}")
|
||||
public ResponseEntity<String> changeExemptionReqState(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newstate){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
ExemptionsRequest exemptionsRequest = err.findById(id);
|
||||
|
||||
if (exemptionsRequest.getState() == RequestState.Accepted){
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
exemptionsRequest.setState(newstate);
|
||||
err.save(exemptionsRequest);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
//Get all the scholarships requests
|
||||
@GetMapping(value = "/scholarshipreq")
|
||||
public ResponseEntity<ArrayList<ScholarshipRequest>> getAllScholarshipRequests(@RequestHeader("Authorization") String token){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
ArrayList<ScholarshipRequest> toReturn = new ArrayList<>();
|
||||
|
||||
srr.findAll().forEach(toReturn::add);
|
||||
|
||||
return new ResponseEntity<>(toReturn, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/unregister")
|
||||
public ResponseEntity<String> postUnregReq(@RequestBody Map<String,Object> uninscr){
|
||||
User u = userRepository.findById((int) uninscr.get("userId"));
|
||||
Curriculum c;
|
||||
|
||||
if (uninscr.get("curriculumId") == null){
|
||||
c = null;
|
||||
}else{
|
||||
c = curriculumRepository.findById((Integer) uninscr.get("curriculumId"));
|
||||
}
|
||||
|
||||
UnregisterRequest ur = new UnregisterRequest(RequestState.Pending, (String) uninscr.get("reason"), new Date(), u.getRegNo(), u.getFirstName(), u.getLastName(), u.getEmail(), c);
|
||||
unregisterRequestRepository.save(ur);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PatchMapping(value = "/scholarshipreq/")
|
||||
public ResponseEntity<String> editScholReq(@RequestHeader("Authorization") String token, @RequestBody Map<String,Object> infos){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
ScholarshipRequest scholarshipRequest = srr.findById((Integer) infos.get("id"));
|
||||
|
||||
User u = scholarshipRequest.getUser();
|
||||
|
||||
//If the request is already accepted we just return ok (otherwise we would duplicate the procedure below)
|
||||
if (scholarshipRequest.getState() == RequestState.Accepted){
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
if (infos.get("state").equals("Accepted")){
|
||||
scholarshipRequest.setState(RequestState.Accepted);
|
||||
scholarshipRequest.setAmount((int) infos.get("amount"));
|
||||
|
||||
//We then deduce then amount from the minerval
|
||||
ArrayList<Minerval> minerval = minervalRepository.getMinervalsByStudentRegNoOrderByYearDesc(u.getRegNo());
|
||||
minerval.get(0).setPaidAmount(minerval.get(0).getPaidAmount() + scholarshipRequest.getAmount());
|
||||
minerval.get(0).setToPay(minerval.get(0).getToPay() - scholarshipRequest.getAmount());
|
||||
minervalRepository.save(minerval.get(0));
|
||||
}else{
|
||||
scholarshipRequest.setState(RequestState.Refused);
|
||||
}
|
||||
|
||||
srr.save(scholarshipRequest);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/scholarshipreq/{id}")
|
||||
public ResponseEntity<ScholarshipRequest> getScholReqbyId(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin, Role.InscriptionService},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
ScholarshipRequest toReturn = srr.findById(id);
|
||||
return new ResponseEntity<>(toReturn, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/unregister")
|
||||
public ResponseEntity<ArrayList<UnregisterRequest>> getAllUnregReq(@RequestHeader("Authorization") String token){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
ArrayList<UnregisterRequest> toReturn = new ArrayList<>();
|
||||
unregisterRequestRepository.findAll().forEach(toReturn::add);
|
||||
return new ResponseEntity<>(toReturn, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/unregister/{id}")
|
||||
public ResponseEntity<UnregisterRequest> getUnregbyId(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
UnregisterRequest unregisterRequest = unregisterRequestRepository.findById(id);
|
||||
return new ResponseEntity<>(unregisterRequest, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PatchMapping(value = "/unregister/{id}/{newstate}")
|
||||
public ResponseEntity<String> pathUnregReq(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newstate){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
UnregisterRequest unregisterRequest = unregisterRequestRepository.findById(id);
|
||||
User u = userRepository.findById(unregisterRequest.getRegNo());
|
||||
|
||||
//If the request is already accepted we just return ok (otherwise we would duplicate the procedure below)
|
||||
if (unregisterRequest.getState() == RequestState.Accepted){
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
unregisterRequest.setState(newstate);
|
||||
unregisterRequestRepository.save(unregisterRequest);
|
||||
if (newstate == RequestState.Accepted){
|
||||
if (unregisterRequest.getCurriculum() == null){
|
||||
ArrayList<UserCurriculum> userCurricula = userCurriculumRepository.findByUserOrderByCurriculum(u);
|
||||
for (int i = 0; i < userCurricula.size(); i++){
|
||||
userCurricula.get(i).setActual(false);
|
||||
}
|
||||
userCurriculumRepository.saveAll(userCurricula);
|
||||
}else{
|
||||
//This usercurriculum will contain the usercurriculum to set false
|
||||
UserCurriculum userCurriculum = userCurriculumRepository.findByUserAndCurriculumAndActual(u, unregisterRequest.getCurriculum(), true);
|
||||
userCurriculum.setActual(false);
|
||||
userCurriculumRepository.save(userCurriculum);
|
||||
}
|
||||
}
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
//We look in the usercursus table if the student has already the previous year of a curriculum
|
||||
public boolean studentHasPrevYear(Curriculum curriculum, User user){
|
||||
ArrayList<UserCurriculum> userCurrList = userCurriculumRepository.findByUserOrderByCurriculum(user);
|
||||
for (int i = 0; i < userCurrList.size(); i++){
|
||||
if (userCurrList.get(i).getCurriculum().getOption().equals(curriculum.getOption()) && userCurrList.get(i).getCurriculum().getYear() == curriculum.getYear()-1){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@PostMapping("/changecurriculumreq")
|
||||
public ResponseEntity<String> addChangeCurrReq(@RequestBody Map<String,Object> reqInfos){
|
||||
User user = userRepository.findById((Integer) reqInfos.get("userId"));
|
||||
|
||||
Curriculum actualCurriculum;
|
||||
|
||||
//If null then it means we are in a supplementary cursus case
|
||||
if (reqInfos.get("actualcursus") == null){
|
||||
actualCurriculum = null;
|
||||
}else{
|
||||
actualCurriculum = curriculumRepository.findById((Integer) reqInfos.get("actualcursus"));
|
||||
}
|
||||
|
||||
Curriculum destinationCurriculum = curriculumRepository.findById((Integer) reqInfos.get("newcursus"));
|
||||
|
||||
ChangeCurriculumRequest changeCurriculumRequest = new ChangeCurriculumRequest(user, actualCurriculum, destinationCurriculum, new Date(), RequestState.Pending, RequestState.Unrequired);
|
||||
|
||||
//Si l'année du cursus est plus grande que 1 et que l'étudiant n'a pas dans sa liste de cursus l'année d'en dessous alors on demande l'accord du prof
|
||||
if (destinationCurriculum.getYear() > 1 && !studentHasPrevYear(destinationCurriculum, user)){
|
||||
changeCurriculumRequest.setTeacherApprovalState(RequestState.Pending);
|
||||
}
|
||||
changeCurriculumRequestRepository.save(changeCurriculumRequest);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/changecurriculumreq")
|
||||
public ResponseEntity<ArrayList <ChangeCurriculumRequest>> getAllChangeCurrReq(@RequestHeader("Authorization") String token){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService, Role.Teacher},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
ArrayList<ChangeCurriculumRequest> toReturn = new ArrayList<>();
|
||||
|
||||
changeCurriculumRequestRepository.findAll().forEach(toReturn::add);
|
||||
|
||||
return new ResponseEntity<>(toReturn, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/changecurriculumreq/{id}")
|
||||
public ResponseEntity<ChangeCurriculumRequest> getCCrbyId(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher,Role.InscriptionService},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
ChangeCurriculumRequest toReturn = changeCurriculumRequestRepository.findById(id);
|
||||
return new ResponseEntity<>(toReturn, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PatchMapping("/changecurriculumreq/{id}/{newState}")
|
||||
public ResponseEntity<String> editCCReq(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newState){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
ChangeCurriculumRequest toEdit = changeCurriculumRequestRepository.findById(id);
|
||||
|
||||
//If the request is already accepted we just return ok (otherwise we would duplicate the procedure below)
|
||||
if (toEdit.getState() == RequestState.Accepted){
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
toEdit.setState(newState);
|
||||
changeCurriculumRequestRepository.save(toEdit);
|
||||
if (newState == RequestState.Accepted && (toEdit.getTeacherApprovalState() == RequestState.Accepted || toEdit.getTeacherApprovalState() == RequestState.Unrequired)){
|
||||
//If actual curriculum is not null then we need to set that the user doesn't follow it anymore
|
||||
acceptProcedure(toEdit);
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PatchMapping("/changecurriculumreqteacher/{id}/{newteacherstate}")
|
||||
public ResponseEntity<String> editCCReqTeacherState(@RequestHeader("Authorization") String token, @PathVariable long id, @PathVariable RequestState newteacherstate){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
ChangeCurriculumRequest toEdit = changeCurriculumRequestRepository.findById(id);
|
||||
|
||||
//If the request is already accepted we just return ok (otherwise we would duplicate the procedure below)
|
||||
if (toEdit.getTeacherApprovalState() == RequestState.Accepted){
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
toEdit.setTeacherApprovalState(newteacherstate);
|
||||
changeCurriculumRequestRepository.save(toEdit);
|
||||
|
||||
if (newteacherstate == RequestState.Accepted && toEdit.getState() == RequestState.Accepted){
|
||||
//If actual curriculum is not null then we need to set that the user doesn't follow it anymore
|
||||
acceptProcedure(toEdit);
|
||||
}
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
private void acceptProcedure(ChangeCurriculumRequest toEdit) {
|
||||
User u = toEdit.getUser();
|
||||
if (toEdit.getActualCurriculum() != null){
|
||||
ArrayList<UserCurriculum> listcurr = userCurriculumRepository.findByUserOrderByCurriculum(u);
|
||||
|
||||
for (int i = 0; i < listcurr.size(); i++){
|
||||
if (listcurr.get(i).getCurriculum() == toEdit.getActualCurriculum()){
|
||||
listcurr.get(i).setActual(false);
|
||||
}
|
||||
}
|
||||
|
||||
userCurriculumRepository.saveAll(listcurr);
|
||||
}
|
||||
|
||||
Calendar c = Calendar.getInstance();
|
||||
UserCurriculum userCurriculum = new UserCurriculum(u, toEdit.getDestinationCurriculum(), c.get(Calendar.YEAR), true);
|
||||
userCurriculumRepository.save(userCurriculum);
|
||||
}
|
||||
|
||||
@GetMapping("/exemptionreq/{userId}")
|
||||
public ResponseEntity<ArrayList<ExemptionsRequest>> getExReqByuser(@RequestHeader("Authorization") String token, @PathVariable long userId){
|
||||
User currentUser = tokenService.getUserFromToken(token);
|
||||
|
||||
//Only admin, teacher, secretary and the student himself can access a student's data here
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher, Role.Secretary},token) && currentUser.getRegNo() != userId)
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
User u = userRepository.findById(userId);
|
||||
|
||||
ArrayList<ExemptionsRequest> exList = err.findByUser(u);
|
||||
return new ResponseEntity<>(exList, HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.InscriptionService;
|
||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.RequestState;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
|
||||
public class InscriptionController {
|
||||
|
||||
|
||||
private final InscriptionService inscriptionServ;
|
||||
private final AuthenticatorService authServ;
|
||||
|
||||
public InscriptionController(InscriptionService inscriptionServ, AuthenticatorService authServ){
|
||||
this.inscriptionServ = inscriptionServ;
|
||||
this.authServ = authServ;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/requests/register")
|
||||
public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
|
||||
|
||||
if (!isSecretaryOrAdmin(token)){return new UnauthorizedResponse<>(null);}
|
||||
|
||||
Iterable<InscriptionRequest> inscriptionRequests = inscriptionServ.getAll();
|
||||
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
||||
|
||||
for (InscriptionRequest i:inscriptionRequests){
|
||||
toReturn.add(requestWithoutPassword(i));
|
||||
}
|
||||
|
||||
return new ResponseEntity<>(toReturn, HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/request/register/{id}")
|
||||
public ResponseEntity<Map<String,Object>> getById(@PathVariable long id){
|
||||
InscriptionRequest inscriptionRequest = inscriptionServ.getById(id);
|
||||
if (inscriptionRequest == null) {return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);}
|
||||
|
||||
return new ResponseEntity<>(requestWithoutPassword(inscriptionRequest), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("request/user/{id}")
|
||||
public ResponseEntity<InscriptionRequest> getUserInscriptionRequest(@PathVariable long id, @RequestHeader("Authorize") String token){
|
||||
//todo return l'inscriptionRequest ACTUELLE du user (check si le poster est bien le même que id target ou secretariat)
|
||||
return null;
|
||||
}
|
||||
|
||||
@PatchMapping("/request/register/{id}")
|
||||
public ResponseEntity<InscriptionRequest> changeRequestState(@PathVariable long id,
|
||||
@RequestHeader("Authorize") String token,
|
||||
@RequestBody RequestState requestState)
|
||||
{
|
||||
if (!isSecretaryOrAdmin(token)) return new UnauthorizedResponse<>(null);
|
||||
inscriptionServ.modifyState(id, requestState);
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<String,Object> requestWithoutPassword(InscriptionRequest inscriptionRequest) {
|
||||
Map<String, Object> toReturn = new HashMap<>();
|
||||
|
||||
toReturn.put("id", inscriptionRequest.getId());
|
||||
toReturn.put("firstName", inscriptionRequest.getFirstName());
|
||||
toReturn.put("lastName", inscriptionRequest.getLastName());
|
||||
toReturn.put("address", inscriptionRequest.getAddress());
|
||||
toReturn.put("birthDate", inscriptionRequest.getBirthDate());
|
||||
toReturn.put("country", inscriptionRequest.getCountry());
|
||||
toReturn.put("cursus", inscriptionRequest.getCursus());
|
||||
toReturn.put("profilePictureUrl", inscriptionRequest.getProfilePicture());
|
||||
toReturn.put("state", inscriptionRequest.getState());
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
private boolean isSecretaryOrAdmin(String authorization){
|
||||
if (authorization ==null)
|
||||
return false;
|
||||
|
||||
User poster = authServ.getUserFromToken(authorization);
|
||||
if (poster == null) return false;
|
||||
|
||||
return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin;
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
/******************************************************
|
||||
* @file LessonController.java
|
||||
* @author William Karpinski
|
||||
* @scope Extension Horaire
|
||||
*
|
||||
* Controller of Lessons API
|
||||
******************************************************/
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.LessonService;
|
||||
import ovh.herisson.Clyde.Services.ProtectionService;
|
||||
import ovh.herisson.Clyde.Services.ScheduleLessonService;
|
||||
import ovh.herisson.Clyde.Tables.Lesson;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
public class LessonController {
|
||||
private final LessonService lessonServ;
|
||||
|
||||
private final ScheduleLessonService scheduleLessonServ;
|
||||
private final AuthenticatorService authServ;
|
||||
|
||||
public LessonController(LessonService lessonServ, ScheduleLessonService scheduleLessonService, AuthenticatorService authServ) {
|
||||
this.lessonServ = lessonServ;
|
||||
this.scheduleLessonServ = scheduleLessonService;
|
||||
this.authServ = authServ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a lesson via its id
|
||||
*/
|
||||
@GetMapping("/lesson/{id}")
|
||||
public ResponseEntity<HashMap<String,Object>> getLesson(@PathVariable long id){
|
||||
Lesson lesson = lessonServ.findById(id);
|
||||
|
||||
if(lesson == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.lessonWithoutPassword(lesson),HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the lessons
|
||||
*/
|
||||
@GetMapping("/lessons")
|
||||
public ResponseEntity<Iterable<HashMap<String,Object>>> getAllLessons(@RequestHeader("Authorization") String token){
|
||||
if(authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
return new ResponseEntity<>(ProtectionService.lessonsWithoutPassword(lessonServ.findAll()),HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the lessons of a teacher's courses
|
||||
*/
|
||||
@GetMapping("/lessons/owned")
|
||||
public ResponseEntity<Iterable<HashMap<String,Object>>> getOwnedLessons(@RequestHeader("Authorization") String token){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token)){
|
||||
return new UnauthorizedResponse<>(null);}
|
||||
return new ResponseEntity<>(ProtectionService.lessonsWithoutPassword(lessonServ.findAllOwnedLesson(authServ.getUserFromToken(token))),HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
⋅* Return all the lessons of a student
|
||||
*/
|
||||
@GetMapping("/lessons/OwnCurriculum")
|
||||
public ResponseEntity<Iterable<HashMap<String,Object>>> getOnesLessons(@RequestHeader("Authorization") String token){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Student},token)){
|
||||
return new UnauthorizedResponse<>(null);}
|
||||
return new ResponseEntity<>(ProtectionService.lessonsWithoutPassword(lessonServ.findOnesLessons(authServ.getUserFromToken(token))),HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new lesson
|
||||
*/
|
||||
@PostMapping("/lesson")
|
||||
public ResponseEntity<HashMap<String, Object>> postLesson(@RequestHeader("Authorization") String token,
|
||||
@RequestBody Map<String, Object> lessonInfos){
|
||||
if(authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
|
||||
Lesson lesson = lessonServ.createLesson(lessonInfos);
|
||||
Lesson createdLesson = lessonServ.save(lesson);
|
||||
scheduleLessonServ.saveToAllSchedule(lesson);
|
||||
|
||||
if(createdLesson==null)
|
||||
return new ResponseEntity<>(null,HttpStatus.BAD_REQUEST);
|
||||
return new ResponseEntity<>(ProtectionService.lessonWithoutPassword(createdLesson), HttpStatus.OK);
|
||||
}
|
||||
/**
|
||||
* Modify a lesson
|
||||
*/
|
||||
@PatchMapping("/lesson/{id}")
|
||||
public ResponseEntity<Lesson> patchLesson(@RequestHeader("Authorization") String token,
|
||||
@RequestBody Map<String, Object> updates,
|
||||
@PathVariable long id){
|
||||
if(authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
if(!lessonServ.modifyData(id, updates)){
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
/**
|
||||
* Delete a lesson
|
||||
*/
|
||||
@DeleteMapping("lesson/{id}")
|
||||
public ResponseEntity<String> deleteLesson(@RequestHeader("Authorization") String token,
|
||||
@PathVariable Long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
Lesson toDelete = lessonServ.findById(id);
|
||||
if(toDelete == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
lessonServ.delete(toDelete);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,149 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
/******************************************************
|
||||
* @file LessonRequestsController.java
|
||||
* @author William Karpinski
|
||||
* @scope Extension Horaire
|
||||
*
|
||||
* Controller of lesson requests API
|
||||
******************************************************/
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.*;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
public class LessonRequestsController {
|
||||
private final LessonRequestService lessonRequestServ;
|
||||
private final AuthenticatorService authServ;
|
||||
private final UserService userServ;
|
||||
|
||||
private final LessonService lessonServ;
|
||||
public LessonRequestsController(LessonRequestService lessonRequestServer, AuthenticatorService authServ, UserService userServ, LessonService lessonServ) {
|
||||
this.lessonRequestServ = lessonRequestServer;
|
||||
this.authServ = authServ;
|
||||
this.userServ = userServ;
|
||||
this.lessonServ = lessonServ;
|
||||
}
|
||||
/**
|
||||
* Return a lesson request via its id
|
||||
*/
|
||||
@GetMapping("/requests/lessonRequest/{id}")
|
||||
public ResponseEntity<Map<String,Object>> getById(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
LessonChangesRequest lessonRequest= lessonRequestServ.findById(id);
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.lessonRequestWithoutPassword(lessonRequest), HttpStatus.OK);
|
||||
}
|
||||
/**
|
||||
* return all the requests made by a user
|
||||
*/
|
||||
@GetMapping("/requests/lessonRequests/owned")
|
||||
public ResponseEntity<Iterable<Map<String, Object>>> getOwnedRequests(@RequestHeader("Authorization") String token){
|
||||
if(authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
User user = authServ.getUserFromToken(token);
|
||||
Iterable<LessonChangesRequest> lessonChangesRequests = lessonRequestServ.findOwnRequests(user);
|
||||
return new ResponseEntity<>(ProtectionService.lessonRequestsWithoutPassword(lessonChangesRequests),HttpStatus.OK);
|
||||
|
||||
}
|
||||
/**
|
||||
* Return all the lesson requests
|
||||
*/
|
||||
@GetMapping("/requests/lessonRequests")
|
||||
public ResponseEntity<Iterable<Map<String,Object>>> getAllRequests(@RequestHeader("Authorization") String token){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
Iterable<LessonChangesRequest> lessonRequests= lessonRequestServ.getAll();
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.lessonRequestsWithoutPassword(lessonRequests), HttpStatus.OK);
|
||||
}
|
||||
/**
|
||||
* Post a lesson request
|
||||
*/
|
||||
@PostMapping("/requests/lessonRequest")
|
||||
public ResponseEntity<Map<String, Object>> makeRequest(@RequestHeader("Authorization") String token, @RequestBody Map<String,Object> lessonRequestInfos){
|
||||
if(authServ.isNotIn(new Role[]{Role.Admin,Role.Teacher},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
LessonChangesRequest lessonChangesRequest = lessonRequestServ.createLessonRequest(lessonRequestInfos);
|
||||
LessonChangesRequest createdRequest = lessonRequestServ.save(lessonChangesRequest);
|
||||
if(createdRequest == null)
|
||||
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||
return new ResponseEntity<>(ProtectionService.lessonRequestWithoutPassword(lessonChangesRequest),HttpStatus.OK);
|
||||
}
|
||||
/**
|
||||
* Modify a lesson Request
|
||||
*/
|
||||
@PatchMapping("/requests/lessonRequest/{id}")
|
||||
public ResponseEntity<LessonChangesRequest> changeRequestState(@PathVariable long id,
|
||||
@RequestHeader("Authorization") String token,
|
||||
@RequestBody Map<String , Object> infos){
|
||||
if(authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
LessonChangesRequest lessonRequest = lessonRequestServ.findById(id);
|
||||
String local = "";
|
||||
RequestState state = null;
|
||||
for (Map.Entry<String, Object> entry : infos.entrySet()) {
|
||||
switch (entry.getKey()) {
|
||||
case "local":
|
||||
local = (String) entry.getValue();
|
||||
break;
|
||||
case "state":
|
||||
state = RequestState.valueOf((String)entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (state == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
if(lessonRequest.getRequestType() == 0 ) {
|
||||
if (!lessonRequestServ.modifyCreateRequestState(lessonRequest, state, local))
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
userServ.Notify(lessonRequest.getUser(), new Notification("Request took in charge","Request"+ state + ":" + lessonRequest.getCourse().getTitle(), "#/manage-owned-lessons"));
|
||||
}
|
||||
|
||||
else if(lessonRequest.getRequestType() == 1){
|
||||
infos.put("lessonStart", lessonRequest.getLessonStart());
|
||||
infos.put("lessonEnd", lessonRequest.getLessonEnd());
|
||||
infos.put("lessonType",lessonRequest.getLessonType());
|
||||
if(!lessonRequestServ.modifyChangeRequestState(infos,lessonRequest.getLessonId(),state))
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
lessonRequest.setState(state);
|
||||
userServ.Notify(lessonRequest.getUser(), new Notification("Request took in charge","Request"+ state + ":" + lessonServ.findById(lessonRequest.getLessonId()).getCourse().getTitle(), "#/manage-owned-lessons"));
|
||||
|
||||
}
|
||||
|
||||
else{
|
||||
userServ.Notify(lessonRequest.getUser(), new Notification("Request took in charge","Request"+ state + ":" + lessonServ.findById(lessonRequest.getLessonId()).getCourse().getTitle(), "#/manage-owned-lessons"));
|
||||
lessonRequestServ.modifyDeleteRequest(lessonRequest, state);
|
||||
lessonRequest.setState(state);
|
||||
}
|
||||
lessonRequestServ.save(lessonRequest);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a lesson request
|
||||
*/
|
||||
@DeleteMapping("/requests/lessonRequest/{id}")
|
||||
public ResponseEntity<String> deleteRequest(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
if(authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.Teacher},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
LessonChangesRequest lessonChangesRequest = lessonRequestServ.findById(id);
|
||||
if (lessonChangesRequest == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
lessonRequestServ.delete(lessonChangesRequest);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -1,20 +1,26 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
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.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Services.ProtectionService;
|
||||
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.RequestState;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@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;
|
||||
@ -27,8 +33,9 @@ public class LoginController {
|
||||
}
|
||||
}
|
||||
|
||||
public LoginController(AuthenticatorService authServ){
|
||||
public LoginController(AuthenticatorService authServ, CurriculumRepository curriculumRepository){
|
||||
this.authServ = authServ;
|
||||
this.curriculumRepository = curriculumRepository;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/login")
|
||||
@ -44,9 +51,20 @@ public class LoginController {
|
||||
return ResponseEntity.ok().headers(responseHeaders).build();
|
||||
}
|
||||
|
||||
@PostMapping("/request/register")
|
||||
public ResponseEntity<String> register(@RequestBody InscriptionRequest inscriptionRequest){
|
||||
authServ.register(inscriptionRequest);
|
||||
return new ResponseEntity<>("Is OK", HttpStatus.OK);
|
||||
@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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +1,73 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Repositories.TokenRepository;
|
||||
import ovh.herisson.Clyde.Repositories.UserRepository;
|
||||
import ovh.herisson.Clyde.Repositories.*;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.MinervalRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.ScholarshipRequestRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.UnregisterRequestRepository;
|
||||
import ovh.herisson.Clyde.Services.*;
|
||||
import ovh.herisson.Clyde.Services.ScientificPublications.ResearchesService;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Access;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.PaperType;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
import ovh.herisson.Clyde.Services.Inscription.InscriptionService;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.ExternalCurriculum;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.Minerval;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.ScholarshipRequest;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
|
||||
public class MockController {
|
||||
private final BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
|
||||
public final UserService userService;
|
||||
public final UserRepository userRepo;
|
||||
public final TokenRepository tokenRepo;
|
||||
public final TokenService tokenService;
|
||||
public final CursusCourseService cursusCourseService;
|
||||
public final CursusService cursusService;
|
||||
public final CurriculumCourseService CurriculumCourseService;
|
||||
public final CurriculumService curriculumService;
|
||||
public final CourseService courseService;
|
||||
public final ExternalCurriculumRepository externalCurriculumRepository;
|
||||
public final InscriptionService inscriptionService;
|
||||
|
||||
public final LessonService lessonService;
|
||||
public final ScheduleService scheduleService;
|
||||
public final ScheduleLessonService scheduleLessonService;
|
||||
|
||||
public final LessonRequestService lessonRequestService;
|
||||
ArrayList<User> mockUsers;
|
||||
|
||||
|
||||
public MockController(UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CursusCourseService cursusCourseService, CursusService cursusService, CourseService courseService){
|
||||
public static boolean isMocked = false;
|
||||
public final ResearchesService researchesService;
|
||||
public final UserCurriculumRepository ucr;
|
||||
public final MinervalRepository minervalRepository;
|
||||
public final ScholarshipRequestRepository scholarshipRequestRepository;
|
||||
|
||||
public final UnregisterRequestRepository uninscriptionRequestRepository;
|
||||
public MockController(UserService userService, UserRepository userRepo, TokenRepository tokenRepo, TokenService tokenService, CurriculumCourseService CurriculumCourseService, CurriculumService curriculumService, CourseService courseService, ExternalCurriculumRepository externalCurriculumRepository, ResearchesService researchesService, InscriptionService inscriptionService, UserCurriculumRepository ucr, MinervalRepository minervalRepository, ScholarshipRequestRepository scholarshipRequestRepository, UnregisterRequestRepository unregisterRequestRepository, LessonService lessonService, ScheduleService scheduleService, ScheduleLessonService scheduleLessonService, LessonRequestService lessonRequestService){
|
||||
this.userService = userService;
|
||||
this.tokenRepo = tokenRepo;
|
||||
this.userRepo = userRepo;
|
||||
this.tokenService = tokenService;
|
||||
this.cursusCourseService = cursusCourseService;
|
||||
this.cursusService = cursusService;
|
||||
this.CurriculumCourseService = CurriculumCourseService;
|
||||
this.curriculumService = curriculumService;
|
||||
this.courseService = courseService;
|
||||
this.externalCurriculumRepository = externalCurriculumRepository;
|
||||
this.inscriptionService = inscriptionService;
|
||||
this.researchesService = researchesService;
|
||||
this.lessonService = lessonService;
|
||||
this.scheduleService = scheduleService;
|
||||
this.scheduleLessonService = scheduleLessonService;
|
||||
this.lessonRequestService = lessonRequestService;
|
||||
this.ucr = ucr;
|
||||
this.minervalRepository = minervalRepository;
|
||||
this.scholarshipRequestRepository = scholarshipRequestRepository;
|
||||
this.uninscriptionRequestRepository = unregisterRequestRepository;
|
||||
}
|
||||
|
||||
/** Saves an example of each user type by :
|
||||
@ -42,62 +77,163 @@ public class MockController {
|
||||
*/
|
||||
|
||||
@PostMapping("/mock")
|
||||
public void postMock(){
|
||||
public void postMock() {
|
||||
|
||||
if(!isMocked){
|
||||
// user part
|
||||
User herobrine = new User("brine","hero","admin@admin.com","behind","ShadowsLand",new Date(0), null,Role.Admin,"admin");
|
||||
User joe = new User("Piplo","Joe","student@student.com","roundabout","England",new Date(0), null,Role.Student,"student");
|
||||
User meh = new User("Polo","Marco","secretary@secretary.com","a Box","Monaco",new Date(0), null,Role.Secretary,"secretary");
|
||||
User joke = new User("Gaillard","Corentin","teacher@teacher.com","lab","faculty",new Date(0), null,Role.Teacher,"teacher");
|
||||
User jojo = new User("Bridoux","Justin","teacher2@teacher2.com","lab","faculty",new Date(0), null,Role.Teacher,"teacher");
|
||||
User lena = new User("Louille","Lena","inscriptionService@InscriptionService.com","no","yes",new Date(0), null,Role.InscriptionService,"inscriptionService");
|
||||
User popo = new User("Smith", "Paul", "paulsmith@gmail.com", "306 rue du poulet", "belgique", new Date(0), null, Role.Student, "jesuispaulleroi");
|
||||
mockUsers = new ArrayList<>(Arrays.asList(herobrine,joe,meh,joke,lena,jojo, popo));
|
||||
|
||||
userService.saveAll(mockUsers);
|
||||
|
||||
ExternalCurriculum externalCurriculum = new ExternalCurriculum(null, "HEH", "Bachelier en ingénieur", "completed", 2015, 2017, null, joe);
|
||||
externalCurriculumRepository.save(externalCurriculum);
|
||||
|
||||
Minerval minerval = new Minerval(joe.getRegNo(), 0, 852, 2023);
|
||||
minervalRepository.save(minerval);
|
||||
// Course / Curriculum part
|
||||
|
||||
Curriculum infoBab1 = new Curriculum(1,"info", false);
|
||||
Curriculum chemistryBab1 = new Curriculum(1,"chemistry", false);
|
||||
Curriculum psychologyBab1 = new Curriculum(1,"psychology", false);
|
||||
Curriculum infoBab2 = new Curriculum(2,"info", false);
|
||||
Curriculum masterinfo1 = new Curriculum(4, "info", false);
|
||||
Curriculum masterinfo2 = new Curriculum(5, "info", false);
|
||||
Curriculum chemistryBab2 = new Curriculum(2, "chemistry", false);
|
||||
Curriculum ingebab1 = new Curriculum(1, "ingénieur", true);
|
||||
|
||||
curriculumService.save(infoBab1);
|
||||
curriculumService.save(chemistryBab1);
|
||||
curriculumService.save(psychologyBab1);
|
||||
curriculumService.save(infoBab2);
|
||||
curriculumService.save(masterinfo1);
|
||||
curriculumService.save(masterinfo2);
|
||||
curriculumService.save(chemistryBab2);
|
||||
curriculumService.save(ingebab1);
|
||||
|
||||
ucr.save(new UserCurriculum(joe, infoBab1, 2022, false));
|
||||
ucr.save(new UserCurriculum(joe, chemistryBab1, 2023, true));
|
||||
ucr.save(new UserCurriculum(joe, infoBab1, 2023, true));
|
||||
ucr.save(new UserCurriculum(joe, psychologyBab1, 2020, false));
|
||||
ucr.save(new UserCurriculum(popo, infoBab1, 2022, false));
|
||||
ucr.save(new UserCurriculum(popo, infoBab2, 2023, true));
|
||||
|
||||
Course progra1 = new Course(5,"Programmation et algorithmique 1",joke);
|
||||
Course chemistry1 = new Course(12, "Thermochimie",jojo);
|
||||
Course psycho1 = new Course(21, "Neuroreaction of isolated brain cells",joke);
|
||||
Course commun = new Course(2, "cours commun",joke);
|
||||
|
||||
courseService.save(progra1);
|
||||
courseService.save(chemistry1);
|
||||
courseService.save(psycho1);
|
||||
courseService.save(commun);
|
||||
|
||||
ScholarshipRequest ssr1 = new ScholarshipRequest(joe, RequestState.Pending, 0, new Date(), "test", "test");
|
||||
scholarshipRequestRepository.save(ssr1);
|
||||
|
||||
|
||||
User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand",new Date(0), null,Role.Admin,passwordEncoder.encode("admin"));
|
||||
User joe = new User("Mama","Joe","student@student.com","roundabout","DaWarudo",new Date(0), null,Role.Student,passwordEncoder.encode("student"));
|
||||
User meh = new User("Inspiration","lackOf","secretary@secretary.com","a Box","the street",new Date(0), null,Role.Teacher,passwordEncoder.encode("secretary"));
|
||||
User joke = new User("CthemBalls","Lemme","teacher@teacher.com","lab","faculty",new Date(0), null,Role.Teacher,passwordEncoder.encode("teacher"));
|
||||
mockUsers = new ArrayList<User>(Arrays.asList(herobrine,joe,meh,joke));
|
||||
CurriculumCourseService.save(new CurriculumCourse(infoBab1,progra1));
|
||||
CurriculumCourseService.save(new CurriculumCourse(infoBab1,commun));
|
||||
CurriculumCourseService.save(new CurriculumCourse(infoBab1, psycho1));
|
||||
CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,psycho1));
|
||||
CurriculumCourseService.save(new CurriculumCourse(psychologyBab1,commun));
|
||||
CurriculumCourseService.save(new CurriculumCourse(chemistryBab1, chemistry1));
|
||||
|
||||
userRepo.saveAll(mockUsers);
|
||||
CurriculumCourseService.save(new CurriculumCourse(chemistryBab1, commun));
|
||||
CurriculumCourseService.save(new CurriculumCourse(chemistryBab1, chemistry1));
|
||||
|
||||
|
||||
// Course / Curriculum part
|
||||
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, null);
|
||||
|
||||
Cursus infoBab1 = new Cursus(1,"info");
|
||||
Cursus chemistryBab1 = new Cursus(1,"chemistry");
|
||||
Cursus psychologyBab1 = new Cursus(1,"psychology");
|
||||
inscriptionService.save(inscriptionRequest);
|
||||
|
||||
cursusService.save(infoBab1);
|
||||
cursusService.save(chemistryBab1);
|
||||
cursusService.save(psychologyBab1);
|
||||
///////////////////////////
|
||||
// extension Publications Scientifiques
|
||||
Researcher jojoResearcherAccount = new Researcher(jojo, "3363-22555-AB33-T", null, "IT");
|
||||
|
||||
Researcher joResearchAccount = new Researcher(joe,"N555-321213-BED-DD",null, "Physics");
|
||||
|
||||
|
||||
Course progra1 = new Course(5,"Programmation et algorithimque 1","TODO DELETE");
|
||||
Course chemistry1 = new Course(12, "Thermochimie","TODO DELETE");
|
||||
Course psycho1 = new Course(21, "rien faire t'as cru c'est psycho", "TODO DELETE");
|
||||
Course commun = new Course(2, "cours commun","TODO DELETE");
|
||||
Researcher output = researchesService.saveResearcher(jojoResearcherAccount);
|
||||
Researcher joOutput = researchesService.saveResearcher(joResearchAccount);
|
||||
|
||||
courseService.save(progra1);
|
||||
courseService.save(chemistry1);
|
||||
courseService.save(psycho1);
|
||||
courseService.save(commun);
|
||||
Set<Researcher> coAuthor = new HashSet<>();
|
||||
coAuthor.add(joOutput);
|
||||
|
||||
Research jojoResearch = new Research("Graphs : Advanced Search Algorithms", output, new Date(0),
|
||||
PaperType.Article, "test.pdf", null, "english",
|
||||
Access.OpenSource, "IT", "This Article's title speaks for itself \n We'll discuss about advanced Graph search Algorithms",coAuthor);
|
||||
Research restrictedResearch = new Research("the great Constantinople war", output, new Date(1111111111),
|
||||
PaperType.Article, "restricted", null, "Portuguese",
|
||||
Access.Restricted, "history", "this is a summary", new HashSet<>());
|
||||
|
||||
Research privateResearch = new Research("the great Potato War", output, new Date(),
|
||||
PaperType.Article, "private", null, "english",
|
||||
Access.Private, "agriculture", "my life is potato",null);
|
||||
|
||||
|
||||
cursusCourseService.save(new CursusCourse(infoBab1,progra1));
|
||||
cursusCourseService.save(new CursusCourse(infoBab1,commun));
|
||||
|
||||
cursusCourseService.save(new CursusCourse(psychologyBab1,psycho1));
|
||||
cursusCourseService.save(new CursusCourse(psychologyBab1,commun));
|
||||
researchesService.saveResearch(restrictedResearch);
|
||||
researchesService.saveResearch(privateResearch);
|
||||
researchesService.saveResearch(jojoResearch);
|
||||
|
||||
|
||||
cursusCourseService.save(new CursusCourse(chemistryBab1,commun));
|
||||
cursusCourseService.save(new CursusCourse(chemistryBab1,chemistry1));
|
||||
//Schedule part
|
||||
|
||||
Lesson lesson_0_progra1 = new Lesson(progra1, "Mon Apr 22 2024 08:15", "Mon Apr 22 2024 10:15","rgb(255,36,175)","A0B2","Course");
|
||||
Lesson lesson_0_chemistry1 = new Lesson(chemistry1, "Wed Mar 27 2024 08:15", "Wed Mar 27 2024 09:15","rgb(36,175,255)","A0B2","TP");
|
||||
Lesson lesson_0_psycho1 = new Lesson(psycho1, "Sun Mar 24 2024 10:30 ","Sun Mar 24 2024 12:30 ","rgb(255,36,175)", "A0B2","TD");
|
||||
Lesson lesson_1_progra1 = new Lesson(progra1, "Mon Apr 02 2024 13:30", "Mon Apr 02 2024 15:30","rgb(36,175,255)","A0B2","TP");
|
||||
Lesson lesson_0_commun = new Lesson(commun, "Mon Apr 01 2024 10:30", "Mon Apr 01 2024 12:30","rgb(255,36,175)","A0B2","Course");
|
||||
|
||||
LessonChangesRequest request1 = new LessonChangesRequest(joke,RequestState.Pending,null,null,null,null,2,null,1);
|
||||
LessonChangesRequest request2 = new LessonChangesRequest(joke,RequestState.Pending,"Fri Apr 19 2024 10:30 ","Fri Apr 19 2024 12:30 ",null,null,1,null,2);
|
||||
LessonChangesRequest request3 = new LessonChangesRequest(joke,RequestState.Pending,"Fri Apr 19 2024 13:30 ","Fri Apr 19 2024 15:30 ","Course",progra1,0,"rgb(27,49,100)",4);
|
||||
|
||||
|
||||
Schedule infoBab1Schedule = new Schedule(infoBab1);
|
||||
Schedule chemistryBab1Schedule = new Schedule(chemistryBab1);
|
||||
Schedule psychoBab1Schedule = new Schedule(psychologyBab1);
|
||||
|
||||
|
||||
scheduleService.save(infoBab1Schedule);
|
||||
scheduleService.save(chemistryBab1Schedule);
|
||||
scheduleService.save(psychoBab1Schedule);
|
||||
|
||||
lessonService.save(lesson_0_progra1);
|
||||
lessonService.save(lesson_0_chemistry1);
|
||||
lessonService.save(lesson_0_commun);
|
||||
lessonService.save(lesson_0_psycho1);
|
||||
lessonService.save(lesson_1_progra1);
|
||||
|
||||
scheduleLessonService.save(new ScheduleLesson(infoBab1Schedule,lesson_0_progra1));
|
||||
scheduleLessonService.save(new ScheduleLesson(infoBab1Schedule,lesson_1_progra1));
|
||||
scheduleLessonService.save(new ScheduleLesson(infoBab1Schedule,lesson_0_commun));
|
||||
|
||||
scheduleLessonService.save(new ScheduleLesson(chemistryBab1Schedule,lesson_0_chemistry1));
|
||||
scheduleLessonService.save(new ScheduleLesson(chemistryBab1Schedule,lesson_0_commun));
|
||||
|
||||
scheduleLessonService.save(new ScheduleLesson(psychoBab1Schedule,lesson_0_psycho1));
|
||||
scheduleLessonService.save(new ScheduleLesson(psychoBab1Schedule,lesson_0_commun));
|
||||
|
||||
|
||||
lessonRequestService.save(request1);
|
||||
lessonRequestService.save(request2);
|
||||
lessonRequestService.save(request3);
|
||||
|
||||
UnregisterRequest unregisterRequest = new UnregisterRequest(RequestState.Pending, "je veux partir", new Date(), joe.getRegNo(), joe.getFirstName(), joe.getLastName(), joe.getEmail(), null);
|
||||
uninscriptionRequestRepository.save(unregisterRequest);
|
||||
|
||||
externalCurriculum = new ExternalCurriculum(inscriptionRequest, "HEH", "Bachelier en informatique", "Completed", 2015, 2018, null, null);
|
||||
externalCurriculumRepository.save(externalCurriculum);
|
||||
|
||||
isMocked = true;
|
||||
}
|
||||
|
||||
@DeleteMapping("/mock")
|
||||
public void deleteMock(){
|
||||
for (User user:mockUsers){
|
||||
tokenRepo.deleteAll(tokenRepo.getByUser(user));
|
||||
}
|
||||
userRepo.deleteAll(mockUsers);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,113 @@
|
||||
package ovh.herisson.Clyde.EndPoints.Msg;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
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.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 jakarta.websocket.server.PathParam;
|
||||
import lombok.AllArgsConstructor;
|
||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Msg.AnswerRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Msg.ForumRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Msg.TopicRepository;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.CourseService;
|
||||
import ovh.herisson.Clyde.Services.Msg.ForumService;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.Token;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
import ovh.herisson.Clyde.Tables.Msg.Answer;
|
||||
import ovh.herisson.Clyde.Tables.Msg.Forum;
|
||||
import ovh.herisson.Clyde.Tables.Msg.Topic;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
@AllArgsConstructor
|
||||
public class ForumController {
|
||||
|
||||
private CourseRepository courseRepo;
|
||||
private AuthenticatorService authServ;
|
||||
private ForumService forumServ;
|
||||
private ForumRepository forumRepo;
|
||||
private TopicRepository topicRepo;
|
||||
|
||||
//// Endpoints to get and create new forums
|
||||
|
||||
@GetMapping("/forums/{id}")
|
||||
public ResponseEntity<List<Forum>> getForumFromCourseId(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
User u = authServ.getUserFromToken(token);
|
||||
if(u == null){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
return new ResponseEntity<>(courseRepo.findById(id).getForums(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/forums/{id}")
|
||||
public ResponseEntity<Forum> createForumOfCourse(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Forum data){
|
||||
User u = authServ.getUserFromToken(token);
|
||||
Course c = courseRepo.findById(id);
|
||||
if(!(c.getOwner().equals(u) || u.getRole() == Role.Admin)){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
forumServ.createForum(c, data);
|
||||
return new ResponseEntity<>(HttpStatus.ACCEPTED);
|
||||
}
|
||||
|
||||
//// Endpoints to get and create forum's topic
|
||||
|
||||
@GetMapping("/forum/{id}")
|
||||
public ResponseEntity<List<Topic>> getTopicsFromForumId(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
User u = authServ.getUserFromToken(token);
|
||||
if(u == null){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
return new ResponseEntity<>(forumRepo.findById(id).orElse(null).getTopics(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/forum/{id}")
|
||||
public ResponseEntity<Topic> postTopicToForum(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Topic data){
|
||||
User u = authServ.getUserFromToken(token);
|
||||
Forum f = forumRepo.findById(id).orElse(null);
|
||||
if(!(f.getWriters().contains(u) || f.getCourse().getOwner().equals(u) || u.getRole() == Role.Admin)){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
forumServ.createTopic(f, data);
|
||||
return new ResponseEntity<>(HttpStatus.ACCEPTED);
|
||||
}
|
||||
|
||||
//// Endpoints related to topics and messages
|
||||
|
||||
@GetMapping("/forum/post/{id}")
|
||||
public ResponseEntity<Topic> getPost(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
User u = authServ.getUserFromToken(token);
|
||||
if(u == null){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
Topic t = topicRepo.findById(id).orElse(null);
|
||||
return new ResponseEntity<>(t, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/forum/post/{id}")
|
||||
public ResponseEntity<Topic> postTopicToForum(@RequestHeader("Authorization") String token, @PathVariable long id, @RequestBody Answer data){
|
||||
User u = authServ.getUserFromToken(token);
|
||||
Topic t = topicRepo.findById(id).orElse(null);
|
||||
if(t.isLocked() && u.getRole() != Role.Admin){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
System.out.println(data);
|
||||
forumServ.answerTopic(t, data, u);
|
||||
return new ResponseEntity<>(HttpStatus.ACCEPTED);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
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.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import ovh.herisson.Clyde.Repositories.NotificationRepository;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Tables.Notification;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
import ovh.herisson.Clyde.Tables.Notification.Status;
|
||||
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
public class NotificationController {
|
||||
|
||||
private AuthenticatorService authServ;
|
||||
private NotificationRepository notifRepo;
|
||||
|
||||
@GetMapping("/notifications")
|
||||
public ResponseEntity<List<Notification>> getNotifications(@RequestHeader("Authorization") String token){
|
||||
User u = authServ.getUserFromToken(token);
|
||||
if(u == null){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
ArrayList<Notification> ret = new ArrayList<>();
|
||||
for (Notification n : u.getNotifications()) {
|
||||
if(!n.getStatus().equals(Status.Archived)){
|
||||
ret.add(n);
|
||||
}
|
||||
}
|
||||
return new ResponseEntity<>(ret, HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/notifications/{id}")
|
||||
public ResponseEntity<Notification> archiveNotification(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
User u = authServ.getUserFromToken(token);
|
||||
Notification n = notifRepo.findById(id).orElse(null);
|
||||
if(u == null || n.getUser() != u){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
|
||||
n.setStatus(Status.Archived);
|
||||
notifRepo.save(n);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
/******************************************************
|
||||
* @file ScheduleController.java
|
||||
* @author William Karpinski
|
||||
* @scope Extension Horaire
|
||||
*
|
||||
* Controller of Schedule API
|
||||
******************************************************/
|
||||
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.ScheduleLessonService;
|
||||
import ovh.herisson.Clyde.Services.ScheduleService;
|
||||
import ovh.herisson.Clyde.Services.UserCurriculumService;
|
||||
import ovh.herisson.Clyde.Services.CurriculumService;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
import ovh.herisson.Clyde.Services.LessonService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
public class ScheduleController {
|
||||
|
||||
private final ScheduleService scheduleServ;
|
||||
private final LessonService lessonServ;
|
||||
|
||||
private final CurriculumService curriculumServ;
|
||||
private final AuthenticatorService authServ;
|
||||
|
||||
private final ScheduleLessonService scheduleLessonServ;
|
||||
|
||||
public ScheduleController(ScheduleService scheduleServ, AuthenticatorService authServ, ScheduleLessonService scheduleLessonServ, CurriculumService curriculumServ,LessonService lessonServ) {
|
||||
this.scheduleServ = scheduleServ;
|
||||
this.authServ = authServ;
|
||||
this.scheduleLessonServ = scheduleLessonServ;
|
||||
this.curriculumServ = curriculumServ;
|
||||
this.lessonServ = lessonServ;
|
||||
}
|
||||
/**
|
||||
* Return schedule via its id
|
||||
*/
|
||||
@GetMapping("/schedule/{id}")
|
||||
public ResponseEntity<Map<String,Object>> findById(@PathVariable long id){
|
||||
Schedule schedule = scheduleServ.findById(id);
|
||||
|
||||
if(schedule == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
return new ResponseEntity<>(scheduleLessonServ.getDepthScheduleBySchedule(schedule),HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a schedule via its curriculum id
|
||||
*/
|
||||
@GetMapping("/schedule/curriculum/{id}")
|
||||
public ResponseEntity<Map<String, Object>> findCurriculumSchedule(@PathVariable Long id){
|
||||
Schedule schedule = scheduleLessonServ.getScheduleByCurriculum(curriculumServ.findById(id));
|
||||
if(schedule == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
return new ResponseEntity<>(scheduleLessonServ.getDepthScheduleBySchedule(schedule),HttpStatus.OK);
|
||||
}
|
||||
/**
|
||||
* Return all schedules
|
||||
*/
|
||||
@GetMapping("/schedules")
|
||||
public ResponseEntity<Iterable<Map<String , Object>>> findAllSchedule(){
|
||||
return new ResponseEntity<>(scheduleLessonServ.getAllSchedule(),HttpStatus.OK);
|
||||
}
|
||||
/**
|
||||
* Post a new schedule
|
||||
*/
|
||||
@PostMapping("/schedule")
|
||||
public ResponseEntity<Schedule> postSchedule(@RequestHeader("Authorization") String token,
|
||||
@RequestBody Schedule schedule){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
return new ResponseEntity<>(scheduleServ.save(schedule),HttpStatus.OK);
|
||||
}
|
||||
/**
|
||||
* Post a lesson to a schedule
|
||||
*/
|
||||
@PostMapping("/schedule/{id}")
|
||||
public ResponseEntity<String> postLessonToSchedule(@RequestHeader("Authorization") String token,
|
||||
@RequestBody Long lessonId,
|
||||
@PathVariable long id)
|
||||
{
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
if (!scheduleLessonServ.save(new ScheduleLesson( scheduleServ.findById(id), lessonServ.findById(lessonId))))
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
/**
|
||||
* Delete a lesson from a schedule
|
||||
*/
|
||||
@DeleteMapping("/schedule/lesson/{id}")
|
||||
public ResponseEntity<String> deleteLessonFromSchedule(@RequestHeader("Authorization") String token,
|
||||
@RequestBody Long lessonId,
|
||||
@PathVariable Long id)
|
||||
{
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
if (!scheduleLessonServ.delete(lessonId))
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,167 @@
|
||||
package ovh.herisson.Clyde.EndPoints.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file ResearchController.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* API class for the researches
|
||||
******************************************************/
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.DTO.ScientificPublications.ResearchDTO;
|
||||
import ovh.herisson.Clyde.DTO.ScientificPublications.ResearcherDTO;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.ScientificPublications.ResearchesService;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
@AllArgsConstructor
|
||||
public class ResearchController {
|
||||
|
||||
|
||||
|
||||
private final ResearchesService researchesServ;
|
||||
|
||||
private final AuthenticatorService authServ;
|
||||
|
||||
/** Is accessible by anyone
|
||||
* but if the user doesn't have the permission to download the research
|
||||
* the return Research Download URL will be null
|
||||
*/
|
||||
@GetMapping("/research/{id}")
|
||||
public ResponseEntity<ResearchDTO> getResearch(@RequestHeader(value = "Authorization", required = false) String token, @PathVariable long id){
|
||||
|
||||
Research research = researchesServ.getResearchById(id);
|
||||
|
||||
if (research == null)
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
|
||||
if (researchesServ.hasNoAccessTo(research,authServ.getUserFromToken(token))){
|
||||
research.setPdfLocation(null);
|
||||
}// If the user doesn't have access to the document he can't download the pdf
|
||||
|
||||
return new ResponseEntity<>(ResearchDTO.construct(research), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param token used to know if the user can download or not the research pdf
|
||||
* @return every research
|
||||
*/
|
||||
@GetMapping("/researches")
|
||||
public ResponseEntity<Iterable<ResearchDTO>> getResearches(@RequestHeader(value = "Authorization",required = false) String token){
|
||||
Iterable<Research> researches = researchesServ.getAllResearches();
|
||||
|
||||
ArrayList<ResearchDTO> toReturnResearches = new ArrayList<>();
|
||||
|
||||
for (Research research: researches){
|
||||
if (researchesServ.hasNoAccessTo(research,authServ.getUserFromToken(token))){
|
||||
research.setPdfLocation(null);
|
||||
}
|
||||
toReturnResearches.add(ResearchDTO.construct(research));
|
||||
}
|
||||
return new ResponseEntity<>(toReturnResearches,HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/researches/{id}")
|
||||
public ResponseEntity<Iterable<ResearchDTO>> getResearchesFromResearcher(@RequestHeader(value = "Authorization",required = false) String token,
|
||||
@PathVariable Long id
|
||||
){
|
||||
Iterable<Research> researches = researchesServ.getResearchesByAuthor(id);
|
||||
if (researches == null) return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
|
||||
ArrayList<ResearchDTO> toReturnResearches = new ArrayList<>();
|
||||
|
||||
for (Research research: researches){
|
||||
if (researchesServ.hasNoAccessTo(research,authServ.getUserFromToken(token))){
|
||||
research.setPdfLocation(null);
|
||||
}
|
||||
toReturnResearches.add(ResearchDTO.construct(research));
|
||||
}
|
||||
return new ResponseEntity<>(toReturnResearches,HttpStatus.OK);
|
||||
}
|
||||
|
||||
/** post a new research
|
||||
*
|
||||
* @return the research saved
|
||||
*/
|
||||
@PostMapping("/research")
|
||||
public ResponseEntity<Research> postResearch(@RequestHeader("Authorization") String token, @RequestBody Research research){
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin},token) &&
|
||||
researchesServ.getResearcherByUser(authServ.getUserFromToken(token)) == null){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
} // if the poster isn't a researcher
|
||||
|
||||
return new ResponseEntity<>(researchesServ.saveResearch(research), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/** post updates to the research
|
||||
* in the updates, the coAuthors have to be referenced by their ids
|
||||
*
|
||||
*/
|
||||
@PatchMapping("/research/{id}")
|
||||
public ResponseEntity<String> patchResearch(@RequestHeader("Authorization") String token,
|
||||
@RequestBody Map<String,Object> updates,
|
||||
@PathVariable long id
|
||||
)
|
||||
{
|
||||
Research research = researchesServ.getResearchById(id);
|
||||
Researcher researcher = researchesServ.getResearcherByUser(authServ.getUserFromToken(token));
|
||||
|
||||
if (research == null)
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token) &&
|
||||
researcher != research.getAuthor()) {
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
|
||||
researchesServ.modifyResearchData(research, updates);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/** Only Admin, Secretary and author can delete a research
|
||||
*
|
||||
*/
|
||||
@DeleteMapping("/research/{id}")
|
||||
public ResponseEntity<String> deleteResearch(@RequestHeader("Authorization") String token, @PathVariable long id){
|
||||
|
||||
Research research = researchesServ.getResearchById(id);
|
||||
Researcher researcher = researchesServ.getResearcherByUser(authServ.getUserFromToken(token));
|
||||
|
||||
if (research == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin, Role.Secretary},token) &&
|
||||
researcher != research.getAuthor()){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
|
||||
researchesServ.deleteResearch(research);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
///////
|
||||
//views part
|
||||
@PostMapping("/addview/cdn/{url}")
|
||||
public ResponseEntity<ResearchDTO> addView(@PathVariable String url){
|
||||
System.out.println(url);
|
||||
Research research = researchesServ.getResearchByUrl("cdn/" + url);
|
||||
if (research ==null) return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(ResearchDTO.construct(researchesServ.addView(research)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
package ovh.herisson.Clyde.EndPoints.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file ResearcherController.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* API class for the researchers
|
||||
******************************************************/
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.DTO.ScientificPublications.ResearcherDTO;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.ScientificPublications.ResearchesService;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
@AllArgsConstructor
|
||||
public class ResearcherController {
|
||||
|
||||
ResearchesService researchesServ;
|
||||
AuthenticatorService authServ;
|
||||
|
||||
|
||||
@GetMapping("/researcher/{id}")
|
||||
public ResponseEntity<ResearcherDTO> getResearcher(@PathVariable long id){
|
||||
Researcher researcher = researchesServ.getResearcherById(id);
|
||||
return new ResponseEntity<>(ResearcherDTO.construct(researcher),HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* Everyone can access every researcher Account
|
||||
* @return all the researchers accounts
|
||||
*/
|
||||
@GetMapping("/researchers")
|
||||
public ResponseEntity<Iterable<ResearcherDTO>> getAllResearchers(){
|
||||
Iterable<Researcher> researchers = researchesServ.getAllResearchers();
|
||||
ArrayList<ResearcherDTO> toReturnResearchersDTO = new ArrayList<>();
|
||||
for (Researcher researcher: researchers){
|
||||
toReturnResearchersDTO.add(ResearcherDTO.construct(researcher));
|
||||
}
|
||||
return new ResponseEntity<>(toReturnResearchersDTO, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/researcher")
|
||||
public ResponseEntity<ResearcherDTO> getSelf(@RequestHeader("Authorization") String token){
|
||||
|
||||
Researcher self = researchesServ.getResearcherByUser(authServ.getUserFromToken(token));
|
||||
|
||||
if (self ==null) return new UnauthorizedResponse<>(null);
|
||||
|
||||
return new ResponseEntity<>(ResearcherDTO.construct(self), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/researcher")
|
||||
public ResponseEntity<ResearcherDTO> postResearcher(@RequestHeader("Authorization") String token, @RequestBody Researcher researcher){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary}, token)){
|
||||
return new UnauthorizedResponse<>(null);
|
||||
}
|
||||
|
||||
Researcher posted = researchesServ.saveResearcher(researcher);
|
||||
|
||||
if (posted == null) return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(ResearcherDTO.construct(posted), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@PatchMapping("/researcher/{id}")
|
||||
public ResponseEntity<ResearcherDTO> patchResearcher(@RequestHeader("Authorization") String token,
|
||||
@PathVariable long id,
|
||||
@RequestBody Map<String ,Object> updates){
|
||||
|
||||
Researcher researcher = researchesServ.getResearcherById(id);
|
||||
if (authServ.isNotIn(new Role[]{Role.Secretary,Role.Admin}, token)
|
||||
&& researcher.getId() != researchesServ.getResearcherByUser(authServ.getUserFromToken(token)).getId())
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
|
||||
if (researcher == null) return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
researchesServ.modifyResearcherData(researcher,updates);
|
||||
|
||||
return new ResponseEntity<>(ResearcherDTO.construct(researcher),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping("/researcher/{id}")
|
||||
public ResponseEntity<String> deleteResearcher(@RequestHeader ("Authorization") String token, @PathVariable long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
researchesServ.deleteResearcher(researchesServ.getResearcherById(id));
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package ovh.herisson.Clyde.EndPoints.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file StatController.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Api class for handling statistics
|
||||
******************************************************/
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Services.ScientificPublications.ResearchesService;
|
||||
import ovh.herisson.Clyde.Services.ScientificPublications.StatisticsService;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
@AllArgsConstructor
|
||||
public class StatController {
|
||||
|
||||
|
||||
private StatisticsService statServ;
|
||||
private ResearchesService researchesServ;
|
||||
|
||||
/** returns all the statistics in a 2D array
|
||||
*
|
||||
* @param id the researcher's id
|
||||
* @return all the stats in a 2D array
|
||||
*/
|
||||
@GetMapping("/stats/{id}")
|
||||
public ResponseEntity<Iterable<Iterable<Map<String, Integer>>>> getStat(@PathVariable Long id){
|
||||
|
||||
Researcher researcher = researchesServ.getResearcherById(id);
|
||||
if (researcher == null) return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
Iterable<Iterable<Map<String,Integer>>> stats = statServ.generateStats(researcher);
|
||||
|
||||
if (stats == null) return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(stats,HttpStatus.OK);
|
||||
|
||||
}
|
||||
}
|
@ -11,7 +11,6 @@ import ovh.herisson.Clyde.Tables.StorageFile;
|
||||
@RestController
|
||||
@CrossOrigin(originPatterns = "*", allowCredentials = "true")
|
||||
public class StorageController {
|
||||
|
||||
private final StorageService storageServ;
|
||||
|
||||
public StorageController(StorageService storageServ){
|
||||
@ -22,12 +21,13 @@ public class StorageController {
|
||||
@PostMapping("/upload/{fileType}")
|
||||
public ResponseEntity<StorageFile> handleFileUpload(@RequestParam("file") MultipartFile file, @PathVariable FileType fileType) {
|
||||
|
||||
StorageFile fileEntry = null;
|
||||
StorageFile fileEntry;
|
||||
try {
|
||||
fileEntry = storageServ.store(file,fileType);
|
||||
|
||||
} catch(Exception e){
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(null,HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,11 +1,15 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
|
||||
|
||||
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.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.TokenService;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.Token;
|
||||
|
||||
@RestController
|
||||
@ -14,13 +18,20 @@ public class TokenController {
|
||||
|
||||
private final TokenService tokenServ;
|
||||
|
||||
public TokenController(TokenService tokenServ){
|
||||
private final AuthenticatorService authServ;
|
||||
|
||||
public TokenController(TokenService tokenServ, AuthenticatorService authServ){
|
||||
this.tokenServ = tokenServ;
|
||||
this.authServ = authServ;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/tokens")
|
||||
public Iterable<Token> getTokens(){
|
||||
return tokenServ.getAllTokens();
|
||||
public ResponseEntity<Iterable<Token>> getTokens(@RequestHeader("Authorization")String token){
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
return new ResponseEntity<>(tokenServ.getAllTokens(), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,15 @@
|
||||
package ovh.herisson.Clyde.EndPoints;
|
||||
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
|
||||
import ovh.herisson.Clyde.Services.AuthenticatorService;
|
||||
import ovh.herisson.Clyde.Services.ProtectionService;
|
||||
import ovh.herisson.Clyde.Services.UserService;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -25,79 +26,112 @@ public class UserController {
|
||||
this.authServ = authServ;
|
||||
}
|
||||
|
||||
/** returns information about the connected user
|
||||
*
|
||||
* @param token the session token of the user
|
||||
* @return the user information except his password
|
||||
*/
|
||||
@GetMapping("/user")
|
||||
public ResponseEntity<HashMap<String,Object>> getUser(@RequestHeader("Authorization") String authorization){
|
||||
public ResponseEntity<HashMap<String,Object>> getUser(@RequestHeader("Authorization") String token){
|
||||
|
||||
if (authorization == null) return new UnauthorizedResponse<>(null);
|
||||
User user = authServ.getUserFromToken(authorization);
|
||||
if (user == null) return new UnauthorizedResponse<>(null);
|
||||
User user = authServ.getUserFromToken(token);
|
||||
if (user == null) return new UnauthorizedResponse<>(null);
|
||||
|
||||
return new ResponseEntity<>(userWithoutPassword(user), HttpStatus.OK);
|
||||
return new ResponseEntity<>(ProtectionService.userWithoutPassword(user), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/user/{id}")
|
||||
public ResponseEntity<HashMap<String ,Object>> getUserById(@RequestHeader("Authorization") String token, @PathVariable Long id){
|
||||
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary,Role.InscriptionService, Role.Teacher},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.userWithoutPassword(userService.getUserById(id)), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/user")
|
||||
public ResponseEntity<String> postUser(@RequestBody User user,@RequestHeader("Authorization") String authorization){
|
||||
public ResponseEntity<Map<String ,Object>> postUser(@RequestBody User user,@RequestHeader("Authorization") String token){
|
||||
|
||||
if (!isSecretaryOrAdmin(authorization))
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.InscriptionService,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
userService.save(user);
|
||||
return new ResponseEntity<>(String.format("Account created with ID:%s",user.getRegNo()),HttpStatus.CREATED);
|
||||
return new ResponseEntity<>(ProtectionService.userWithoutPassword(userService.save(user)),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@GetMapping("/users")
|
||||
public ResponseEntity<Iterable<HashMap<String,Object>>> getAllUsers(@RequestHeader("Authorization") String authorization){
|
||||
public ResponseEntity<Iterable<HashMap<String,Object>>> getAllUsers(@RequestHeader("Authorization") String token){
|
||||
|
||||
if (!isSecretaryOrAdmin(authorization))
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
Role posterRole = authServ.getUserFromToken(token).getRole();
|
||||
|
||||
Iterable<User> users = new ArrayList<>();
|
||||
|
||||
if (posterRole == Role.Admin)
|
||||
users = userService.getAll();
|
||||
|
||||
else if (posterRole == Role.Secretary)
|
||||
users = userService.getAllExceptAdmins();
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.usersWithoutPasswords(users), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/** changes the specified user's information
|
||||
*
|
||||
* @param updates the changes to be made
|
||||
* @param token the session token of the user posting the change
|
||||
* @param id the id of the user to change
|
||||
* @return a string clarifying the issue (if there is any)
|
||||
*/
|
||||
@PatchMapping("/user/{id}")
|
||||
public ResponseEntity<Map<String,Object>> patchUser(@RequestHeader("Authorization") String token,
|
||||
@RequestBody Map<String,Object> updates,
|
||||
@PathVariable Long id) {
|
||||
|
||||
if (token == null) return new UnauthorizedResponse<>(null);
|
||||
|
||||
User poster = authServ.getUserFromToken(token);
|
||||
if (poster == null) {return new UnauthorizedResponse<>(null);}
|
||||
|
||||
User modified = userService.modifyData(id,updates,poster);
|
||||
if (modified ==null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.userWithoutPassword(modified), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/teachers")
|
||||
public ResponseEntity<Iterable<HashMap<String,Object>>> getAllTeachers(@RequestHeader("Authorization") String token){
|
||||
Iterable<User> teachers = userService.getAllTeachers();
|
||||
|
||||
return new ResponseEntity<>(ProtectionService.usersWithoutPasswords(teachers), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/students")
|
||||
public ResponseEntity<Iterable<HashMap<String,Object>>> getAllStudent(@RequestHeader("Authorization") String token){
|
||||
if (authServ.getUserFromToken(token) == null)
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
Iterable<User> users = userService.getAll();
|
||||
ArrayList<HashMap<String, Object>> withoutPassword = new ArrayList<>();
|
||||
Iterable<User> students = userService.getAllStudents();
|
||||
|
||||
for (User u :users){
|
||||
withoutPassword.add(userWithoutPassword(u));
|
||||
}
|
||||
return new ResponseEntity<>(withoutPassword, HttpStatus.OK);
|
||||
}
|
||||
@PatchMapping("/user")
|
||||
public ResponseEntity<String> patchUser(@RequestBody Map<String,Object> updates, @RequestHeader("Authorization") String authorization) {
|
||||
|
||||
if (authorization == null) return new UnauthorizedResponse<>(null);
|
||||
|
||||
User poster = authServ.getUserFromToken(authorization);
|
||||
if (poster == null) {return new UnauthorizedResponse<>("bad authorization");}
|
||||
|
||||
if (!userService.modifyData(poster, updates, poster))
|
||||
return new UnauthorizedResponse<>("there was an issue with the updates requested");
|
||||
|
||||
return new ResponseEntity<>("data modified", HttpStatus.OK);
|
||||
}
|
||||
/** return user's data except password
|
||||
* @param user the user to return
|
||||
* @return all the user data without the password
|
||||
*/
|
||||
private HashMap<String,Object> userWithoutPassword(User user){
|
||||
HashMap<String,Object> toReturn = new HashMap<>();
|
||||
|
||||
toReturn.put("regNo",user.getRegNo());
|
||||
toReturn.put("firstName",user.getFirstName());
|
||||
toReturn.put("lastName",user.getLastName());
|
||||
toReturn.put("birthDate",user.getBirthDate());
|
||||
toReturn.put("country",user.getCountry());
|
||||
toReturn.put("address",user.getAddress());
|
||||
toReturn.put("role",user.getRole());
|
||||
|
||||
return toReturn;
|
||||
return new ResponseEntity<>(ProtectionService.usersWithoutPasswords(students), HttpStatus.OK);
|
||||
}
|
||||
|
||||
private boolean isSecretaryOrAdmin(String authorization){
|
||||
if (authorization ==null)
|
||||
return false;
|
||||
|
||||
User poster = authServ.getUserFromToken(authorization);
|
||||
if (poster == null) return false;
|
||||
@DeleteMapping("/user/{id}")
|
||||
public ResponseEntity<String> deleteStudent(@RequestHeader("Authorization") String token, @PathVariable Long id){
|
||||
if (authServ.isNotIn(new Role[]{Role.Admin,Role.Secretary},token) && !id.equals(authServ.getUserFromToken(token).getRegNo()))
|
||||
return new UnauthorizedResponse<>(null);
|
||||
|
||||
return poster.getRole() == Role.Secretary && poster.getRole() == Role.Admin;
|
||||
User toDelete = userService.getUserById(id);
|
||||
|
||||
if (toDelete == null)
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
||||
userService.delete(toDelete);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,37 +0,0 @@
|
||||
package ovh.herisson.Clyde;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
public class JdbcConfig {
|
||||
|
||||
@Bean
|
||||
@Profile("!prod")
|
||||
public DataSource psqlSource(){
|
||||
DriverManagerDataSource source = new DriverManagerDataSource();
|
||||
source.setDriverClassName("org.postgresql.Driver");
|
||||
source.setUrl("jdbc:postgresql://localhost:5432/clyde");
|
||||
source.setUsername("devel");
|
||||
source.setPassword("devel");
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Profile("prod")
|
||||
public DataSource psqlSourceProd(){
|
||||
DriverManagerDataSource source = new DriverManagerDataSource();
|
||||
source.setDriverClassName("org.postgresql.Driver");
|
||||
source.setUrl("jdbc:postgresql:clyde?socketFactory=org.newsclub.net.unix.AFUNIXSocketFactory$FactoryArg&socketFactoryArg=/var/run/postgresql/.s.PGSQL.5432");
|
||||
source.setUsername("clyde");
|
||||
|
||||
return source;
|
||||
}
|
||||
}
|
@ -1,8 +1,15 @@
|
||||
package ovh.herisson.Clyde.Repositories;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
public interface CourseRepository extends CrudRepository<Course,Long> {
|
||||
Course findById(long id);
|
||||
|
||||
|
||||
@Query("select c from Course c where c.owner = ?1")
|
||||
Iterable<Course> findAllOwnedCoures(User teacher);
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package ovh.herisson.Clyde.Repositories;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||
import ovh.herisson.Clyde.Tables.CurriculumCourse;
|
||||
|
||||
public interface CurriculumCourseRepository extends CrudRepository<CurriculumCourse,Long> {
|
||||
|
||||
@Query("select distinct cc.course from CurriculumCourse cc where cc.curriculum = ?1")
|
||||
Iterable<Course> findCoursesByCurriculum(Curriculum curriculum);
|
||||
|
||||
@Query("select distinct cc.curriculum from CurriculumCourse cc where cc.course = ?1")
|
||||
Iterable<Curriculum> findCurriculumByCourses(Course course);
|
||||
|
||||
@Query("select distinct cc.curriculum from CurriculumCourse cc")
|
||||
Iterable<Curriculum> findDistinctCurriculums();
|
||||
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("delete from CurriculumCourse cc where cc.course =?1")
|
||||
void delete(Course course);
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package ovh.herisson.Clyde.Repositories;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||
|
||||
public interface CurriculumRepository extends CrudRepository<Curriculum,Long> {
|
||||
Curriculum findById(long id);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
package ovh.herisson.Clyde.Repositories;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.Cursus;
|
||||
import ovh.herisson.Clyde.Tables.CursusCourse;
|
||||
|
||||
public interface CursusCourseRepository extends CrudRepository<CursusCourse,Long> {
|
||||
|
||||
|
||||
//todo faire custom query pour trouver tous les cours d'un cursus par un cursusId
|
||||
|
||||
@Query("select distinct cc.course from CursusCourse cc where cc.cursus = ?1")
|
||||
Iterable<Course> findCoursesByCursus(Cursus cursus);
|
||||
|
||||
|
||||
@Query("select distinct cc.cursus from CursusCourse cc")
|
||||
Iterable<Cursus> findDistinctCursuses();
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package ovh.herisson.Clyde.Repositories;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Cursus;
|
||||
|
||||
public interface CursusRepository extends CrudRepository<Cursus,Long> {
|
||||
Cursus findById(long id);
|
||||
}
|
@ -1,9 +1,14 @@
|
||||
package ovh.herisson.Clyde.Repositories;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import ovh.herisson.Clyde.Tables.StorageFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public interface FileRepository extends CrudRepository<StorageFile,Long> {
|
||||
public StorageFile getStorageFileByName(String name);
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package ovh.herisson.Clyde.Repositories.Inscription;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.ChangeCurriculumRequest;
|
||||
|
||||
public interface ChangeCurriculumRequestRepository extends CrudRepository<ChangeCurriculumRequest, Long> {
|
||||
ChangeCurriculumRequest findById(long id);
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package ovh.herisson.Clyde.Repositories.Inscription;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.ExemptionsRequest;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface ExemptionsRequestRepository extends CrudRepository<ExemptionsRequest, Long> {
|
||||
ExemptionsRequest findById(long id);
|
||||
|
||||
ArrayList<ExemptionsRequest> findByUser(User user);
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package ovh.herisson.Clyde.Repositories.Inscription;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.ExternalCurriculum;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface ExternalCurriculumRepository extends CrudRepository<ExternalCurriculum, Long> {
|
||||
ArrayList<ExternalCurriculum> getExternalCurriculumByInscriptionRequest(InscriptionRequest ir);
|
||||
|
||||
ArrayList<ExternalCurriculum> getExternalCurriculumByUser(User user);
|
||||
ExternalCurriculum getExternalCurriculumById(long id);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package ovh.herisson.Clyde.Repositories;
|
||||
package ovh.herisson.Clyde.Repositories.Inscription;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
|
||||
|
||||
|
||||
public interface InscriptionRepository extends CrudRepository<InscriptionRequest,Long> {
|
@ -0,0 +1,12 @@
|
||||
package ovh.herisson.Clyde.Repositories.Inscription;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.Minerval;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface MinervalRepository extends CrudRepository<Minerval, Long> {
|
||||
public ArrayList<Minerval> getMinervalsByStudentRegNoOrderByYearDesc(Long studentRegNo);
|
||||
|
||||
public Minerval findById(long id);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package ovh.herisson.Clyde.Repositories.Inscription;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.Payment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface PaymentRepository extends CrudRepository<Payment, Long> {
|
||||
public ArrayList<Payment> getPaymentsByStudentRegNo(long regNo);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package ovh.herisson.Clyde.Repositories.Inscription;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.ScholarshipRequest;
|
||||
|
||||
public interface ScholarshipRequestRepository extends CrudRepository<ScholarshipRequest, Long> {
|
||||
public ScholarshipRequest findById(long id);
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package ovh.herisson.Clyde.Repositories.Inscription;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.UnregisterRequest;
|
||||
|
||||
public interface UnregisterRequestRepository extends CrudRepository<UnregisterRequest, Long> {
|
||||
public UnregisterRequest findById(long l);
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package ovh.herisson.Clyde.Repositories;
|
||||
|
||||
/******************************************************
|
||||
* @file LessonChangesRequestRepository.java
|
||||
* @author William Karpinski
|
||||
* @scope Extension Horaire
|
||||
******************************************************/
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.LessonChangesRequest;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
public interface LessonChangesRequestRepository extends CrudRepository<LessonChangesRequest, Long> {
|
||||
LessonChangesRequest findById(long id);
|
||||
|
||||
|
||||
@Query("select lr from LessonChangesRequest lr where lr.user = ?1")
|
||||
Iterable<LessonChangesRequest> findOwnRequests(User user);
|
||||
|
||||
@Query("select lr from LessonChangesRequest lr where lr.lessonId = ?1")
|
||||
Iterable<LessonChangesRequest> findRequestByLessonId(long id);
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package ovh.herisson.Clyde.Repositories;
|
||||
|
||||
/******************************************************
|
||||
* @file LessonRepository.java
|
||||
* @author William Karpinski
|
||||
* @scope Extension Horaire
|
||||
******************************************************/
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.Lesson;
|
||||
|
||||
public interface LessonRepository extends CrudRepository<Lesson, Long> {
|
||||
|
||||
Lesson findById(long id);
|
||||
|
||||
@Query("select l from Lesson l where l.course = ?1")
|
||||
Iterable<Lesson> findLessonByCourse(Course course);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package ovh.herisson.Clyde.Repositories.Msg;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import ovh.herisson.Clyde.Tables.Msg.Answer;
|
||||
|
||||
public interface AnswerRepository extends CrudRepository<Answer, Long> {
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package ovh.herisson.Clyde.Repositories.Msg;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import ovh.herisson.Clyde.Tables.Msg.Forum;
|
||||
|
||||
public interface ForumRepository extends CrudRepository<Forum, Long> {
|
||||
|
||||
}
|
@ -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> {}
|
@ -0,0 +1,10 @@
|
||||
package ovh.herisson.Clyde.Repositories.Msg;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import ovh.herisson.Clyde.Tables.Msg.Topic;
|
||||
|
||||
public interface TopicRepository extends CrudRepository<Topic, Long> {
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
package ovh.herisson.Clyde.Repositories;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import ovh.herisson.Clyde.Tables.Notification;
|
||||
|
||||
public interface NotificationRepository extends CrudRepository<Notification, Long> {}
|
||||
|
@ -0,0 +1,33 @@
|
||||
package ovh.herisson.Clyde.Repositories;
|
||||
|
||||
/******************************************************
|
||||
* @file ScheduleLessonRepository.java
|
||||
* @author William Karpinski
|
||||
* @scope Extension Horaire
|
||||
******************************************************/
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||
import ovh.herisson.Clyde.Tables.Lesson;
|
||||
import ovh.herisson.Clyde.Tables.Schedule;
|
||||
import ovh.herisson.Clyde.Tables.ScheduleLesson;
|
||||
|
||||
public interface ScheduleLessonRepository extends CrudRepository<ScheduleLesson,Long> {
|
||||
|
||||
@Query("select distinct sl.lesson from ScheduleLesson sl where sl.schedule.curriculum = ?1")
|
||||
Iterable<Lesson> findLessonByCurriculum(Curriculum curriculum);
|
||||
|
||||
@Query("select distinct sl.schedule from ScheduleLesson sl where sl.schedule.curriculum = ?1")
|
||||
Schedule findScheduleByCurriculum(Curriculum curriculum);
|
||||
|
||||
@Query("select distinct sl from ScheduleLesson sl where sl.lesson = ?1")
|
||||
ScheduleLesson findByLesson(Lesson lesson);
|
||||
|
||||
@Modifying
|
||||
@Transactional
|
||||
@Query("delete from ScheduleLesson sl where sl.lesson =?1")
|
||||
void delete(Lesson lesson);
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package ovh.herisson.Clyde.Repositories;
|
||||
|
||||
/******************************************************
|
||||
* @file ScheduleRepository.java
|
||||
* @author William Karpinski
|
||||
* @scope Extension Horaire
|
||||
******************************************************/
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.Lesson;
|
||||
import ovh.herisson.Clyde.Tables.Schedule;
|
||||
|
||||
public interface ScheduleRepository extends CrudRepository<Schedule,Long> {
|
||||
|
||||
Schedule getById(long id);
|
||||
|
||||
|
||||
@Query("select distinct sl from Schedule sl where EXISTS (select c.curriculum from CurriculumCourse c where (sl.curriculum = c.curriculum) AND (c.course = ?1))")
|
||||
Iterable<Schedule> findAllLessonSchedule(Course course);
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package ovh.herisson.Clyde.Repositories.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file ResearchRepository.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Repository handling communication with Reseach table
|
||||
******************************************************/
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface ResearchRepository extends CrudRepository<Research,Long> {
|
||||
|
||||
Research findById(long id);
|
||||
|
||||
Iterable<Research> findByAuthor(Researcher author);
|
||||
|
||||
@Query("select r from Research r where r.pdfLocation = ?1")
|
||||
Research findByPdfLocation(String url);
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package ovh.herisson.Clyde.Repositories.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file ResearcherRepository.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Repository handling communication with Reseacher table
|
||||
******************************************************/
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
public interface ResearcherRepository extends CrudRepository<Researcher,Long> {
|
||||
Researcher findByUser(User user);
|
||||
|
||||
Researcher findById(long id);
|
||||
|
||||
@Query("select r from Research r where r.author = ?1")
|
||||
Iterable<Research> findAllByAuthorId(Researcher author);
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package ovh.herisson.Clyde.Repositories.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file StatsRepository.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Repository handling communication with Reseach table for making statistics
|
||||
******************************************************/
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface StatsRepository extends CrudRepository<Research,Long> {
|
||||
|
||||
@Query("select new map(to_char(r.releaseDate, 'month') as label, sum(r.views) as y) from Research r where r.author.id = ?1 group by to_char(r.releaseDate, 'month')")
|
||||
Iterable<Map<String ,Integer>> viewsByMonths(long researcherId);
|
||||
|
||||
@Query("select new map(to_char(r.releaseDate,'YYYY') as label, sum (r.views) as y) from Research r group by to_char(r.releaseDate,'YYYY')")
|
||||
Iterable<Map<String ,Integer>> viewsByYears(long researcherId);
|
||||
|
||||
|
||||
@Query("select new map(r.domain as label, sum(r.views) as y) from Research r where r.author.id = ?1 group by r.domain")
|
||||
Iterable<Map<String ,Integer>> viewsByTopics(long researcherId);
|
||||
|
||||
|
||||
@Query("select new map(r.domain as label, count(distinct r.language) as y) from Research r where r.author.id = ?1 group by r.domain")
|
||||
Iterable<Map<String ,Integer>> languageByTopics(long researcherId);
|
||||
|
||||
@Query("select new map(to_char(r.releaseDate,'YYYY') as label, count(distinct r.language) as y) from Research r where r.author.id = ?1 group by to_char(r.releaseDate,'YYYY')")
|
||||
Iterable<Map<String ,Integer>> languageByYears(long researcherId);
|
||||
|
||||
@Query("select new map(to_char(r.releaseDate, 'month') as label, count(distinct r.language) as y) from Research r where r.author.id = ?1 group by to_char(r.releaseDate, 'month')")
|
||||
Iterable<Map<String ,Integer>> languageByMonths(long researcherId);
|
||||
|
||||
@Query("select new map(to_char(r.releaseDate,'YYYY') as label, count(distinct r) as y) from Research r where r.author.id = ?1 group by to_char(r.releaseDate,'YYYY')")
|
||||
Iterable<Map<String ,Integer>> researchesByYears(long researcherId);
|
||||
|
||||
@Query("select new map(r.domain as label, count(distinct r) as y) from Research r where r.author.id = ?1 group by r.domain")
|
||||
Iterable<Map<String ,Integer>> researchesByTopics(long researcherId);
|
||||
|
||||
@Query("select new map(to_char(r.releaseDate, 'month') as label, count(distinct r) as y) from Research r where r.author.id = ?1 group by to_char(r.releaseDate, 'month')")
|
||||
Iterable<Map<String ,Integer>> researchesByMonth(long researcherId);
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package ovh.herisson.Clyde.Repositories;
|
||||
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.TeacherCourse;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
public interface TeacherCourseRepository extends CrudRepository<TeacherCourse, Long> {
|
||||
|
||||
@Query("select tc.user from TeacherCourse tc where tc.course = ?1")
|
||||
Iterable<User> findAllAssistantOfCourse(Course course);
|
||||
}
|
@ -10,7 +10,5 @@ public interface TokenRepository extends CrudRepository<Token,Long> {
|
||||
|
||||
Token getByToken(String token);
|
||||
|
||||
Iterable<Token> getByUser(User user);
|
||||
|
||||
ArrayList <Token> getByUserOrderByExpirationDate(User user);
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package ovh.herisson.Clyde.Repositories;
|
||||
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
import ovh.herisson.Clyde.Tables.UserCurriculum;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface UserCurriculumRepository extends CrudRepository<UserCurriculum, Long> {
|
||||
|
||||
@Query("select uc.curriculum from UserCurriculum uc where uc.user = ?1")
|
||||
Curriculum findByUser(User student);
|
||||
|
||||
@Query("select distinct uc.user from UserCurriculum uc where uc.curriculum = ?1")
|
||||
Iterable<User> findUsersByCurriculum(Curriculum curriculum);
|
||||
|
||||
ArrayList<UserCurriculum> findByUserOrderByCurriculum(User student);
|
||||
UserCurriculum findByUserAndCurriculumAndActual(User user, Curriculum curriculum, boolean actual);
|
||||
|
||||
ArrayList<UserCurriculum> findByUserAndActual(User user, boolean actual);
|
||||
}
|
@ -4,15 +4,20 @@ import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface UserRepository extends CrudRepository<User, Long> {
|
||||
|
||||
User findById(long id);
|
||||
|
||||
User findByEmail(String email);
|
||||
|
||||
/**
|
||||
@Query(value = "select a.* from Users a ",nativeQuery = true)
|
||||
Iterable<User> findAllUsers();**/
|
||||
|
||||
|
||||
@Query("select u from User u where u.role = ovh.herisson.Clyde.Tables.Role.Teacher")
|
||||
Iterable<User> findAllTeachers();
|
||||
|
||||
@Query("select u from User u where u.role = ovh.herisson.Clyde.Tables.Role.Student")
|
||||
Iterable<User> findAllStudents();
|
||||
|
||||
@Query("select u from User u where u.role <> ovh.herisson.Clyde.Tables.Role.Admin")
|
||||
Iterable<User> findAllExceptAdmins();
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.EndPoints.LoginController;
|
||||
import ovh.herisson.Clyde.Repositories.InscriptionRepository;
|
||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.Token;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
import ovh.herisson.Clyde.Services.Inscription.InscriptionService;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ -26,7 +24,6 @@ public class AuthenticatorService {
|
||||
return tokenService.getUserFromToken(token);
|
||||
}
|
||||
|
||||
|
||||
public String login(String identifier, String password, Date expirationDate){
|
||||
User user = userService.getUser(identifier);
|
||||
if (user == null){return null;}
|
||||
@ -36,7 +33,23 @@ public class AuthenticatorService {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void register(InscriptionRequest inscriptionRequest) {
|
||||
inscriptionService.save(inscriptionRequest);
|
||||
public InscriptionRequest register(InscriptionRequest inscriptionRequest) {
|
||||
inscriptionRequest.setState(RequestState.Pending);
|
||||
return inscriptionService.save(inscriptionRequest);
|
||||
}
|
||||
|
||||
public boolean isNotIn(Role[] roles, String token){
|
||||
if (token == null)
|
||||
return true;
|
||||
|
||||
User poster = getUserFromToken(token);
|
||||
if (poster == null) return true;
|
||||
|
||||
for (Role r:roles){
|
||||
if (poster.getRole() == r)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,9 @@ package ovh.herisson.Clyde.Services;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class CourseService {
|
||||
@ -13,11 +16,68 @@ public class CourseService {
|
||||
this.courseRepo = courseRepo;
|
||||
}
|
||||
|
||||
public void save(Course course){
|
||||
courseRepo.save(course);
|
||||
public Course save(Course course){
|
||||
if (course.getOwner().getRole() != Role.Teacher)
|
||||
return null;
|
||||
return courseRepo.save(course);
|
||||
}
|
||||
|
||||
public Course findById(long id){
|
||||
return courseRepo.findById(id);
|
||||
}
|
||||
|
||||
|
||||
public Iterable<Course> findAll() {
|
||||
return courseRepo.findAll();
|
||||
}
|
||||
|
||||
|
||||
public Iterable<Course> findOwnedCourses(User userFromToken) {
|
||||
return courseRepo.findAllOwnedCoures(userFromToken);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean modifyData(long id, Map<String, Object> updates, Role role) {
|
||||
Course target = courseRepo.findById(id);
|
||||
|
||||
if (target == null)
|
||||
return false;
|
||||
|
||||
if (role == Role.Teacher){
|
||||
for (Map.Entry<String, Object> entry : updates.entrySet()){
|
||||
if (entry.getKey().equals("title")){
|
||||
target.setTitle((String) entry.getValue());
|
||||
courseRepo.save(target);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (role != Role.Secretary)
|
||||
return false;
|
||||
|
||||
for (Map.Entry<String ,Object> entry: updates.entrySet()){
|
||||
switch (entry.getKey()){
|
||||
case "title":
|
||||
target.setTitle((String) entry.getValue());
|
||||
break;
|
||||
case "credits":
|
||||
target.setCredits((Integer) entry.getValue());
|
||||
break;
|
||||
case "owner":
|
||||
if (((User) entry.getValue() ).getRole() != Role.Teacher)
|
||||
break;
|
||||
|
||||
target.setOwner((User) entry.getValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
courseRepo.save(target);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void delete(Course course) {
|
||||
courseRepo.delete(course);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,97 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
||||
import ovh.herisson.Clyde.Repositories.CurriculumCourseRepository;
|
||||
import ovh.herisson.Clyde.Repositories.CurriculumRepository;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class CurriculumCourseService {
|
||||
|
||||
private final CurriculumCourseRepository curriculumCourseRepo;
|
||||
|
||||
private final CourseRepository courseRepo;
|
||||
|
||||
private final CurriculumRepository curriculumRepo;
|
||||
|
||||
public CurriculumCourseService(CurriculumCourseRepository curriculumCourseRepository, CourseRepository courseRepo, CurriculumRepository curriculumRepo) {
|
||||
this.curriculumCourseRepo = curriculumCourseRepository;
|
||||
this.courseRepo = courseRepo;
|
||||
this.curriculumRepo = curriculumRepo;
|
||||
}
|
||||
|
||||
public void save(CurriculumCourse curriculumCourse){
|
||||
curriculumCourseRepo.save(curriculumCourse);
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Object> getDepthCurriculum(Curriculum curriculum){
|
||||
|
||||
if (curriculum == null)
|
||||
return null;
|
||||
|
||||
HashMap<String ,Object> toReturn = new HashMap<>();
|
||||
ArrayList<Map<String ,Object>> courses = new ArrayList<>();
|
||||
Iterable<Course> foundCourses = curriculumCourseRepo.findCoursesByCurriculum(curriculum);
|
||||
|
||||
for (Course c: foundCourses){
|
||||
courses.add(ProtectionService.courseWithoutPassword(c));
|
||||
}
|
||||
toReturn.put("courses",courses);
|
||||
toReturn.put("curriculumId", curriculum.getCurriculumId());
|
||||
toReturn.put("year", curriculum.getYear());
|
||||
toReturn.put("option", curriculum.getOption());
|
||||
toReturn.put("requireCertificate", curriculum.isRequireCertificate());
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public Iterable<Curriculum> findCurriculumByCourses(Course course){
|
||||
return curriculumCourseRepo.findCurriculumByCourses(course);
|
||||
}
|
||||
|
||||
public Iterable<Map<String, Object>> getAllDepthCurriculum(){
|
||||
|
||||
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
||||
|
||||
for (Curriculum curriculum : curriculumRepo.findAll()){
|
||||
toReturn.add(getDepthCurriculum(curriculum));
|
||||
}
|
||||
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/** tries to add all courses to the curriculum
|
||||
*
|
||||
* @param coursesIds the ids of the courses to be added
|
||||
* @param curriculum the curriculum to add the courses to
|
||||
* @return if the changes were made
|
||||
*/
|
||||
public boolean saveAll(Iterable<Long> coursesIds, Curriculum curriculum) {
|
||||
|
||||
if (curriculum == null || coursesIds == null)
|
||||
return false;
|
||||
|
||||
ArrayList<Course> toAdd = new ArrayList<>();
|
||||
for (Long courseId : coursesIds){
|
||||
|
||||
Course course = courseRepo.findById((long) courseId);
|
||||
if (course == null)
|
||||
return false;
|
||||
|
||||
if (!toAdd.contains(course))
|
||||
toAdd.add(course);
|
||||
}
|
||||
|
||||
for (Course course : toAdd){
|
||||
curriculumCourseRepo.save(new CurriculumCourse(curriculum,course));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.CurriculumRepository;
|
||||
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||
|
||||
@Service
|
||||
public class CurriculumService {
|
||||
|
||||
private final CurriculumRepository curriculumRepo;
|
||||
|
||||
public CurriculumService(CurriculumRepository curriculumRepo){
|
||||
this.curriculumRepo = curriculumRepo;
|
||||
}
|
||||
public Curriculum save(Curriculum curriculum){
|
||||
return curriculumRepo.save(curriculum);
|
||||
}
|
||||
public Curriculum findById(long id){
|
||||
return curriculumRepo.findById(id);
|
||||
}
|
||||
public void delete(Curriculum curriculum) {
|
||||
curriculumRepo.delete(curriculum);
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
||||
import ovh.herisson.Clyde.Repositories.CursusCourseRepository;
|
||||
import ovh.herisson.Clyde.Repositories.CursusRepository;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.Cursus;
|
||||
import ovh.herisson.Clyde.Tables.CursusCourse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class CursusCourseService {
|
||||
|
||||
private final CursusCourseRepository cursusCourseRepo;
|
||||
|
||||
private final CourseRepository courseRepo;
|
||||
|
||||
private final CursusRepository cursusRepo;
|
||||
|
||||
public CursusCourseService(CursusCourseRepository cursusCourseRepo, CourseRepository courseRepo, CursusRepository cursusRepo) {
|
||||
this.cursusCourseRepo = cursusCourseRepo;
|
||||
this.courseRepo = courseRepo;
|
||||
this.cursusRepo = cursusRepo;
|
||||
}
|
||||
|
||||
public void save(CursusCourse cursusCourse){
|
||||
cursusCourseRepo.save(cursusCourse);
|
||||
}
|
||||
|
||||
public Iterable<CursusCourse> findAll(){
|
||||
return cursusCourseRepo.findAll();
|
||||
}
|
||||
|
||||
|
||||
public Map<String, Object> getDepthCursus(Cursus cursus){
|
||||
|
||||
HashMap<String ,Object> toReturn = new HashMap<>();
|
||||
ArrayList<Course> courses = new ArrayList<>();
|
||||
for (Course c: cursusCourseRepo.findCoursesByCursus(cursus)){
|
||||
courses.add(c);
|
||||
}
|
||||
toReturn.put("courses",courses);
|
||||
toReturn.put("cursusId",cursus.getCursusId());
|
||||
toReturn.put("year",cursus.getYear());
|
||||
toReturn.put("option",cursus.getOption());
|
||||
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public Iterable<Map<String, Object>> getAllDepthCursus(){
|
||||
|
||||
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
||||
|
||||
for (Cursus cursus : cursusCourseRepo.findDistinctCursuses()){
|
||||
toReturn.add(getDepthCursus(cursus));
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
||||
import ovh.herisson.Clyde.Repositories.CursusRepository;
|
||||
import ovh.herisson.Clyde.Tables.Cursus;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class CursusService {
|
||||
|
||||
|
||||
private final CursusRepository cursusRepo;
|
||||
|
||||
private final CourseRepository courseRepo;
|
||||
|
||||
public CursusService(CursusRepository cursusRepo, CourseRepository courseRepo){
|
||||
this.cursusRepo = cursusRepo;
|
||||
this.courseRepo = courseRepo;
|
||||
}
|
||||
|
||||
|
||||
public void save(Cursus cursus){
|
||||
cursusRepo.save(cursus);
|
||||
}
|
||||
|
||||
public Cursus findById(long id){
|
||||
return cursusRepo.findById(id);
|
||||
}
|
||||
|
||||
public Iterable<Cursus> findAll(){
|
||||
return cursusRepo.findAll();
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
package ovh.herisson.Clyde.Services.Inscription;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.*;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.InscriptionRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.MinervalRepository;
|
||||
import ovh.herisson.Clyde.Services.UserService;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.ExternalCurriculum;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.Minerval;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
||||
@Service
|
||||
public class InscriptionService {
|
||||
|
||||
private final InscriptionRepository inscriptionRepo;
|
||||
|
||||
private final UserRepository userRepo;
|
||||
|
||||
private final UserCurriculumRepository userCurriculumRepo;
|
||||
|
||||
private final CurriculumRepository curriculumRepo;
|
||||
|
||||
private final MinervalRepository minervalRepository;
|
||||
private final ExternalCurriculumRepository externalCurriculumRepository;
|
||||
private final UserService userService;
|
||||
|
||||
public InscriptionService(InscriptionRepository inscriptionRepo, UserRepository userRepo, UserCurriculumRepository userCurriculumRepo, CurriculumRepository curriculumRepo, MinervalRepository minervalRepository, ExternalCurriculumRepository externalCurriculumRepository, UserService userService){
|
||||
this.inscriptionRepo = inscriptionRepo;
|
||||
this.userRepo = userRepo;
|
||||
this.userCurriculumRepo = userCurriculumRepo;
|
||||
this.curriculumRepo = curriculumRepo;
|
||||
this.minervalRepository = minervalRepository;
|
||||
this.externalCurriculumRepository = externalCurriculumRepository;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
public InscriptionRequest save(InscriptionRequest inscriptionRequest){
|
||||
return inscriptionRepo.save(inscriptionRequest);
|
||||
}
|
||||
|
||||
public InscriptionRequest getById(long id){
|
||||
return inscriptionRepo.findById(id);
|
||||
}
|
||||
|
||||
public Iterable<InscriptionRequest> getAll(){
|
||||
return inscriptionRepo.findAll();
|
||||
}
|
||||
|
||||
public boolean modifyState(long id, RequestState requestState) {
|
||||
InscriptionRequest inscrRequest = getById(id);
|
||||
|
||||
if (inscrRequest == null)
|
||||
return false;
|
||||
|
||||
//If the request is already accepted we just return ok (otherwise we would duplicate the procedure below)
|
||||
if (inscrRequest.getState() == RequestState.Accepted){
|
||||
return true;
|
||||
}
|
||||
|
||||
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(),
|
||||
inscrRequest.getIdentityCard()
|
||||
);
|
||||
|
||||
userService.save(userFromRequest);
|
||||
Calendar c = Calendar.getInstance();
|
||||
userCurriculumRepo.save(new UserCurriculum(userFromRequest, curriculumRepo.findById(inscrRequest.getCurriculumId()),c.get(Calendar.YEAR), true));
|
||||
|
||||
//Create a minerval for the new student
|
||||
Minerval minerval = new Minerval(userFromRequest.getRegNo(), 0, 852, 2023);
|
||||
minervalRepository.save(minerval);
|
||||
|
||||
//Assign the externals curriculums from the inscription request to newly created student
|
||||
ArrayList<ExternalCurriculum> extCurrList = externalCurriculumRepository.getExternalCurriculumByInscriptionRequest(inscrRequest);
|
||||
for (int i = 0; i < extCurrList.size(); i++){
|
||||
extCurrList.get(i).setUser(userFromRequest);
|
||||
externalCurriculumRepository.save(extCurrList.get(i));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public void delete(InscriptionRequest toDelete) {
|
||||
inscriptionRepo.delete(toDelete);
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.InscriptionRepository;
|
||||
import ovh.herisson.Clyde.Tables.InscriptionRequest;
|
||||
import ovh.herisson.Clyde.Tables.RequestState;
|
||||
|
||||
@Service
|
||||
public class InscriptionService {
|
||||
|
||||
InscriptionRepository inscriptionRepo;
|
||||
|
||||
public InscriptionService(InscriptionRepository inscriptionRepo){
|
||||
this.inscriptionRepo = inscriptionRepo;
|
||||
}
|
||||
|
||||
public void save(InscriptionRequest inscriptionRequest){
|
||||
inscriptionRepo.save(inscriptionRequest);
|
||||
}
|
||||
|
||||
public InscriptionRequest getById(long id){
|
||||
return inscriptionRepo.findById(id);
|
||||
}
|
||||
|
||||
public Iterable<InscriptionRequest> getAll(){
|
||||
return inscriptionRepo.findAll();
|
||||
}
|
||||
|
||||
public void modifyState(long id, RequestState requestState) {
|
||||
InscriptionRequest inscriptionRequest = getById(id);
|
||||
inscriptionRequest.setState(requestState);
|
||||
save(inscriptionRequest);
|
||||
}
|
||||
}
|
@ -0,0 +1,177 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
/******************************************************
|
||||
* @file LeessonRequestService.java
|
||||
* @author William Karpinski
|
||||
* @scope Extension Horaire
|
||||
******************************************************/
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.*;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class LessonRequestService {
|
||||
private final LessonChangesRequestRepository lessonChangesRepo;
|
||||
|
||||
private final UserRepository userRepo;
|
||||
|
||||
private final LessonRepository lessonRepo;
|
||||
|
||||
private final LessonService lessonServ;
|
||||
|
||||
private final ScheduleLessonRepository scheduleLessonRepo;
|
||||
|
||||
private final ScheduleRepository scheduleRepository;
|
||||
|
||||
private final ScheduleLessonService scheduleLessonService;
|
||||
|
||||
private final UserService userServ;
|
||||
|
||||
private final CourseRepository courseRepository;
|
||||
public LessonRequestService(LessonChangesRequestRepository lessonChangesRepo,
|
||||
UserRepository userRepo, LessonRepository lessonRepo,
|
||||
LessonService lessonServ, ScheduleLessonRepository scheduleLessonRepo,
|
||||
ScheduleRepository scheduleRepository, ScheduleLessonService scheduleLessonService,
|
||||
UserService userServ, CourseRepository courseRepository) {
|
||||
this.lessonChangesRepo = lessonChangesRepo;
|
||||
this.userRepo = userRepo;
|
||||
this.lessonRepo = lessonRepo;
|
||||
this.lessonServ = lessonServ;
|
||||
this.scheduleLessonRepo = scheduleLessonRepo;
|
||||
this.scheduleRepository = scheduleRepository;
|
||||
this.scheduleLessonService = scheduleLessonService;
|
||||
this.userServ = userServ;
|
||||
this.courseRepository = courseRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new lesson request
|
||||
*/
|
||||
public LessonChangesRequest save(LessonChangesRequest lessonRequest){
|
||||
return lessonChangesRepo.save(lessonRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find all the requests made by a user
|
||||
*/
|
||||
public Iterable<LessonChangesRequest> findOwnRequests(User user){
|
||||
return lessonChangesRepo.findOwnRequests(user);
|
||||
}
|
||||
public LessonChangesRequest findById(long id){
|
||||
return lessonChangesRepo.findById(id);
|
||||
}
|
||||
/**
|
||||
* Return all the requests
|
||||
*/
|
||||
public Iterable<LessonChangesRequest> getAll(){return lessonChangesRepo.findAll();}
|
||||
|
||||
/**
|
||||
* Create a lesson if a request is accepted
|
||||
*/
|
||||
public boolean modifyCreateRequestState(LessonChangesRequest lessonRequest, RequestState state, String local ){
|
||||
if(lessonRequest == null || state == lessonRequest.getState() || state == null){
|
||||
return false;}
|
||||
if (state == RequestState.Accepted){
|
||||
Course course = courseRepository.findById(lessonRequest.getCourse().getCourseID());
|
||||
if(courseRepository.findById(lessonRequest.getCourse().getCourseID())==null|| local == null){
|
||||
return false;}
|
||||
Lesson lesson = new Lesson();
|
||||
lesson.setCourse(course);
|
||||
lesson.setLessonStart(lessonRequest.getLessonStart());
|
||||
lesson.setLessonEnd(lessonRequest.getLessonEnd());
|
||||
lesson.setColor(lessonRequest.getColor());
|
||||
lesson.setLocal(local);
|
||||
lesson.setLessonType(lessonRequest.getLessonType());
|
||||
|
||||
lesson = lessonRepo.save(lesson);
|
||||
scheduleLessonService.saveToAllSchedule(lesson);
|
||||
}
|
||||
lessonRequest.setState(state);
|
||||
save(lessonRequest);
|
||||
return true;
|
||||
}
|
||||
|
||||
public Iterable<LessonChangesRequest> findRequestByLessonId(long id){
|
||||
return lessonChangesRepo.findRequestByLessonId(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refuse all the lesson request that depends on a certain lesson
|
||||
* Used after the deletion of the lesson
|
||||
*/
|
||||
public void refuseAllByLessonId(long id){
|
||||
Iterable<LessonChangesRequest> toRefuse = findRequestByLessonId(id);
|
||||
for(LessonChangesRequest element : toRefuse)
|
||||
element.setState(RequestState.Refused);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify a lesson if a request is accepted
|
||||
*/
|
||||
public boolean modifyChangeRequestState(Map<String, Object> updates, long lessonId,RequestState state){
|
||||
if(state == RequestState.Accepted){
|
||||
Lesson lesson = lessonServ.findById(lessonId);
|
||||
return lessonServ.modifyData(lesson.getLessonID(),updates);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a lesson if a request is accepted
|
||||
*/
|
||||
public void modifyDeleteRequest(LessonChangesRequest lessonChangesRequest, RequestState state){
|
||||
if(state == RequestState.Accepted){
|
||||
lessonServ.delete(lessonServ.findById(lessonChangesRequest.getLessonId()));
|
||||
refuseAllByLessonId(lessonChangesRequest.getLessonId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a lesson request
|
||||
*/
|
||||
public LessonChangesRequest createLessonRequest(Map<String,Object> lessonInfos) {
|
||||
LessonChangesRequest target = new LessonChangesRequest();
|
||||
|
||||
for (Map.Entry<String, Object> entry : lessonInfos.entrySet()) {
|
||||
System.out.println(entry.toString());
|
||||
if(entry.getValue() != null){
|
||||
switch (entry.getKey()) {
|
||||
case "requestType":
|
||||
target.setRequestType((int) entry.getValue());
|
||||
break;
|
||||
case "lessonStart":
|
||||
target.setLessonStart((String) entry.getValue());
|
||||
break;
|
||||
case "lessonEnd":
|
||||
target.setLessonEnd((String) entry.getValue());
|
||||
break;
|
||||
case "color":
|
||||
target.setColor((String) entry.getValue());
|
||||
break;
|
||||
case "user":
|
||||
target.setUser(userServ.getUserById((int) entry.getValue()));
|
||||
break;
|
||||
case "lessonType":
|
||||
target.setLessonType((String) entry.getValue());
|
||||
break;
|
||||
case "course":
|
||||
target.setCourse(courseRepository.findById((int) entry.getValue()));
|
||||
break;
|
||||
case "lessonId":
|
||||
target.setLessonId((int) entry.getValue());
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
target.setState(RequestState.Pending);
|
||||
return target;
|
||||
}
|
||||
|
||||
public void delete (LessonChangesRequest toDelete) {
|
||||
lessonChangesRepo.delete(toDelete);
|
||||
}
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
|
||||
/******************************************************
|
||||
* @file LessonService.java
|
||||
* @author William Karpinski
|
||||
* @scope Extension Horaire
|
||||
******************************************************/
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.*;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class LessonService {
|
||||
private final LessonRepository lessonRepo;
|
||||
|
||||
private final ScheduleLessonRepository scheduleLessonRepo;
|
||||
private final UserCurriculumRepository userCurriculumRepo;
|
||||
private final UserService userServ;
|
||||
private final CourseRepository courseRepo;
|
||||
private final CurriculumCourseRepository curriculumCourseRepo;
|
||||
public LessonService(LessonRepository lessonRepo, ScheduleLessonRepository scheduleLessonRepo, UserCurriculumRepository userCurriculumRepo, UserService userServ, CourseRepository courseRepo, CurriculumCourseRepository curriculumCourseRepo){
|
||||
this.lessonRepo = lessonRepo;
|
||||
this.scheduleLessonRepo = scheduleLessonRepo;
|
||||
this.userCurriculumRepo = userCurriculumRepo;
|
||||
this.userServ = userServ;
|
||||
this.courseRepo = courseRepo;
|
||||
this.curriculumCourseRepo = curriculumCourseRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a lesson
|
||||
*/
|
||||
public Lesson save(Lesson lesson){
|
||||
return lessonRepo.save(lesson);
|
||||
}
|
||||
/**
|
||||
* Find a lesson by its id
|
||||
*/
|
||||
public Lesson findById(long id){
|
||||
return lessonRepo.findById(id);
|
||||
}
|
||||
/**
|
||||
* Return all the lessons
|
||||
*/
|
||||
public Iterable<Lesson> findAll(){return lessonRepo.findAll();}
|
||||
/**
|
||||
* Return all a teacher's lessons
|
||||
*/
|
||||
public Iterable<Lesson> findAllOwnedLesson(User teacher){
|
||||
ArrayList<Lesson> toReturn = new ArrayList<>();
|
||||
ArrayList<Course> coursesOwned = (ArrayList<Course>) courseRepo.findAllOwnedCoures(teacher);
|
||||
for (Course element : coursesOwned) {
|
||||
for(Lesson lesson : lessonRepo.findLessonByCourse(element))
|
||||
toReturn.add(lesson);
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
/**
|
||||
* Return all a student's lessons
|
||||
*/
|
||||
|
||||
public Iterable<Lesson> findOnesLessons(User student){
|
||||
ArrayList<Lesson> toReturn = new ArrayList<>();
|
||||
ArrayList<Course> courses = new ArrayList<>();
|
||||
ArrayList<UserCurriculum> userCurricula = userCurriculumRepo.findByUserAndActual(student, true);
|
||||
for (UserCurriculum userCurriculum : userCurricula) {
|
||||
curriculumCourseRepo.findCoursesByCurriculum(userCurriculum.getCurriculum()).forEach((item) -> {
|
||||
//We need this to eliminate clones because a course can belong to several curriculums
|
||||
if (!courses.contains(item)) {
|
||||
System.out.println(item.getTitle());
|
||||
courses.add(item);
|
||||
}
|
||||
});
|
||||
}
|
||||
for (Course element : courses) {
|
||||
for(Lesson lesson : lessonRepo.findLessonByCourse(element))
|
||||
toReturn.add(lesson);
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
/**
|
||||
* Construct a new lesson
|
||||
*/
|
||||
public Lesson createLesson(Map<String,Object> lessonInfos) {
|
||||
Lesson target = new Lesson();
|
||||
|
||||
for (Map.Entry<String, Object> entry : lessonInfos.entrySet()) {
|
||||
switch (entry.getKey()) {
|
||||
case "lessonStart":
|
||||
target.setLessonStart((String) entry.getValue());
|
||||
break;
|
||||
case "lessonEnd":
|
||||
target.setLessonEnd((String) entry.getValue());
|
||||
case "color":
|
||||
target.setColor((String) entry.getValue());
|
||||
break;
|
||||
case "local":
|
||||
target.setLocal((String) entry.getValue());
|
||||
break;
|
||||
case "lessonType":
|
||||
target.setLessonType((String) entry.getValue());
|
||||
break;
|
||||
case "courseID":
|
||||
target.setCourse(courseRepo.findById((int) entry.getValue()));
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return target;
|
||||
}
|
||||
/**
|
||||
* Modify a lesson
|
||||
*/
|
||||
public boolean modifyData(long id, Map<String ,Object> updates){
|
||||
Lesson target = lessonRepo.findById(id);
|
||||
|
||||
if(target == null)
|
||||
return false;
|
||||
|
||||
for (Map.Entry<String , Object> entry: updates.entrySet()){
|
||||
switch (entry.getKey()){
|
||||
case "lessonStart":
|
||||
target.setLessonStart((String) entry.getValue());
|
||||
break;
|
||||
case "lessonEnd":
|
||||
target.setLessonEnd((String) entry.getValue());
|
||||
break;
|
||||
case "local":
|
||||
target.setLocal((String) entry.getValue());
|
||||
break;
|
||||
case "lessonType":
|
||||
target.setLessonType((String) entry.getValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
Lesson lesson = lessonRepo.save(target);
|
||||
ScheduleLesson scheduleLesson = scheduleLessonRepo.findByLesson(lesson);
|
||||
Iterable<User> users = userCurriculumRepo.findUsersByCurriculum(scheduleLesson.getSchedule().getCurriculum());
|
||||
for(User user: users){
|
||||
userServ.Notify(user, new Notification("Course modified in the schedule", "Course Modified " + lesson.getCourse().getTitle() , "/#/schedule"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Delete a lesson
|
||||
*/
|
||||
public void delete(Lesson lesson){
|
||||
lessonRepo.delete(lesson);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
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.Services.UserService;
|
||||
import ovh.herisson.Clyde.Tables.Notification;
|
||||
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;
|
||||
@Autowired
|
||||
private UserService userServ;
|
||||
|
||||
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){
|
||||
for(User u: disc.getMembers()){
|
||||
userServ.Notify(u, new Notification("msg.notification.new", msg.getContent(), "/#/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);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package ovh.herisson.Clyde.Services.Msg;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import ovh.herisson.Clyde.Repositories.CourseRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Msg.ForumRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Msg.TopicRepository;
|
||||
import ovh.herisson.Clyde.Services.UserService;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.Notification;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
import ovh.herisson.Clyde.Tables.Msg.Answer;
|
||||
import ovh.herisson.Clyde.Tables.Msg.Forum;
|
||||
import ovh.herisson.Clyde.Tables.Msg.Topic;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class ForumService {
|
||||
|
||||
private UserService userServ;
|
||||
private CourseRepository courseRepo;
|
||||
private ForumRepository forumRepo;
|
||||
private TopicRepository topicRepo;
|
||||
|
||||
public void createForum(Course c, Forum f){
|
||||
c.addForum(f);
|
||||
for (User u: f.getRegister()) {
|
||||
userServ.Notify(u, new Notification("forum.notification.forum.new", f.getName(), "/#/Forum"));
|
||||
}
|
||||
courseRepo.save(c);
|
||||
}
|
||||
|
||||
public void createTopic(Forum f, Topic data) {
|
||||
f.addTopic(data);
|
||||
for (User u: f.getRegister()) {
|
||||
userServ.Notify(u, new Notification("forum.notification.topic.new", data.getSubject(), "/#/Forum"));
|
||||
}
|
||||
forumRepo.save(f);
|
||||
}
|
||||
|
||||
public void answerTopic(Topic t, Answer data, User u) {
|
||||
data.setAuthor(u);
|
||||
t.addAnswer(data);
|
||||
topicRepo.save(t);
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class NotificationService {
|
||||
|
||||
}
|
@ -0,0 +1,161 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
import ovh.herisson.Clyde.Tables.Inscription.InscriptionRequest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProtectionService {
|
||||
|
||||
/** return user's data except password
|
||||
* @param user the user to return
|
||||
* @return all the user data without the password
|
||||
*/
|
||||
public static HashMap<String,Object> userWithoutPassword(User user){
|
||||
|
||||
if (user ==null)
|
||||
return null;
|
||||
|
||||
HashMap<String,Object> toReturn = new HashMap<>();
|
||||
|
||||
toReturn.put("regNo",user.getRegNo());
|
||||
toReturn.put("lastName",user.getLastName());
|
||||
toReturn.put("firstName",user.getFirstName());
|
||||
toReturn.put("email", user.getEmail());
|
||||
toReturn.put("address",user.getAddress());
|
||||
toReturn.put("birthDate",user.getBirthDate());
|
||||
toReturn.put("country",user.getCountry());
|
||||
toReturn.put("profilePictureUrl",user.getProfilePictureUrl());
|
||||
toReturn.put("role",user.getRole());
|
||||
toReturn.put("identityCard", user.getIdentityCardUrl());
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static Iterable<HashMap<String ,Object>>usersWithoutPasswords(Iterable<User> users){
|
||||
ArrayList<HashMap<String,Object>> toReturn = new ArrayList<>();
|
||||
|
||||
for (User u : users){
|
||||
toReturn.add(userWithoutPassword(u));
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static HashMap<String,Object> courseWithoutPassword(Course course){
|
||||
if (course == null)
|
||||
return null;
|
||||
|
||||
HashMap<String ,Object> toReturn = new HashMap<>();
|
||||
|
||||
toReturn.put("courseID",course.getCourseID());
|
||||
toReturn.put("credits",course.getCredits());
|
||||
toReturn.put("title", course.getTitle());
|
||||
toReturn.put("owner", userWithoutPassword(course.getOwner()));
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static Iterable<HashMap<String ,Object>> coursesWithoutPasswords(Iterable<Course> courses){
|
||||
ArrayList<HashMap<String,Object>> toReturn = new ArrayList<>();
|
||||
|
||||
for (Course course: courses){
|
||||
toReturn.add(ProtectionService.courseWithoutPassword(course));
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
|
||||
}
|
||||
|
||||
public static HashMap<String , Object> lessonWithoutPassword(Lesson lesson){
|
||||
if(lesson == null)
|
||||
return null;
|
||||
|
||||
HashMap<String, Object> toReturn = new HashMap<>();
|
||||
|
||||
toReturn.put("lessonID", lesson.getLessonID());
|
||||
toReturn.put("lessonStart", lesson.getLessonStart());
|
||||
toReturn.put("lessonEnd", lesson.getLessonEnd());
|
||||
toReturn.put("course",courseWithoutPassword(lesson.getCourse()));
|
||||
toReturn.put("local",lesson.getLocal());
|
||||
toReturn.put("color", lesson.getColor());
|
||||
toReturn.put("lessonType",lesson.getLessonType());
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static Iterable<HashMap<String ,Object>> lessonsWithoutPassword(Iterable<Lesson> lessons){
|
||||
ArrayList<HashMap<String,Object>> toReturn = new ArrayList<>();
|
||||
|
||||
for (Lesson l: lessons){
|
||||
toReturn.add(ProtectionService.lessonWithoutPassword(l));
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, Object> requestWithoutPassword(InscriptionRequest inscriptionRequest) {
|
||||
|
||||
if (inscriptionRequest == null)
|
||||
return null;
|
||||
|
||||
Map<String, Object> toReturn = new HashMap<>();
|
||||
|
||||
toReturn.put("id", inscriptionRequest.getId());
|
||||
toReturn.put("lastName", inscriptionRequest.getLastName());
|
||||
toReturn.put("firstName", inscriptionRequest.getFirstName());
|
||||
toReturn.put("address", inscriptionRequest.getAddress());
|
||||
toReturn.put("email",inscriptionRequest.getEmail());
|
||||
toReturn.put("birthDate", inscriptionRequest.getBirthDate());
|
||||
toReturn.put("country", inscriptionRequest.getCountry());
|
||||
toReturn.put("curriculum", inscriptionRequest.getCurriculumId());
|
||||
toReturn.put("state", inscriptionRequest.getState());
|
||||
toReturn.put("profilePictureUrl", inscriptionRequest.getProfilePicture());
|
||||
toReturn.put("identityCard", inscriptionRequest.getIdentityCard());
|
||||
toReturn.put("submissionDate", inscriptionRequest.getSubmissionDate());
|
||||
toReturn.put("equivalenceState", inscriptionRequest.getEquivalenceState());
|
||||
toReturn.put("admissionDocUrl", inscriptionRequest.getAdmissionDocUrl());
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static Map<String, Object> lessonRequestWithoutPassword(LessonChangesRequest lessonRequest){
|
||||
if (lessonRequest == null)
|
||||
return null;
|
||||
Map<String, Object> toReturn = new HashMap<>();
|
||||
toReturn.put("id", lessonRequest.getId());
|
||||
toReturn.put("lessonStart", lessonRequest.getLessonStart());
|
||||
toReturn.put("lessonEnd", lessonRequest.getLessonEnd());
|
||||
toReturn.put("lessonType",lessonRequest.getLessonType());
|
||||
toReturn.put("course", courseWithoutPassword(lessonRequest.getCourse()));
|
||||
toReturn.put("user", userWithoutPassword(lessonRequest.getUser()));
|
||||
toReturn.put("requestType", lessonRequest.getRequestType());
|
||||
toReturn.put("state", lessonRequest.getState());
|
||||
toReturn.put("lessonId",lessonRequest.getLessonId());
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public static Iterable<Map<String, Object>> lessonRequestsWithoutPassword(Iterable<LessonChangesRequest> lessonChangesRequests){
|
||||
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
||||
|
||||
for(LessonChangesRequest lessonChangeRequest: lessonChangesRequests){
|
||||
toReturn.add(lessonRequestWithoutPassword(lessonChangeRequest));
|
||||
}
|
||||
return toReturn;
|
||||
|
||||
}
|
||||
public static Iterable<Map<String ,Object>> requestsWithoutPasswords(Iterable<InscriptionRequest> inscriptionRequests){
|
||||
|
||||
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
||||
|
||||
for (InscriptionRequest i:inscriptionRequests){
|
||||
toReturn.add(requestWithoutPassword(i));
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,105 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
/******************************************************
|
||||
* @file ScheduleLessonService.java
|
||||
* @author William Karpinski
|
||||
* @scope Extension Horaire
|
||||
******************************************************/
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.LessonRepository;
|
||||
import ovh.herisson.Clyde.Repositories.ScheduleLessonRepository;
|
||||
import ovh.herisson.Clyde.Repositories.ScheduleRepository;
|
||||
import ovh.herisson.Clyde.Repositories.UserCurriculumRepository;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class ScheduleLessonService {
|
||||
|
||||
private final ScheduleLessonRepository scheduleLessonRepo;
|
||||
|
||||
private final UserCurriculumRepository userCurriculumRepo;
|
||||
private final UserService userServ;
|
||||
private final LessonRepository lessonRepo;
|
||||
private final ScheduleRepository scheduleRepo;
|
||||
public ScheduleLessonService(ScheduleLessonRepository scheduleLessonRepo, UserCurriculumRepository userCurriculumRepo, UserService userServ, LessonRepository lessonRepo, ScheduleRepository scheduleRepo) {
|
||||
this.scheduleLessonRepo = scheduleLessonRepo;
|
||||
this.userCurriculumRepo = userCurriculumRepo;
|
||||
this.userServ = userServ;
|
||||
this.lessonRepo = lessonRepo;
|
||||
this.scheduleRepo = scheduleRepo;
|
||||
}
|
||||
public boolean save(ScheduleLesson scheduleLesson){
|
||||
if(scheduleLesson == null)
|
||||
return false;
|
||||
scheduleLessonRepo.save(scheduleLesson);
|
||||
Iterable<User> users = userCurriculumRepo.findUsersByCurriculum(scheduleLesson.getSchedule().getCurriculum());
|
||||
for(User user: users){
|
||||
userServ.Notify(user, new Notification("New course in the schedule", "Course added " + scheduleLesson.getLesson().getCourse().getTitle(), "/#/schedule"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Save a lesson to all the schedule it is linked
|
||||
*/
|
||||
public void saveToAllSchedule(Lesson lesson){
|
||||
Iterable<Schedule> schedules = scheduleRepo.findAllLessonSchedule(lesson.getCourse());
|
||||
if(schedules == null)
|
||||
return;
|
||||
for (Schedule schedule : schedules){
|
||||
save(new ScheduleLesson(schedule, lesson));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Delete a scheduleLesson via its lesson
|
||||
*/
|
||||
public boolean delete(long lessonId){
|
||||
if(lessonId == 0)
|
||||
return false;
|
||||
ScheduleLesson scheduleLesson = scheduleLessonRepo.findByLesson(lessonRepo.findById(lessonId));
|
||||
Iterable<User> users = userCurriculumRepo.findUsersByCurriculum(scheduleLesson.getSchedule().getCurriculum());
|
||||
for(User user: users){
|
||||
userServ.Notify(user, new Notification("Course deleted in the schedule","Course deleted " + scheduleLesson.getLesson().getCourse().getTitle(), "/#/schedule"));
|
||||
}
|
||||
scheduleLessonRepo.delete(lessonRepo.findById(lessonId));
|
||||
return true;
|
||||
}
|
||||
|
||||
public Schedule getScheduleByCurriculum(Curriculum curriculum){
|
||||
return scheduleLessonRepo.findScheduleByCurriculum(curriculum);
|
||||
}
|
||||
/**
|
||||
* Return a schedule and the list of lessons that corresponds
|
||||
*/
|
||||
public Map<String , Object> getDepthScheduleBySchedule(Schedule schedule){
|
||||
if(schedule == null)
|
||||
return null;
|
||||
|
||||
HashMap<String , Object> toReturn = new HashMap<>();
|
||||
ArrayList<Map<String, Object>> lessons = new ArrayList<>();
|
||||
Iterable<Lesson> foundLessons = scheduleLessonRepo.findLessonByCurriculum(schedule.getCurriculum());
|
||||
|
||||
for (Lesson l: foundLessons){
|
||||
lessons.add(ProtectionService.lessonWithoutPassword(l));
|
||||
}
|
||||
toReturn.put("lessons",lessons);
|
||||
toReturn.put("scheduleId" , schedule.getScheduleID());
|
||||
toReturn.put("curriculum", schedule.getCurriculum());
|
||||
return toReturn;
|
||||
}
|
||||
/**
|
||||
* Return all the schedules
|
||||
*/
|
||||
public Iterable<Map<String,Object>> getAllSchedule(){
|
||||
ArrayList<Map<String,Object>> toReturn = new ArrayList<>();
|
||||
|
||||
for (Schedule schedule: scheduleRepo.findAll()){
|
||||
toReturn.add(getDepthScheduleBySchedule(schedule));
|
||||
}
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.ScheduleRepository;
|
||||
import ovh.herisson.Clyde.Tables.Schedule;
|
||||
|
||||
@Service
|
||||
public class ScheduleService {
|
||||
private final ScheduleRepository scheduleRepo;
|
||||
public ScheduleService(ScheduleRepository scheduleRepo) {
|
||||
this.scheduleRepo = scheduleRepo;
|
||||
}
|
||||
public Schedule save(Schedule schedule){
|
||||
return scheduleRepo.save(schedule);
|
||||
}
|
||||
public Schedule findById(long id){
|
||||
return scheduleRepo.getById(id);
|
||||
}
|
||||
public void delete(Schedule schedule){
|
||||
scheduleRepo.delete(schedule);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,178 @@
|
||||
package ovh.herisson.Clyde.Services.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file ResearchesService.java
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Service for managing researcher and researches
|
||||
******************************************************/
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearchRepository;
|
||||
import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearcherRepository;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.*;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ResearchesService {
|
||||
|
||||
private final ResearcherRepository researcherRepo;
|
||||
private final ResearchRepository articleRepo;
|
||||
|
||||
|
||||
// researches Part
|
||||
public Research getResearchById(long id) {
|
||||
return articleRepo.findById(id);
|
||||
}
|
||||
|
||||
public Research getResearchByUrl(String url) {
|
||||
return articleRepo.findByPdfLocation(url);
|
||||
}
|
||||
|
||||
|
||||
public Iterable<Research> getResearchesByAuthor(long authorId){
|
||||
Researcher researcher = researcherRepo.findById(authorId);
|
||||
if (researcher == null) return null;
|
||||
|
||||
return researcherRepo.findAllByAuthorId(researcher);
|
||||
}
|
||||
|
||||
public Research saveResearch(Research research) {
|
||||
return articleRepo.save(research);
|
||||
}
|
||||
|
||||
public void modifyResearchData(Research research, Map<String, Object> updates) {
|
||||
for (Map.Entry<String, Object> entry : updates.entrySet()){
|
||||
switch (entry.getKey()){
|
||||
case "title":
|
||||
research.setTitle((String) entry.getValue());
|
||||
break;
|
||||
case "paperType":
|
||||
research.setPaperType((PaperType) entry.getValue());
|
||||
break;
|
||||
case "language":
|
||||
research.setLanguage((String) entry.getValue());
|
||||
break;
|
||||
case "domain":
|
||||
research.setDomain((String) entry.getValue());
|
||||
break;
|
||||
case "summary":
|
||||
research.setSummary((String) entry.getValue());
|
||||
break;
|
||||
case "access":
|
||||
research.setAccess(Access.valueOf((String) entry.getValue()));
|
||||
break;
|
||||
case "coAuthors":
|
||||
Set<Researcher> set = new HashSet<>();
|
||||
|
||||
for (int id : (List<Integer>) entry.getValue()) {
|
||||
|
||||
Researcher r = researcherRepo.findById(id);
|
||||
if (r != null){
|
||||
set.add(r);
|
||||
}
|
||||
}
|
||||
research.setCoAuthors(set);
|
||||
break;
|
||||
}
|
||||
}
|
||||
articleRepo.save(research);
|
||||
}
|
||||
|
||||
public void deleteResearch(Research research) {
|
||||
articleRepo.delete(research);
|
||||
}
|
||||
|
||||
|
||||
// Researchers Part
|
||||
public Researcher getResearcherByUser(User user){
|
||||
return researcherRepo.findByUser(user);
|
||||
}
|
||||
|
||||
public Iterable<Research> getAllResearches() {
|
||||
return articleRepo.findAll();
|
||||
}
|
||||
|
||||
public Researcher saveResearcher(Researcher researcher) {
|
||||
|
||||
if (researcherRepo.findByUser(researcher.getUser()) != null) return null;
|
||||
return researcherRepo.save(researcher);
|
||||
}
|
||||
|
||||
public Iterable<Researcher> getAllResearchers() {
|
||||
return researcherRepo.findAll();
|
||||
}
|
||||
|
||||
public Researcher getResearcherById(long id) {
|
||||
return researcherRepo.findById(id);
|
||||
}
|
||||
|
||||
public void deleteResearcher(Researcher researcher) {
|
||||
articleRepo.findAll();
|
||||
for (Research r: articleRepo.findAll())
|
||||
{
|
||||
if (r.getCoAuthors().contains(researcher)){
|
||||
r.getCoAuthors().remove(researcher);
|
||||
articleRepo.save(r);
|
||||
}
|
||||
}
|
||||
researcherRepo.delete(researcher);
|
||||
}
|
||||
|
||||
public void modifyResearcherData(Researcher researcher, Map<String, Object> updates) {
|
||||
|
||||
for (Map.Entry<String, Object> entry : updates.entrySet()){
|
||||
switch (entry.getKey()){
|
||||
case "orcidId":
|
||||
if (entry.getValue() != null)
|
||||
researcher.setOrcidId((String) entry.getValue());
|
||||
break;
|
||||
case "domain":
|
||||
if (entry.getValue() != null)
|
||||
researcher.setDomain((String) entry.getValue());
|
||||
break;
|
||||
case "site":
|
||||
if (entry.getValue() != null)
|
||||
researcher.setSite((String) entry.getValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
researcherRepo.save(researcher);
|
||||
}
|
||||
// Other stuff
|
||||
|
||||
public Research addView(Research research) {
|
||||
research.setViews(research.getViews()+1);
|
||||
return articleRepo.save(research);
|
||||
}
|
||||
|
||||
public boolean hasNoAccessTo(Research research, User user){
|
||||
if (research.getAccess() == Access.OpenSource) return false; // if the access is open source even non-users can see it
|
||||
if (user == null) return true; // else you need at least to be a user
|
||||
|
||||
if (user.getRole() == Role.Admin) return false;
|
||||
|
||||
|
||||
Researcher researcher = getResearcherByUser(user);
|
||||
if (researcher !=null ){
|
||||
if (research.getAuthor().getId() == researcher.getId())
|
||||
return false;
|
||||
|
||||
for (Researcher coAuthor: research.getCoAuthors()){
|
||||
if (coAuthor.getId() == researcher.getId())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return research.getAccess() != Access.Restricted || (user.getRole() != Role.Secretary &&
|
||||
user.getRole() != Role.Teacher && user.getRole() != Role.InscriptionService);
|
||||
// if the access is restricted only the staff member (above) can access the research
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package ovh.herisson.Clyde.Services.ScientificPublications;
|
||||
|
||||
/******************************************************
|
||||
* @file StatisticsService
|
||||
* @author Bartha Maxime
|
||||
* @scope Publications Scientifiques
|
||||
*
|
||||
* Service for managing statistics
|
||||
******************************************************/
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.ScientificPublications.ResearchRepository;
|
||||
import ovh.herisson.Clyde.Repositories.ScientificPublications.StatsRepository;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Research;
|
||||
import ovh.herisson.Clyde.Tables.ScientificPublications.Researcher;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class StatisticsService {
|
||||
|
||||
|
||||
private ResearchRepository articleRepo;
|
||||
private StatsRepository statsRepo;
|
||||
|
||||
|
||||
public Iterable<Iterable<Map<String, Integer>>> generateStats(Researcher researcher){
|
||||
|
||||
Iterable<Research> researches = articleRepo.findByAuthor(researcher);
|
||||
|
||||
if (researches == null) return null;
|
||||
|
||||
|
||||
ArrayList<Iterable<Map<String,Integer>>> toReturn = new ArrayList<>();
|
||||
|
||||
toReturn.add(statsRepo.viewsByYears(researcher.getId()));
|
||||
toReturn.add(statsRepo.viewsByMonths(researcher.getId()));
|
||||
toReturn.add(statsRepo.viewsByTopics(researcher.getId()));
|
||||
|
||||
toReturn.add(statsRepo.researchesByYears(researcher.getId()));
|
||||
toReturn.add(statsRepo.researchesByMonth(researcher.getId()));
|
||||
toReturn.add(statsRepo.researchesByTopics(researcher.getId()));
|
||||
|
||||
toReturn.add(statsRepo.languageByYears(researcher.getId()));
|
||||
toReturn.add(statsRepo.languageByMonths(researcher.getId()));
|
||||
toReturn.add(statsRepo.languageByTopics(researcher.getId()));
|
||||
return toReturn;
|
||||
}
|
||||
}
|
@ -4,10 +4,8 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import ovh.herisson.Clyde.Repositories.FileRepository;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
@ -17,8 +15,6 @@ import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class StorageService {
|
||||
|
||||
|
||||
private final Path rootLocation = Paths.get("cdn/");
|
||||
private final FileRepository fileRepo;
|
||||
|
||||
@ -37,6 +33,9 @@ public class StorageService {
|
||||
|
||||
public StorageFile store(MultipartFile file, FileType fileType) {
|
||||
|
||||
if (file == null || file.getOriginalFilename() == null)
|
||||
return null;
|
||||
|
||||
if (file.getOriginalFilename().isEmpty()){return null;}
|
||||
|
||||
UUID uuid = UUID.randomUUID();
|
||||
@ -57,7 +56,7 @@ public class StorageService {
|
||||
String url = this.rootLocation.resolve(Paths.get(Objects.requireNonNull(stringUuid)))
|
||||
.normalize().toString();
|
||||
|
||||
return fileRepo.save(new StorageFile(file.getName(),url, fileType));
|
||||
return fileRepo.save(new StorageFile(file.getOriginalFilename(),url, fileType));
|
||||
}
|
||||
|
||||
public void delete(StorageFile file) throws SecurityException {
|
||||
|
@ -0,0 +1,53 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import ovh.herisson.Clyde.Repositories.TeacherCourseRepository;
|
||||
import ovh.herisson.Clyde.Repositories.UserRepository;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.TeacherCourse;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Controller
|
||||
public class TeacherCourseService {
|
||||
private final TeacherCourseRepository teacherCourseRepo;
|
||||
|
||||
private final UserRepository userRepo;
|
||||
|
||||
public TeacherCourseService(TeacherCourseRepository teacherCourseRepo, UserRepository userRepo) {
|
||||
this.teacherCourseRepo = teacherCourseRepo;
|
||||
this.userRepo = userRepo;
|
||||
}
|
||||
|
||||
public Iterable<User> findCourseAssistants(Course course) {
|
||||
if (course == null)
|
||||
return null;
|
||||
return teacherCourseRepo.findAllAssistantOfCourse(course);
|
||||
}
|
||||
|
||||
|
||||
public boolean saveAll(Iterable<Long> teacherIds, Course course){
|
||||
|
||||
if (course == null || teacherIds == null)
|
||||
return false;
|
||||
|
||||
ArrayList<User> toAdd = new ArrayList<>();
|
||||
for (Long teacherId : teacherIds){
|
||||
User teacher = userRepo.findById((long) teacherId);
|
||||
if ( teacher== null){
|
||||
return false;
|
||||
}
|
||||
if (!toAdd.contains(teacher) && teacher.getRole() == Role.Teacher)
|
||||
{
|
||||
toAdd.add(teacher);
|
||||
}
|
||||
}
|
||||
for (User teacher: toAdd){
|
||||
teacherCourseRepo.save(new TeacherCourse(teacher,course));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -5,16 +5,15 @@ import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.TokenRepository;
|
||||
import ovh.herisson.Clyde.Tables.Token;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
public class TokenService {
|
||||
TokenRepository tokenRepo;
|
||||
private final TokenRepository tokenRepo;
|
||||
|
||||
public TokenService(TokenRepository tokenRepo){
|
||||
this.tokenRepo = tokenRepo;
|
||||
@ -30,13 +29,10 @@ public class TokenService {
|
||||
new SecureRandom().nextBytes(bytes);
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
bytes[i] = (byte) (((bytes[i]+256)%256 %95+ 32));
|
||||
while ((char)bytes[i] == ';'){
|
||||
bytes[i] = new SecureRandom().generateSeed(1)[0];
|
||||
}
|
||||
}
|
||||
// will never end up in the catch because of the way that SecureRandom.nextBytes is implemented
|
||||
try {
|
||||
return new String(bytes,"ISO_8859_1");
|
||||
return new String(Base64.getEncoder().encode(bytes),"ISO_8859_1");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -44,13 +40,16 @@ public class TokenService {
|
||||
|
||||
public User getUserFromToken(String token) {
|
||||
Token tokenRep = tokenRepo.getByToken(token);
|
||||
if (tokenRep == null) return null;
|
||||
if (tokenRep == null)
|
||||
return null;
|
||||
|
||||
return tokenRep.getUser();
|
||||
}
|
||||
|
||||
public void saveToken(Token token){
|
||||
//Si l'utilisateur a déja 5 token delete celui qui devait expirer le plus vite
|
||||
ArrayList<Token> tokenList = tokenRepo.getByUserOrderByExpirationDate(token.getUser());
|
||||
|
||||
while(tokenList.size() >= 5){
|
||||
tokenRepo.delete(tokenList.get(0));
|
||||
tokenList.remove(tokenList.get(0));
|
||||
@ -71,5 +70,5 @@ public class TokenService {
|
||||
tokenRepo.delete(t);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Repositories.CurriculumRepository;
|
||||
import ovh.herisson.Clyde.Repositories.Inscription.ExternalCurriculumRepository;
|
||||
import ovh.herisson.Clyde.Repositories.UserCurriculumRepository;
|
||||
import ovh.herisson.Clyde.Tables.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
@Service
|
||||
public class UserCurriculumService {
|
||||
|
||||
private final UserCurriculumRepository userCurriculumRepository;
|
||||
private final CurriculumRepository curriculumRepo;
|
||||
|
||||
private final ExternalCurriculumRepository externalCurriculumRepo;
|
||||
public UserCurriculumService(UserCurriculumRepository userCurriculumRepository, CurriculumRepository curriculumRepo, ExternalCurriculumRepository externalCurriculumRepo) {
|
||||
this.userCurriculumRepository = userCurriculumRepository;
|
||||
this.curriculumRepo = curriculumRepo;
|
||||
this.externalCurriculumRepo = externalCurriculumRepo;
|
||||
}
|
||||
|
||||
public Curriculum findByUser(User student){
|
||||
return userCurriculumRepository.findByUser(student);
|
||||
}
|
||||
|
||||
public HashMap<String,Object> findAllCurriculumByStudent(User student) {
|
||||
ArrayList<UserCurriculum> list = userCurriculumRepository.findByUserOrderByCurriculum(student);
|
||||
|
||||
ArrayList<HashMap<String, Object>> curriculumlist = new ArrayList<HashMap<String, Object>>();
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
HashMap<String, Object> element = new HashMap<>();
|
||||
Curriculum c = list.get(i).getCurriculum();
|
||||
|
||||
element.put("curriculumId", c.getCurriculumId());
|
||||
element.put("year", c.getYear());
|
||||
element.put("option", c.getOption());
|
||||
element.put("dateyear", list.get(i).getYear());
|
||||
element.put("actual", list.get(i).isActual());
|
||||
|
||||
curriculumlist.add(element);
|
||||
}
|
||||
|
||||
HashMap<String, Object> toReturn = new HashMap<String, Object>();
|
||||
toReturn.put("curriculumList", curriculumlist);
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
public ArrayList<UserCurriculum> findByStudentAndActual(User u, boolean actual){
|
||||
return userCurriculumRepository.findByUserAndActual(u, actual);
|
||||
}
|
||||
}
|
@ -2,7 +2,9 @@ package ovh.herisson.Clyde.Services;
|
||||
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ovh.herisson.Clyde.Tables.RegNoGenerator;
|
||||
import ovh.herisson.Clyde.Repositories.UserRepository;
|
||||
import ovh.herisson.Clyde.Tables.Notification;
|
||||
import ovh.herisson.Clyde.Tables.Role;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
import java.util.*;
|
||||
@ -17,8 +19,15 @@ public class UserService {
|
||||
}
|
||||
|
||||
|
||||
/** return the user identified by th identifier
|
||||
*
|
||||
* @param identifier can be an email or the RegNo
|
||||
* @return the identified user
|
||||
*/
|
||||
public User getUser(String identifier){
|
||||
if (identifier == null) return null;
|
||||
if (identifier == null)
|
||||
return null;
|
||||
|
||||
try {
|
||||
int id = Integer.parseInt(identifier);
|
||||
return userRepo.findById(id);
|
||||
@ -33,61 +42,58 @@ public class UserService {
|
||||
*
|
||||
* @param poster the user wanting to modify target's data
|
||||
* @param updates the changes to be made
|
||||
* @param target the user to update
|
||||
* @param targetId the id of the user to update
|
||||
* @return if the changes were done or not
|
||||
*/
|
||||
public boolean modifyData(User poster, Map<String ,Object> updates, User target){
|
||||
public User modifyData(long targetId, Map<String ,Object> updates, User poster){
|
||||
|
||||
if (poster.getRegNo().equals(target.getRegNo())){
|
||||
for (Map.Entry<String, Object> entry : updates.entrySet()){
|
||||
User target = userRepo.findById(targetId);
|
||||
if (target == null)
|
||||
return null;
|
||||
|
||||
if ( entry.getKey().equals("regNo") || entry.getKey().equals("role")) {return false;}
|
||||
if (!target.getRegNo().equals(poster.getRegNo()) && !(poster.getRole() == Role.Secretary) &&
|
||||
!(poster.getRole() == Role.Admin))
|
||||
return null;
|
||||
|
||||
switch (entry.getKey()){
|
||||
case "firstName":
|
||||
target.setFirstName((String) entry.getValue());
|
||||
break;
|
||||
case "lastName":
|
||||
target.setLastName((String) entry.getValue());
|
||||
break;
|
||||
case "email":
|
||||
target.setEmail((String) entry.getValue());
|
||||
break;
|
||||
case "address":
|
||||
target.setAddress((String) entry.getValue());
|
||||
break;
|
||||
case "country":
|
||||
target.setCountry((String) entry.getValue());
|
||||
break;
|
||||
case "birthDate":
|
||||
target.setBirthDate((Date) entry.getValue());
|
||||
break;
|
||||
case "profilePictureUrl":
|
||||
target.setProfilePictureUrl((String) entry.getValue());
|
||||
break;
|
||||
case "password":
|
||||
target.setPassword(passwordEncoder.encode((String) entry.getValue()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
userRepo.save(target);
|
||||
return true;
|
||||
}
|
||||
// the secretary can change roles (for example if a student becomes a teacher)
|
||||
else if (poster.getRole() == Role.Secretary)
|
||||
{
|
||||
for (Map.Entry<String, Object> entry : updates.entrySet()){
|
||||
|
||||
if ( !entry.getKey().equals("role")) {return false;}
|
||||
|
||||
if (entry.getValue() == Role.Admin){return false;}
|
||||
|
||||
target.setRole((Role) entry.getValue());
|
||||
userRepo.save(target);
|
||||
return true;
|
||||
for (Map.Entry<String, Object> entry : updates.entrySet()){
|
||||
System.out.println(entry.getValue());
|
||||
switch (entry.getKey()){
|
||||
case "firstName":
|
||||
target.setFirstName((String) entry.getValue());
|
||||
break;
|
||||
case "lastName":
|
||||
target.setLastName((String) entry.getValue());
|
||||
break;
|
||||
case "email":
|
||||
target.setEmail((String) entry.getValue());
|
||||
break;
|
||||
case "address":
|
||||
target.setAddress((String) entry.getValue());
|
||||
break;
|
||||
case "country":
|
||||
target.setCountry((String) entry.getValue());
|
||||
break;
|
||||
case "birthDate":
|
||||
target.setBirthDate((Date) entry.getValue());
|
||||
break;
|
||||
case "profilePictureUrl":
|
||||
target.setProfilePictureUrl((String) entry.getValue());
|
||||
break;
|
||||
case "password":
|
||||
target.setPassword((String) entry.getValue());
|
||||
break;
|
||||
case "role":
|
||||
//a user can't change his own role
|
||||
if (poster.getRole()==Role.Secretary || poster.getRole() == Role.Admin){
|
||||
Role wanted = Role.valueOf((String) entry.getValue());
|
||||
if (wanted == Role.Admin && poster.getRole() != Role.Admin)
|
||||
return null;
|
||||
target.setRole(wanted);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
userRepo.save(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
@ -95,12 +101,42 @@ public class UserService {
|
||||
return passwordEncoder.matches(tryingPassword, user.getPassword());
|
||||
}
|
||||
|
||||
public void save(User user){
|
||||
user.setPassword(passwordEncoder.encode(user.getPassword()));
|
||||
userRepo.save(user);
|
||||
public User save(User user){
|
||||
RegNoGenerator.resetCount();
|
||||
return userRepo.save(user);
|
||||
}
|
||||
|
||||
public void saveAll(ArrayList<User> list){
|
||||
//S'assure que le compteur est bien a 0
|
||||
RegNoGenerator.resetCount();
|
||||
userRepo.saveAll(list);
|
||||
}
|
||||
|
||||
public Iterable<User> getAll(){
|
||||
return userRepo.findAll();
|
||||
}
|
||||
}
|
||||
|
||||
public Iterable<User> getAllExceptAdmins(){
|
||||
return userRepo.findAllExceptAdmins();
|
||||
}
|
||||
|
||||
|
||||
public Iterable<User> getAllTeachers (){return userRepo.findAllTeachers();}
|
||||
|
||||
public Iterable<User> getAllStudents(){return userRepo.findAllStudents();}
|
||||
|
||||
|
||||
public User getUserById(long id) {
|
||||
return userRepo.findById(id);
|
||||
}
|
||||
|
||||
public void delete(User user) {
|
||||
userRepo.delete(user);
|
||||
}
|
||||
|
||||
public void Notify(User u, Notification n){
|
||||
n.setUser(u);
|
||||
u.getNotifications().add(n);
|
||||
userRepo.save(u);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
package ovh.herisson.Clyde.Tables;
|
||||
|
||||
public enum Applications {
|
||||
// without any token
|
||||
Login,
|
||||
Schedule,
|
||||
|
||||
// with any token
|
||||
Profile,
|
||||
|
||||
// Students and higher authorization
|
||||
Msg,
|
||||
Forum,
|
||||
Rdv,
|
||||
// teachers authorization
|
||||
|
||||
ManageOwnedLessons,
|
||||
|
||||
// teachers and Secretary authorization
|
||||
ManageCourses,
|
||||
UsersList,
|
||||
|
||||
//Secretary authorization
|
||||
ManageSchedules,
|
||||
LessonRequests,
|
||||
|
||||
// InscriptionService authorization
|
||||
Requests,
|
||||
// profile of a researcher
|
||||
ResearcherProfile,
|
||||
ManageResearcherProfile,
|
||||
|
||||
//the list of all researches (filterable)
|
||||
ListResearches,
|
||||
CreateUser,
|
||||
StudentsList,
|
||||
Payments
|
||||
}
|
@ -1,52 +1,45 @@
|
||||
package ovh.herisson.Clyde.Tables;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import ovh.herisson.Clyde.Tables.Msg.Forum;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Course {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int courseID;
|
||||
private int credits;
|
||||
private String title;
|
||||
private String faculty;
|
||||
|
||||
public Course(int credits, String title, String faculty){
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@OnDelete(action = OnDeleteAction.SET_NULL)
|
||||
@JoinColumn(name = "Users")
|
||||
private User owner;
|
||||
|
||||
//// Extension Messagerie /////
|
||||
@OneToMany(mappedBy = "course", cascade = CascadeType.ALL)
|
||||
private List<Forum> forums;
|
||||
|
||||
public void addForum(Forum f){
|
||||
f.setCourse(this);
|
||||
forums.add(f);
|
||||
}
|
||||
///////////////////////////////
|
||||
|
||||
public Course(int credits, String title, User owner){
|
||||
this.credits = credits;
|
||||
this.title = title;
|
||||
this.faculty = faculty;
|
||||
}
|
||||
|
||||
public Course() {}
|
||||
|
||||
public int getCourseID() {
|
||||
return courseID;
|
||||
}
|
||||
|
||||
public int getCredits() {
|
||||
return credits;
|
||||
}
|
||||
|
||||
public void setCredits(int credits){
|
||||
this.credits = credits;
|
||||
}
|
||||
|
||||
public String getFaculty() {
|
||||
return faculty;
|
||||
}
|
||||
|
||||
public void setFaculty(String faculty){
|
||||
this.faculty = faculty;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title){
|
||||
this.title = title;
|
||||
this.owner = owner;
|
||||
}
|
||||
}
|
||||
|
@ -6,21 +6,25 @@ import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class Cursus {
|
||||
public class Curriculum {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int cursusId;
|
||||
private int curriculumId;
|
||||
private int year;
|
||||
private String option;
|
||||
public Cursus(int year, String option){
|
||||
|
||||
//True if the curriculum need an entry exam
|
||||
private boolean requireCertificate;
|
||||
public Curriculum(int year, String option, boolean requireCertificate){
|
||||
this.year = year;
|
||||
this.option = option;
|
||||
this.requireCertificate = requireCertificate;
|
||||
}
|
||||
|
||||
public Cursus() {}
|
||||
public Curriculum() {}
|
||||
|
||||
public int getCursusId(){
|
||||
return this.cursusId;
|
||||
public int getCurriculumId(){
|
||||
return this.curriculumId;
|
||||
}
|
||||
|
||||
public int getYear(){
|
||||
@ -39,4 +43,11 @@ public class Cursus {
|
||||
this.option = option;
|
||||
}
|
||||
|
||||
public void setRequireCertificate(boolean requireCertificate) {
|
||||
this.requireCertificate = requireCertificate;
|
||||
}
|
||||
|
||||
public boolean isRequireCertificate() {
|
||||
return requireCertificate;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package ovh.herisson.Clyde.Tables;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import org.hibernate.annotations.OnDelete;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
|
||||
@Entity
|
||||
public class CurriculumCourse {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "Curriculum")
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
private Curriculum curriculum;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@OnDelete(action = OnDeleteAction.CASCADE)
|
||||
@JoinColumn(name = "Course")
|
||||
private Course course;
|
||||
|
||||
public CurriculumCourse(Curriculum curriculum, Course course){
|
||||
this.curriculum = curriculum;
|
||||
this.course = course;
|
||||
}
|
||||
|
||||
public CurriculumCourse() {}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Course getCourse() {
|
||||
return course;
|
||||
}
|
||||
|
||||
public void setCourse(Course course){
|
||||
this.course = course;
|
||||
}
|
||||
|
||||
public Curriculum getCurriculum() {
|
||||
return curriculum;
|
||||
}
|
||||
|
||||
public void setCurriculum(Curriculum curriculum) {
|
||||
this.curriculum = curriculum;
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
package ovh.herisson.Clyde.Tables;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
public class CursusCourse {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "Cursus")
|
||||
private Cursus cursus;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "Course")
|
||||
private Course course;
|
||||
|
||||
public CursusCourse(Cursus cursus, Course course){
|
||||
this.cursus = cursus;
|
||||
this.course = course;
|
||||
}
|
||||
|
||||
public CursusCourse() {}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Course getCourse() {
|
||||
return course;
|
||||
}
|
||||
|
||||
public void setCourse(Course course){
|
||||
this.course = course;
|
||||
}
|
||||
|
||||
public Cursus getCursus() {
|
||||
return cursus;
|
||||
}
|
||||
|
||||
public void setCursus(Cursus cursus) {
|
||||
this.cursus = cursus;
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
package ovh.herisson.Clyde.Tables;
|
||||
|
||||
public enum FileType {
|
||||
|
||||
ProfilePicture,
|
||||
|
||||
EducationCertificate
|
||||
EducationCertificate,
|
||||
Research,
|
||||
ResearchBibTex,
|
||||
JustificationDocument,
|
||||
IdentityCard,
|
||||
}
|
||||
|
@ -0,0 +1,98 @@
|
||||
package ovh.herisson.Clyde.Tables.Inscription;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import ovh.herisson.Clyde.Tables.Curriculum;
|
||||
import ovh.herisson.Clyde.Tables.RequestState;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
public class ChangeCurriculumRequest {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="Users")
|
||||
private User user;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "ActualCurriculum")
|
||||
private Curriculum actualCurriculum;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "DestCurriculum")
|
||||
private Curriculum destinationCurriculum;
|
||||
|
||||
private Date date;
|
||||
|
||||
private RequestState state;
|
||||
|
||||
private RequestState teacherApprovalState;
|
||||
public ChangeCurriculumRequest(){}
|
||||
|
||||
public ChangeCurriculumRequest(User user, Curriculum actualCurriculum, Curriculum destinationCurriculum, Date date, RequestState state, RequestState teacherApprovalState){
|
||||
this.user = user;
|
||||
this.actualCurriculum = actualCurriculum;
|
||||
this.destinationCurriculum = destinationCurriculum;
|
||||
this.date = date;
|
||||
this.state = state;
|
||||
this.teacherApprovalState = teacherApprovalState;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
|
||||
public Curriculum getActualCurriculum() {
|
||||
return actualCurriculum;
|
||||
}
|
||||
|
||||
public void setActualCurriculum(Curriculum actualCurriculum) {
|
||||
this.actualCurriculum = actualCurriculum;
|
||||
}
|
||||
|
||||
public Curriculum getDestinationCurriculum() {
|
||||
return destinationCurriculum;
|
||||
}
|
||||
|
||||
public void setDestinationCurriculum(Curriculum destinationCurriculum) {
|
||||
this.destinationCurriculum = destinationCurriculum;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public RequestState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(RequestState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public RequestState getTeacherApprovalState() {
|
||||
return teacherApprovalState;
|
||||
}
|
||||
|
||||
public void setTeacherApprovalState(RequestState teacherApprovalState) {
|
||||
this.teacherApprovalState = teacherApprovalState;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,85 @@
|
||||
package ovh.herisson.Clyde.Tables.Inscription;
|
||||
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import ovh.herisson.Clyde.Tables.Course;
|
||||
import ovh.herisson.Clyde.Tables.RequestState;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
public class ExemptionsRequest {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
@JoinColumn(name = "Users")
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
private User user;
|
||||
|
||||
@JoinColumn(name = "Course")
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
private Course course;
|
||||
private String justifDocument;
|
||||
|
||||
private RequestState state;
|
||||
|
||||
private Date date;
|
||||
|
||||
public ExemptionsRequest(User user, Course course, String justifDocument, RequestState state, Date date){
|
||||
this.user = user;
|
||||
this.course = course;
|
||||
this.justifDocument = justifDocument;
|
||||
this.state = state;
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
|
||||
public ExemptionsRequest(){}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Course getCourse() {
|
||||
return course;
|
||||
}
|
||||
|
||||
public void setCourse(Course course) {
|
||||
this.course = course;
|
||||
}
|
||||
|
||||
public String getJustifDocument() {
|
||||
return justifDocument;
|
||||
}
|
||||
|
||||
public void setJustifDocument(String justifDocument) {
|
||||
this.justifDocument = justifDocument;
|
||||
}
|
||||
|
||||
|
||||
public RequestState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(RequestState state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package ovh.herisson.Clyde.Tables.Inscription;
|
||||
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import ovh.herisson.Clyde.Tables.User;
|
||||
|
||||
//This table stores a student's curriculum from another university
|
||||
@Entity
|
||||
public class ExternalCurriculum {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
//An external curriculum is first linked to an inscription request and when it is accepted and the user is created we link it to the user
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name="InscriptionRequest")
|
||||
private InscriptionRequest inscriptionRequest;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name="Users")
|
||||
private User user;
|
||||
|
||||
private String school;
|
||||
|
||||
private String formation;
|
||||
|
||||
//This string denotes the completion of the external formation or the last year completed by the student in this formation
|
||||
private String completion;
|
||||
|
||||
private int startYear;
|
||||
private int endYear;
|
||||
private String justifdocUrl;
|
||||
|
||||
public ExternalCurriculum(){}
|
||||
|
||||
public ExternalCurriculum(InscriptionRequest ir, String school, String formation, String completion, int startYear, int endYear, String justifdocUrl,User user){
|
||||
this.inscriptionRequest = ir;
|
||||
this.school = school;
|
||||
this.formation = formation;
|
||||
this.completion = completion;
|
||||
this.startYear = startYear;
|
||||
this.endYear = endYear;
|
||||
this.justifdocUrl = justifdocUrl;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public InscriptionRequest getInscriptionRequest() {
|
||||
return inscriptionRequest;
|
||||
}
|
||||
|
||||
public void setInscriptionRequest(InscriptionRequest inscriptionRequest) {
|
||||
this.inscriptionRequest = inscriptionRequest;
|
||||
}
|
||||
|
||||
public String getSchool() {
|
||||
return school;
|
||||
}
|
||||
|
||||
public void setSchool(String school) {
|
||||
this.school = school;
|
||||
}
|
||||
|
||||
public String getFormation() {
|
||||
return formation;
|
||||
}
|
||||
|
||||
public void setFormation(String formation) {
|
||||
this.formation = formation;
|
||||
}
|
||||
|
||||
public String getCompletion(){
|
||||
return completion;
|
||||
}
|
||||
|
||||
public void setCompletion(String completion) {
|
||||
this.completion = completion;
|
||||
}
|
||||
|
||||
public int getStartYear() {
|
||||
return startYear;
|
||||
}
|
||||
|
||||
public void setStartYear(int startYear) {
|
||||
this.startYear = startYear;
|
||||
}
|
||||
|
||||
public int getEndYear() {
|
||||
return endYear;
|
||||
}
|
||||
|
||||
public void setEndYear(int endYear) {
|
||||
this.endYear = endYear;
|
||||
}
|
||||
|
||||
public void setJustifdocUrl(String justifdocUrl) {
|
||||
this.justifdocUrl = justifdocUrl;
|
||||
}
|
||||
|
||||
public String getJustifdocUrl() {
|
||||
return justifdocUrl;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user