部分后端修改3

master3
Cys 8 months ago
parent 8a07ddfc2c
commit 31ff3f2280

@ -17,4 +17,74 @@ import java.util.List;
@RequiredArgsConstructor
public class AdminController {
private final AdminService adminService;
/**
*
*
* @return
*/
@GetMapping("/admins")
public R<List<Admin>> findAll(){
return ApiResultHandler.success(adminService.findAll());
}
/**
* id
*
* @param adminId id
* @return
*/
@GetMapping("/admin/{adminId}")
public R<Admin> findById(@PathVariable("adminId") Integer adminId){
return ApiResultHandler.success(adminService.findById(adminId));
}
/**
* id
*
* @param adminId id
* @return
*/
@DeleteMapping("/admin/{adminId}")
public R deleteById(@PathVariable("adminId") Integer adminId){
adminService.deleteById(adminId);
return ApiResultHandler.success();
}
/**
*
*
* @param adminId id
* @param admin
* @return
*/
@PutMapping("/admin/{adminId}")
public R update(@PathVariable("adminId") Integer adminId, Admin admin){
return ApiResultHandler.success(adminService.update(admin));
}
/**
*
*
* @param admin
* @return
*/
@PostMapping("/admin")
public R add(Admin admin){
return ApiResultHandler.success(adminService.add(admin));
}
/**
*
*
* @param adminId id
* @param newPsw
* @param oldPsw
* @return
*/
@GetMapping("/admin/resetPsw/{adminId}/{oldPsw}/{newPsw}")
public R resetPsw(@PathVariable("adminId") Integer adminId, @PathVariable("newPsw") String newPsw, @PathVariable("oldPsw") String oldPsw) {
return ApiResultHandler.success(adminService.resetPsw(adminId, newPsw, oldPsw));
}
}

