Skip to content

Commit 53460f5

Browse files
committed
WIP making My Courses work (currently still not authenticated)
1 parent 07e91a7 commit 53460f5

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/main/java/net/hackyourfuture/coursehub/SecurityConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
3737
.permitAll()
3838
.requestMatchers(HttpMethod.OPTIONS, "/courses")
3939
.permitAll()
40+
.requestMatchers("/students/**")
41+
.hasRole("student")
4042
.anyRequest()
4143
.authenticated())
4244
.build();

src/main/java/net/hackyourfuture/coursehub/web/StudentController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package net.hackyourfuture.coursehub.web;
22

3+
import jakarta.validation.constraints.Positive;
34
import net.hackyourfuture.coursehub.service.CourseService;
45
import net.hackyourfuture.coursehub.web.model.CourseDto;
56
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.PathVariable;
68
import org.springframework.web.bind.annotation.RequestMapping;
79
import org.springframework.web.bind.annotation.RestController;
810

@@ -19,7 +21,7 @@ public StudentController(CourseService courseService) {
1921
}
2022

2123
@GetMapping("/{studentId}/courses")
22-
public List<CourseDto> getCoursesForStudent(Integer studentId) {
24+
public List<CourseDto> getCoursesForStudent(@PathVariable(value = "studentId") @Positive Integer studentId) {
2325
return courseService.getCoursesForStudent(studentId);
2426
}
2527
}

ui/src/pages/MyCourses.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function MyCourses({user}: { user: User | null }) {
1717
credentials: "include",
1818
}).then(res => res.json())
1919
.then(data => setCourses(data.courses))
20-
.catch(err => console.error('Error fetching courses:', err))
20+
.catch(err => console.error("Error fetching My Courses:", err))
2121
}, [])
2222

2323
return (
@@ -40,7 +40,7 @@ function MyCourses({user}: { user: User | null }) {
4040
<tbody>
4141
{courses.map((course, idx) => (
4242
<tr
43-
key={course.courseId}
43+
key={course.id}
4444
className={`border-t transition ${idx % 2 === 0 ? 'bg-gray-50' : 'bg-white'} hover:bg-blue-50`}
4545
>
4646
<td className="px-6 py-4 text-gray-700">{course.name}</td>
@@ -59,5 +59,3 @@ function MyCourses({user}: { user: User | null }) {
5959
}
6060

6161
export default MyCourses
62-
63-

0 commit comments

Comments
 (0)