1
0
forked from PGL/Clyde
This commit is contained in:
Debucquoy Anthony 2024-04-21 09:46:46 +02:00
parent ecaf5e3df8
commit 0621c6fe68
7 changed files with 31 additions and 90 deletions

View File

@ -13,6 +13,7 @@ import ovh.herisson.Clyde.Tables.UserCurriculum;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
@RestController @RestController
@ -149,13 +150,13 @@ public class CourseController {
//Get all the courses followed by an user //Get all the courses followed by an user
@GetMapping("/usercourses/{userId}") @GetMapping("/usercourses")
public ResponseEntity<ArrayList<Course>> getAllUserCourses(@PathVariable long userId){ public ResponseEntity<List<Course>> getAllUserCourses(@RequestHeader("Authorization") String token){
User u = userService.getUserById(userId); User u = authServ.getUserFromToken(token);
//We get all the actual curriculums of the user //We get all the actual curriculums of the user
ArrayList<UserCurriculum> userCurricula = userCurriculumService.findByStudentAndActual(u, true); List<UserCurriculum> userCurricula = userCurriculumService.findByStudentAndActual(u, true);
ArrayList<Course> toReturn = new ArrayList<>(); List<Course> toReturn = new ArrayList<>();
//We iterate through all the curriculums and we extract the courses //We iterate through all the curriculums and we extract the courses
for (int i = 0; i < userCurricula.size(); i++){ for (int i = 0; i < userCurricula.size(); i++){

View File

@ -110,7 +110,4 @@ public class ForumController {
forumServ.answerTopic(t, data, u); forumServ.answerTopic(t, data, u);
return new ResponseEntity<>(HttpStatus.ACCEPTED); return new ResponseEntity<>(HttpStatus.ACCEPTED);
} }
// TODO: <tonitch> Check if authorization to view a post/forum/...
} }

View File

@ -51,7 +51,7 @@ public class ProtectionService {
HashMap<String ,Object> toReturn = new HashMap<>(); HashMap<String ,Object> toReturn = new HashMap<>();
toReturn.put("courseId",course.getCourseID()); toReturn.put("courseID",course.getCourseID());
toReturn.put("credits",course.getCredits()); toReturn.put("credits",course.getCredits());
toReturn.put("title", course.getTitle()); toReturn.put("title", course.getTitle());
toReturn.put("owner", userWithoutPassword(course.getOwner())); toReturn.put("owner", userWithoutPassword(course.getOwner()));

View File

@ -1,7 +1,9 @@
package ovh.herisson.Clyde.Tables; package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*; import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import ovh.herisson.Clyde.Tables.Msg.Forum; import ovh.herisson.Clyde.Tables.Msg.Forum;
import java.util.List; import java.util.List;
@ -11,6 +13,8 @@ import org.hibernate.annotations.OnDeleteAction;
@Entity @Entity
@Data @Data
@NoArgsConstructor
@AllArgsConstructor
public class Course { public class Course {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
@ -37,34 +41,4 @@ public class Course {
this.title = title; this.title = title;
this.owner = owner; this.owner = owner;
} }
public Course() {}
public int getCourseID() {
return courseID;
}
public int getCredits() {
return credits;
}
public void setCredits(int credits){
this.credits = credits;
}
public String getTitle() {
return title;
}
public void setTitle(String title){
this.title = title;
}
public User getOwner() {
return owner;
}
public void setOwner(User owner) {
this.owner = owner;
}
} }

View File

@ -1,10 +1,17 @@
package ovh.herisson.Clyde.Tables; package ovh.herisson.Clyde.Tables;
import jakarta.persistence.*; import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction; import org.hibernate.annotations.OnDeleteAction;
@Entity @Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserCurriculum { public class UserCurriculum {
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
@ -26,48 +33,10 @@ public class UserCurriculum {
//True if the user has that curriculum at the moment false if not //True if the user has that curriculum at the moment false if not
private boolean actual; private boolean actual;
public UserCurriculum(User user, Curriculum curriculum, int year, boolean actual){ public UserCurriculum(User u, Curriculum cu, int year, boolean actual){
this.user = user; this.user = u;
this.curriculum = curriculum; this.curriculum = cu;
this.year = year; this.year = year;
this.actual = actual; this.actual = actual;
} }
public UserCurriculum() {}
public int getId() {
return id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Curriculum getCurriculum() {
return curriculum;
}
public void setCurriculum(Curriculum curriculum) {
this.curriculum = curriculum;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public void setActual(boolean actual) {
this.actual = actual;
}
public boolean isActual() {
return actual;
}
} }

View File

@ -8,16 +8,16 @@
<script setup> <script setup>
import { ref, reactive } from 'vue' import { ref, reactive } from 'vue'
import i18n from '@/i18n.js' import i18n from '@/i18n.js'
import { getCourses } from '@/rest/courses.js' import { getCourses, getUserActualCourses } from '@/rest/courses.js'
import { ForumsOfCurrentCourse, getForumsOfCourse, createForum } from '@/rest/forum.js' import { ForumsOfCurrentCourse, getForumsOfCourse, createForum } from '@/rest/forum.js'
import { PostsOfCurrentForum, getPostsOfForum, createPost } from '@/rest/forum.js' import { PostsOfCurrentForum, getPostsOfForum, createPost } from '@/rest/forum.js'
import { fetchedPost, fetchPost, sendAnswer } from '@/rest/forum.js' import { fetchedPost, fetchPost, sendAnswer } from '@/rest/forum.js'
import { getSelf } from '@/rest/Users.js' import { getSelf } from '@/rest/Users.js'
const courses = await reactive(getCourses()); const Role = (await getSelf()).role;
const courses = Role === 'Admin' || Role === 'Secretary' ? await reactive(getCourses()) : await reactive(getUserActualCourses());
const selectedCourse = ref(); const selectedCourse = ref();
const selectedForum = ref(); const selectedForum = ref();
const Role = (await getSelf()).role;
const addForumName = ref(""); const addForumName = ref("");
const addPost = ref(false); const addPost = ref(false);
@ -30,7 +30,7 @@ const addPostContent = ref("");
<div id="app"> <div id="app">
<div id="ForumSelector"> <div id="ForumSelector">
<select id="cours" value="" v-model="selectedCourse" @change="getForumsOfCourse(selectedCourse)"> <select id="cours" value="" v-model="selectedCourse" @change="getForumsOfCourse(selectedCourse)">
<option v-for="course in courses" :value="course.courseId">{{course.title}}</option> <option v-for="course in courses" :value="course.courseID">{{course.title}}</option>
</select> </select>
<select id="forum" value="" v-model="selectedForum" @change="getPostsOfForum(selectedForum !== 'create' ? selectedForum : null)" v-if="ForumsOfCurrentCourse != null"> <select id="forum" value="" v-model="selectedForum" @change="getPostsOfForum(selectedForum !== 'create' ? selectedForum : null)" v-if="ForumsOfCurrentCourse != null">

View File

@ -76,6 +76,6 @@ export async function alterCourse(id, changes){
* Return a list containing all the actual courses of a user * Return a list containing all the actual courses of a user
*/ */
export async function getUserActualCourses(userId){ export async function getUserActualCourses(){
return restGet("/usercourses/"+userId) return restGet("/usercourses")
} }