finish
This commit is contained in:
		@ -13,6 +13,7 @@ import ovh.herisson.Clyde.Tables.UserCurriculum;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@ -149,13 +150,13 @@ public class CourseController {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    //Get all the courses followed by an user
 | 
			
		||||
    @GetMapping("/usercourses/{userId}")
 | 
			
		||||
    public ResponseEntity<ArrayList<Course>> getAllUserCourses(@PathVariable long userId){
 | 
			
		||||
        User u = userService.getUserById(userId);
 | 
			
		||||
    @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
 | 
			
		||||
        ArrayList<UserCurriculum> userCurricula = userCurriculumService.findByStudentAndActual(u, true);
 | 
			
		||||
        ArrayList<Course> toReturn = new ArrayList<>();
 | 
			
		||||
        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++){
 | 
			
		||||
 | 
			
		||||
@ -110,7 +110,4 @@ public class ForumController {
 | 
			
		||||
		forumServ.answerTopic(t, data, u);
 | 
			
		||||
		return new ResponseEntity<>(HttpStatus.ACCEPTED);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	// TODO: <tonitch> Check if authorization to view a post/forum/...
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -51,7 +51,7 @@ public class ProtectionService {
 | 
			
		||||
 | 
			
		||||
        HashMap<String ,Object> toReturn = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
        toReturn.put("courseId",course.getCourseID());
 | 
			
		||||
        toReturn.put("courseID",course.getCourseID());
 | 
			
		||||
        toReturn.put("credits",course.getCredits());
 | 
			
		||||
        toReturn.put("title", course.getTitle());
 | 
			
		||||
        toReturn.put("owner", userWithoutPassword(course.getOwner()));
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,9 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
import lombok.AllArgsConstructor;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import lombok.NoArgsConstructor;
 | 
			
		||||
import ovh.herisson.Clyde.Tables.Msg.Forum;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
@ -11,6 +13,8 @@ import org.hibernate.annotations.OnDeleteAction;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
@Data
 | 
			
		||||
@NoArgsConstructor
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
public class Course {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
@ -37,34 +41,4 @@ public class Course {
 | 
			
		||||
        this.title = title;
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,10 +1,17 @@
 | 
			
		||||
package ovh.herisson.Clyde.Tables;
 | 
			
		||||
 | 
			
		||||
import jakarta.persistence.*;
 | 
			
		||||
import lombok.AllArgsConstructor;
 | 
			
		||||
import lombok.Data;
 | 
			
		||||
import lombok.NoArgsConstructor;
 | 
			
		||||
 | 
			
		||||
import org.hibernate.annotations.OnDelete;
 | 
			
		||||
import org.hibernate.annotations.OnDeleteAction;
 | 
			
		||||
 | 
			
		||||
@Entity
 | 
			
		||||
@Data
 | 
			
		||||
@AllArgsConstructor
 | 
			
		||||
@NoArgsConstructor
 | 
			
		||||
public class UserCurriculum {
 | 
			
		||||
    @Id
 | 
			
		||||
    @GeneratedValue(strategy = GenerationType.AUTO)
 | 
			
		||||
@ -26,48 +33,10 @@ public class UserCurriculum {
 | 
			
		||||
    //True if the user has that curriculum at the moment false if not
 | 
			
		||||
    private boolean actual;
 | 
			
		||||
 | 
			
		||||
    public UserCurriculum(User user, Curriculum curriculum, int year, boolean actual){
 | 
			
		||||
        this.user = user;
 | 
			
		||||
        this.curriculum = curriculum;
 | 
			
		||||
        this.year = year;
 | 
			
		||||
        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;
 | 
			
		||||
    }
 | 
			
		||||
	public UserCurriculum(User u, Curriculum cu, int year, boolean actual){
 | 
			
		||||
		this.user = u;
 | 
			
		||||
		this.curriculum = cu;
 | 
			
		||||
		this.year = year;
 | 
			
		||||
		this.actual = actual;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user