瀏覽代碼

feat: 课程详情页 学生登录时可查看课程下的eval和coder测试

mjh 4 年之前
父節點
當前提交
92bd67bd68

+ 4 - 1
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/config/SpringSecurityConfiguration.java

@@ -77,7 +77,10 @@ public class SpringSecurityConfiguration extends WebSecurityConfigurerAdapter {
                         "/api/eval/exam/student",
                         "/api/eval/exam/recommend",
                         "/api/eval/exam/teacher/course",
-                        "/api/coder/exam/student",
+                        "/api/eval/exam/student/course",
+                        "/api/coder/exam/student/all",
+                        "/api/coder/exam/student/course",
+                        "/api/coder/exam/teacher/course",
                         "/api/coder/exam/recommend",
                         "/api/announcement",
                         "/api/announcement/getAllByCourseId",

+ 4 - 6
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/domain/Course.java

@@ -36,7 +36,6 @@ public class Course {
     private String semester;
 
     @Column
-//    @NotNull
     private String imageUrl;
 
     @Column
@@ -51,23 +50,22 @@ public class Course {
     @NotNull
     private OffsetDateTime endTime;
 
-    @Column
+    @Column(unique = true)
     @NotNull
     private String invitationCode;
 
     @Column
-//    @NotNull
     private String moocUrl;
 
-    @Column
+    @Column(unique = true)
 //    @NotNull
     private Integer evalId;
 
-    @Column
+    @Column(unique = true)
 //    @NotNull
     private Integer coderId;
 
-    @Column
+    @Column(unique = true)
 //    @NotNull
     private Long helperId;
 

+ 8 - 1
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/service/CourseService.java

@@ -149,7 +149,14 @@ public class CourseService {
         if (!user.getId().equals(courseSelectionKey.getUserId())) {
             throw new CustomErrorException("当前用户无权选课");
         }
-        this.getCourseById(courseSelectionKey.getCourseId());
+        CourseVO course = this.getCourseById(courseSelectionKey.getCourseId());
+        // coder系统选课
+        JSONObject coderRes = coderService.chooseCourseByCode(course.getInvitationCode());
+        if(!coderRes.containsKey("res")){
+            throw new CustomErrorException("Coder: " + coderRes.get("msg"));
+        }
+        // eval系统选课
+        // 门户系统选课
         CourseSelection courseSelection = new CourseSelection(courseSelectionKey);
         courseSelection.setState(true);
         courseSelectionRepository.save(courseSelection);

+ 15 - 1
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/service/Impl/CoderService.java

@@ -90,7 +90,7 @@ public class CoderService implements SubsystemService {
         return JSON.parseObject(result);
     }
 
-    public JSONArray getTeacherExamsByCourseId(int courseId) {
+    public JSONArray getExamsByCourseId(int courseId) {
         String uri = "https://coder-server.seec.seecoder.cn/api/exam";
         String token = httpService.getToken();
         List<NameValuePair> params = new ArrayList<>();
@@ -109,4 +109,18 @@ public class CoderService implements SubsystemService {
         }
         return result;
     }
+
+    public JSONObject chooseCourseByCode(String code){
+        String uri = "https://coder-server.seec.seecoder.cn/api/course/student";
+        String token = httpService.getToken();
+        JSONObject requestBody = new JSONObject();
+        requestBody.put("code", code);
+        String result = null;
+        try {
+            result = httpService.sendPost(uri, requestBody, token);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return JSON.parseObject(result);
+    }
 }

+ 14 - 1
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/service/Impl/EvalService.java

@@ -87,7 +87,7 @@ public class EvalService implements SubsystemService {
         return JSONObject.parseObject(result);
     }
 
-    public JSONObject getExamsByCourseId(Integer courseId){
+    public JSONObject getTeacherExamsByCourseId(Integer courseId){
         String uri = "https://eval-server.seec.seecoder.cn/api/exam/teacher/course/" + courseId;
         String token = httpService.getToken();
         List<NameValuePair> params = new ArrayList<>();
@@ -99,4 +99,17 @@ public class EvalService implements SubsystemService {
         }
         return JSONObject.parseObject(result);
     }
+
+    public JSONObject getStudentExamsByCourseId(int courseId){
+        String uri = "https://eval-server.seec.seecoder.cn/api/exam/course/" + courseId;
+        String token = httpService.getToken();
+        List<NameValuePair> params = new ArrayList<>();
+        String result = null;
+        try {
+            result = httpService.sendGet(uri, params, token);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return JSONObject.parseObject(result);
+    }
 }

+ 7 - 2
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/web/rest/CoderController.java

@@ -30,7 +30,12 @@ public class CoderController {
     }
 
     @GetMapping("/exam/teacher/course")
-    public OkResponse<JSONArray> getExamsByCourseId(@RequestParam int courseId){
-        return OkResponse.of(coderService.getTeacherExamsByCourseId(courseId));
+    public OkResponse<JSONArray> getTeacherExamsByCourseId(@RequestParam int courseId){
+        return OkResponse.of(coderService.getExamsByCourseId(courseId));
+    }
+
+    @GetMapping("/exam/student/course")
+    public OkResponse<JSONArray> getStudentExamsByCourseId(@RequestParam int courseId){
+        return OkResponse.of(coderService.getExamsByCourseId(courseId));
     }
 }

+ 8 - 1
seecoder-portal-server/src/main/java/cn/seecoder/seecoderportalserver/web/rest/EvalController.java

@@ -36,6 +36,13 @@ public class EvalController {
 
     @GetMapping("/exam/teacher/course")
     public OkResponse<JSONArray> getExamsByCourseId(@RequestParam Integer courseId) {
-        return OkResponse.of(evalService.getExamsByCourseId(courseId).getJSONArray("result"));
+        return OkResponse.of(evalService.getTeacherExamsByCourseId(courseId).getJSONArray("result"));
     }
+
+    @GetMapping("exam/student/course")
+    public OkResponse<JSONArray> getExamsByCourseId(@RequestParam int courseId){
+        return OkResponse.of(evalService.getStudentExamsByCourseId(courseId).getJSONArray("result"));
+    }
+
+
 }

+ 7 - 14
seecoder-portal-server/src/main/resources/data.sql

@@ -1,17 +1,10 @@
--- portal_user
-INSERT INTO public.portal_user (id, created_time, email, is_valid, name, password, phone, photo, role, signature, username) VALUES (1480, '2021-08-26 14:21:25.848000', 'qinliu@nju.edu.cn', true, 'liuqin', '$2a$10$fk2NGp/Dp6VZgtpKJoWM1uDPZgRDQsnw/X/cSCJGHpYm./jVlDlb6', '18001585267', null, 'TEACHER', '无', 'kenny67nju');
-INSERT INTO public.portal_user (id, created_time, email, is_valid, name, password, phone, photo, role, signature, username) VALUES (1481, '2021-08-26 14:24:37.859000', 'seecoder@163.com', true, 'root', '$2a$10$uGZWj98Wyc7FUr0PRs1v/.W026YuBfXKWPoAT9yLbEEdG90fmyd4G', '17301585267', null, 'ADMIN', '无', 'seecoder');
-INSERT INTO public.portal_user (id, created_time, email, is_valid, name, password, phone, photo, role, signature, username) VALUES (1459, '2021-08-11 01:05:33.361000', '181250102@smail.nju.edu.cn', true, 'MengJunhao', '$2a$10$zrbimQNgk1I/jU3bSCyGuOgeKpbGoJxQeTtTyfst26pXJUfGHpO2W', '15256072859', null, 'SEEC', '无', 'MJH266');
-INSERT INTO public.portal_user (id, created_time, email, is_valid, name, password, phone, photo, role, signature, username) VALUES (3117, '2022-02-21 13:21:26.171000', 'm15256072859@163.com', true, 'PortalTestTeacher', '$2a$10$y1kkNo3r2W3PKp4i.n64TeJz2Uj38r5ShahFh/3wRugFm27wz9eBe', '13382405535', null, 'TEACHER', '无', 'PortalTestTeacher');
+INSERT INTO public.announcement (id, content, course_id, created_at, sender_id, state, title, type) VALUES (8, '', 13, '2022-04-08 16:28:33.724000', 1481, 'DELETED', '测试公告-考试', 2);
+INSERT INTO public.announcement (id, content, course_id, created_at, sender_id, state, title, type) VALUES (9, '人情味热无若群热热武器额外若群去玩儿额温枪我让', 13, '2022-04-11 15:31:10.748000', 3117, 'NORMAL', '123456', 1);
 
--- course
-INSERT INTO public.course (id, coder_id, state, created_time, description, end_time, eval_id, helper_id, image_url, invitation_code, mooc_url, name, semester, start_time, teacher_id, price) VALUES (1, null, 'EXAMPLE', '2022-02-20 11:54:34.084000', '精选课程简介1', '2022-03-28 11:08:07.608000', null, null, null, 'EXAMPLE-1', null, '精选课程1', '2022春', '2022-02-28 11:08:07.608000', 3117, 0);
-INSERT INTO public.course (id, coder_id, state, created_time, description, end_time, eval_id, helper_id, image_url, invitation_code, mooc_url, name, semester, start_time, teacher_id, price) VALUES (2, null, 'EXAMPLE', '2022-02-28 16:52:06.235000', '精选课程简介2', '2022-03-28 16:52:27.670000', null, null, null, 'EXAMPLE-2', null, '精选课程2', '2023春', '2022-02-28 16:52:27.670000', 3117, 0);
-INSERT INTO public.course (id, coder_id, state, created_time, description, end_time, eval_id, helper_id, image_url, invitation_code, mooc_url, name, semester, start_time, teacher_id, price) VALUES (3, null, 'EXAMPLE', '2022-02-28 21:46:24.008000', '精选课程简介3', '2022-03-28 21:46:24.307000', null, null, null, 'EXAMPLE-3', null, '精选课程3', '2022春', '2022-02-28 21:46:24.307000', 3117, 0);
-INSERT INTO public.course (id, coder_id, state, created_time, description, end_time, eval_id, helper_id, image_url, invitation_code, mooc_url, name, semester, start_time, teacher_id, price) VALUES (4, null, 'EXAMPLE', '2022-02-20 12:54:34.084000', '精选课程简介4', '2022-03-24 10:24:18.129000', null, null, null, 'EXAMPLE-4', null, '精选课程4', '2022春', '2022-02-24 10:24:18.129000', 3117, 0);
-INSERT INTO public.course (id, coder_id, state, created_time, description, end_time, eval_id, helper_id, image_url, invitation_code, mooc_url, name, semester, start_time, teacher_id, price) VALUES (5, null, 'EXAMPLE', '2022-02-20 13:54:34.084000', '精选课程简介5', '2022-03-24 10:24:18.129000', null, null, null, 'EXAMPLE-5', null, '精选课程5', '2022春', '2022-02-24 10:24:18.129000', 3117, 0);
-INSERT INTO public.course (id, coder_id, state, created_time, description, end_time, eval_id, helper_id, image_url, invitation_code, mooc_url, name, semester, start_time, teacher_id, price) VALUES (6, null, 'EXAMPLE', '2022-02-20 14:54:34.084000', '精选课程简介6', '2022-03-24 10:24:18.129000', null, null, null, 'EXAMPLE-6', null, '精选课程6', '2022春', '2022-02-24 10:24:18.129000', 3117, 0);
+INSERT INTO public.announcement_record (announcement_id, recipient_id, created_at, read_at, state) VALUES (9, 3187, '2022-04-13 16:51:05.871000', null, false);
 
--- course_generation
-UPDATE public.course_generation SET pk_course_id_value = 7 WHERE pk_course_id_name = 'COURSE_PK';
+INSERT INTO public.course (id, coder_id, created_time, description, end_time, eval_id, helper_id, image_url, invitation_code, mooc_url, name, price, semester, start_time, state, teacher_id) VALUES (13, 21, '2022-04-08 15:19:54.994000', '图片课程测试', '2022-05-31 00:00:00.000000', 2, null, 'http://mjh1.oss-cn-hangzhou.aliyuncs.com/seecoder/image-%E5%9B%BE%E7%89%87%E8%AF%BE%E7%A8%8B.jpg', 'eval', null, '图片课程', 0, '2022夏', '2022-04-01 00:00:00.000000', 'EXAMPLE', 3117);
 
+INSERT INTO public.course_selection (course_id, user_id, state) VALUES (13, 3187, true);
+
+INSERT INTO public.portal_user (id, created_time, email, is_valid, name, password, phone, photo, role, signature, username) VALUES (3187, '2022-04-13 08:29:20.874000', '2570235928@qq.com', true, 'StudentWZX ', '$2a$10$4g2YNGEMgMJlY8YSVLZfh.GEdEiyKVpFdABfMwYHi0Sdow87z7PnS', '13704400822', null, 'STUDENT ', '无        ', 'StudentWZX');