@ -18,9 +18,41 @@ import org.springframework.web.bind.annotation.RestController;
*
*/
@RestController
@RequiredArgsConstructor
public class AnswerController {
private final AnswerService answerService;
/**
*
*
* @param page
* @param size
* @param subject
* @param section
* @param question
* @return
*/
@GetMapping("/answers/{page}/{size}/{subject}/{section}/{question}")
public R<IPage<AnswerVO> > findAllQuestion(
@PathVariable("page") Integer page,
@PathVariable("size") Integer size,
@PathVariable("subject") String subject,
@PathVariable("section") String section,
@PathVariable("question") String question
){
IPage<AnswerVO> answerVOIPage = answerService.findAll(new Page<>(page,size), subject, section, question);
return ApiResultHandler.buildApiResult(200,"查询所有题库", answerVOIPage);
}
/**
* id
*
* @param type
* @param questionId id
* @return
*/
@GetMapping("/answers/{type}/{questionId}")
public R<QuestionVO> findByIdAndType(
@PathVariable("type") String type,

@ -13,7 +13,19 @@ import java.util.List;
/**
*
*
*/
@RestController
@RequiredArgsConstructor
public class ExamManageController {
private final ExamManageService examManageService;
/**
*
*
* @return
*/
@GetMapping("/exams")
public R<List<ExamManage>> findAll() {
return ApiResultHandler.buildApiResult(200, "请求成功!", examManageService.findAll());
@ -31,6 +43,20 @@ import java.util.List;
return ApiResultHandler.buildApiResult(200, "请求成功!", examManageService.findAll(new Page<>(page, size)));
}
/**
*
*
* @param examCode
* @return
*/
@GetMapping("/exam/{examCode}")
public R<ExamManage> findById(@PathVariable("examCode") Integer examCode) {
ExamManage res = examManageService.findById(examCode);
if (res == null) {
return ApiResultHandler.buildApiResult(10000, "考试编号不存在", null);
}
return ApiResultHandler.buildApiResult(200, "请求成功!", res);
}
/**
*
@ -47,17 +73,38 @@ import java.util.List;
*
* @param examManage
*/
@PutMapping("/exam")
public R update(@RequestBody ExamManage examManage) {
return ApiResultHandler.buildApiResult(200, "更新成功", examManageService.update(examManage));
}
/**
*
*
* @param examManage
*/
@PostMapping("/exam")
public R add(@RequestBody ExamManage examManage) {
int res = examManageService.add(examManage);
if (res == 1) {
return ApiResultHandler.buildApiResult(200, "添加成功", res);
} else {
return ApiResultHandler.buildApiResult(400, "添加失败", res);
}
}
/**
* paperId,
*
* @return
*/
@GetMapping("/examManagePaperId")
public R<ExamManage> findOnlyPaperId() {
ExamManage res = examManageService.findOnlyPaperId();
if (res != null) {
return ApiResultHandler.buildApiResult(200, "请求成功", res);
}
return ApiResultHandler.buildApiResult(400, "请求失败", res);
}
}

@ -20,12 +20,33 @@ import org.springframework.web.bind.annotation.RestController;
@RequiredArgsConstructor
public class FillQuestionController {
private final FillQuestionService fillQuestionService;
/**
*
*
* @param fillQuestion
* @return
*/
@PostMapping("/fillQuestion")
public R add(@RequestBody FillQuestion fillQuestion) {
int res = fillQuestionService.add(fillQuestion);
if (res != 0) {
return ApiResultHandler.buildApiResult(200, "添加成功", res);
}
return ApiResultHandler.buildApiResult(400, "添加失败", res);
}
/**
*
*
* @return
*/
@GetMapping("/fillQuestionId")
public R<FillQuestion> findOnlyQuestionId() {
FillQuestion res = fillQuestionService.findOnlyQuestionId();
return ApiResultHandler.buildApiResult(200, "查询成功", res);
}
/**
*
@ -33,5 +54,12 @@ public class FillQuestionController {
* @param fillQuestion
* @return
*/
@PostMapping("/editFillQuestion")
public R edit(@RequestBody FillQuestion fillQuestion) {
int res = fillQuestionService.edit(fillQuestion);
if (res != 0) {
return ApiResultHandler.buildApiResult(200, "修改成功", res);
}
return ApiResultHandler.buildApiResult(400, "修改失败", res);
}
}

@ -34,10 +34,37 @@ public class LoginController {
* @param response http response
* @return
*/
@PostMapping("/login")
public R login(@RequestBody Login login, HttpServletResponse response) {
Integer username = login.getUsername();
String password = login.getPassword();
//登录管理员
Admin adminRes = loginService.adminLogin(username, password);
if (adminRes != null) {
Cookie token = new Cookie("rb_token", adminRes.getCardId());
token.setPath("/");
Cookie role = new Cookie("rb_role", "0");
role.setPath("/");
//登录教师
//将cookie对象加入response响应
response.addCookie(token);
response.addCookie(role);
return ApiResultHandler.buildApiResult(200, "请求成功", adminRes);
}
//登录教师
Teacher teacherRes = loginService.teacherLogin(username, password);
if (teacherRes != null) {
Cookie token = new Cookie("rb_token", teacherRes.getCardId());
token.setPath("/");
Cookie role = new Cookie("rb_role", "1");
role.setPath("/");
response.addCookie(token);
response.addCookie(role);
return ApiResultHandler.buildApiResult(200, "请求成功", teacherRes);
}
//登录选
Student studentRes = loginService.studentLogin(username, password);

@ -15,3 +15,36 @@ import java.util.List;
* @author: ShanZhu
* @date: 2023-11-20
*/
@RestController
@RequiredArgsConstructor
public class ReplayController {
private final ReplayService replayService;
/**
*
*
* @param replay
* @return
*/
@PostMapping("/replay")
public R add(@RequestBody Replay replay) {
int data = replayService.add(replay);
if (data != 0) {
return ApiResultHandler.buildApiResult(200, "添加成功!", data);
} else {
return ApiResultHandler.buildApiResult(400, "添加失败!", null);
}
}
/**
* id
*
* @param messageId id
* @return
*/
@GetMapping("/replay/{messageId}")
public R<List<Replay>> findAllById(@PathVariable("messageId") Integer messageId) {
return ApiResultHandler.buildApiResult(200, "根据messageId查询", replayService.findAllById(messageId));
}
}

@ -26,6 +26,11 @@ public class ScoreController {
*
* @return
*/
@GetMapping("/scores")
public R<List<Score>> findAll() {
List<Score> res = scoreService.findAll();
return ApiResultHandler.buildApiResult(200, "查询所有学生成绩", res);
}
/**
*
@ -35,7 +40,15 @@ public class ScoreController {
* @param studentId id
* @return
*/
@GetMapping("/score/{page}/{size}/{studentId}")
public R<Page<Score>> findById(
@PathVariable("page") Integer page,
@PathVariable("size") Integer size,
@PathVariable("studentId") Integer studentId
) {
IPage<Score> res = scoreService.findById(new Page<>(page, size), studentId);
return ApiResultHandler.buildApiResult(200, "根据ID查询成绩", res);
}
/**
*
@ -43,6 +56,15 @@ public class ScoreController {
* @param studentId id
* @return
*/
@GetMapping("/score/{studentId}")
public R<List<Score>> findById(@PathVariable("studentId") Integer studentId) {
List<Score> res = scoreService.findById(studentId);
if (!res.isEmpty()) {
return ApiResultHandler.buildApiResult(200, "根据ID查询成绩", res);
} else {
return ApiResultHandler.buildApiResult(400, "ID不存在", res);
}
}
/**
*
@ -50,7 +72,15 @@ public class ScoreController {
* @param score
* @return
*/
@PostMapping("/score")
public R add(@RequestBody Score score) {
int res = scoreService.add(score);
if (res == 0) {
return ApiResultHandler.buildApiResult(400, "成绩添加失败", res);
} else {
return ApiResultHandler.buildApiResult(200, "成绩添加成功", res);
}
}
/**
*
@ -58,4 +88,9 @@ public class ScoreController {
* @param examCode
* @return
*/
@GetMapping("/scores/{examCode}")
public R<List<Score>> findByExamCode(@PathVariable("examCode") Integer examCode) {
List<Score> scores = scoreService.findByExamCode(examCode);
return ApiResultHandler.buildApiResult(200, "查询成功", scores);
}
}

@ -35,6 +35,22 @@ public class StudentController {
* @param clazz
* @return
*/
@GetMapping("/students/{page}/{size}/{name}/{grade}/{tel}/{institute}/{major}/{clazz}")
public R<IPage<Student>> findAll(
@PathVariable Integer page,
@PathVariable Integer size,
@PathVariable String name,
@PathVariable String grade,
@PathVariable String tel,
@PathVariable String institute,
@PathVariable String major,
@PathVariable String clazz
) {
IPage<Student> res = studentService.findAll(
new Page<>(page, size), name, grade, tel, institute, major, clazz
);
return ApiResultHandler.buildApiResult(200, "分页查询所有学生", res);
}
/**
* id

Loading…
Cancel
Save