Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,53 +147,64 @@ public String addCourse(@ModelAttribute("course") CourseModel courseModel, Model

@GetMapping("/admin-management/add-class")
public String addClass(ModelMap model) {
model.addAttribute("courses", courseService.findAll());
model.addAttribute("semester", semesterService.findAll());
if(!model.containsAttribute("class"))
model.addAttribute("class",new ClassResDTO());
return "admin/views/createClass";
try{
model.addAttribute("courses", courseService.findAll());
model.addAttribute("semester", semesterService.findAll());
if(!model.containsAttribute("class"))
model.addAttribute("class",new ClassResDTO());
return "admin/views/createClass";
}catch (Exception e){
logger.error(String.valueOf(new RuntimeException(e)));
return "redirect:/login/Rare_fault";
}
}

@PostMapping("/admin-management/add-class")
public String addClass(@ModelAttribute("class") ClassResDTO classRes, ModelMap model) {
ClassModel classModel = new ClassModel();
classModel.setCourseId(classRes.getCourseId());
classModel.setClassName(classRes.getClassName());
classModel.setClassId(classModel.getCourseId()+"-"+classModel.getClassName()+"-"+classRes.getSemesterId());
classModel.setDayOfWeek(classRes.getDayOfWeek());
classModel.setTimeStart(classRes.getTimeStart());
classModel.setTimeEnd(convertTime(classRes.getTimeStart(), classRes.getTimeStudy()));
classModel.setRoom(classRes.getRoom());
classModel.setSemesterId(classRes.getSemesterId());
try {
ClassModel classModel = new ClassModel();
classModel.setCourseId(classRes.getCourseId());
classModel.setClassName(classRes.getClassName());
classModel.setClassId(classModel.getCourseId() + "-" + classModel.getClassName() + "-" + classRes.getSemesterId());
classModel.setDayOfWeek(classRes.getDayOfWeek());
classModel.setTimeStart(classRes.getTimeStart());
classModel.setTimeEnd(convertTime(classRes.getTimeStart(), classRes.getTimeStudy()));
classModel.setRoom(classRes.getRoom());
classModel.setSemesterId(classRes.getSemesterId());

boolean notSave = false;
List<ClassModel> listClass = classService.findAll();
for(ClassModel cls : listClass) {
if(cls.getClassId().equals(classModel.getClassId())) {
model.addAttribute("message", "Lớp " + classModel.getClassName()
+" của khóa học " + classModel.getCourseId() + " đã tồn tại!");
notSave = true;
model.addAttribute("class",classRes);
model.addAttribute("error","error");
break;
} else if(cls.getSemesterId().equals(classModel.getSemesterId()) && conflictTime(cls, classModel)) {
model.addAttribute("message", "Trùng lịch với lớp " + cls.getClassName()
+" của khóa học " + cls.getCourseId() + " (" + cls.getTimeStart() + "-" + cls.getTimeEnd()
+ " " + cls.getDayOfWeek() + " " + cls.getRoom() + ")");
notSave = true;
model.addAttribute("class",classRes);
model.addAttribute("error","error");
break;
boolean notSave = false;
List<ClassModel> listClass = classService.findAll();
for (ClassModel cls : listClass) {
if (cls.getClassId().equals(classModel.getClassId())) {
model.addAttribute("message", "Lớp " + classModel.getClassName()
+ " của khóa học " + classModel.getCourseId() + " đã tồn tại!");
notSave = true;
model.addAttribute("class", classRes);
model.addAttribute("error", "error");
break;
} else if (cls.getSemesterId().equals(classModel.getSemesterId()) && conflictTime(cls, classModel)) {
model.addAttribute("message", "Trùng lịch với lớp " + cls.getClassName()
+ " của khóa học " + cls.getCourseId() + " (" + cls.getTimeStart() + "-" + cls.getTimeEnd()
+ " " + cls.getDayOfWeek() + " " + cls.getRoom() + ")");
notSave = true;
model.addAttribute("class", classRes);
model.addAttribute("error", "error");
break;
}
}
if (!notSave) {
model.addAttribute("message", "Lớp học đã được tạo thành công!");
classService.save(classModel);
model.addAttribute("class", new ClassResDTO());
}
model.addAttribute("courses", courseService.findAll());
model.addAttribute("semester", semesterService.findAll());
return "admin/views/createClass";
}
if(!notSave) {
model.addAttribute("message", "Lớp học đã được tạo thành công!");
classService.save(classModel);
model.addAttribute("class",new ClassResDTO());
catch (Exception e){
logger.error(String.valueOf(new RuntimeException(e)));
return "redirect:/login/Rare_fault";
}
model.addAttribute("courses", courseService.findAll());
model.addAttribute("semester", semesterService.findAll());
return "admin/views/createClass";
}

@GetMapping("/admin-management/update-class")
Expand Down Expand Up @@ -352,14 +363,19 @@ int convertTime2(String timeStart, String timeEnd) {

@GetMapping("/admin-management-semester")
public String viewSemester (ModelMap model) {
List<SemesterModel> semesterList = semesterService.findAll();
semesterList = sortSemester(semesterList);
model.addAttribute("semesters", semesterList);
LocalDate currentDate = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String date = currentDate.format(formatter);
model.addAttribute("currentDate", date);
return "admin/views/viewSemester";
try{
List<SemesterModel> semesterList = semesterService.findAll();
semesterList = sortSemester(semesterList);
model.addAttribute("semesters", semesterList);
LocalDate currentDate = LocalDate.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String date = currentDate.format(formatter);
model.addAttribute("currentDate", date);
return "admin/views/viewSemester";
}catch (Exception e){
logger.error(String.valueOf(new RuntimeException(e)));
return "redirect:/login/Rare_fault";
}
}

@GetMapping("/admin-management/add-semester")
Expand Down
46 changes: 28 additions & 18 deletions src/main/java/com/hcmutap/elearning/controller/api/ClassAPI.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,57 @@
package com.hcmutap.elearning.controller.api;

import com.hcmutap.elearning.controller.admin.HomeController;
import com.hcmutap.elearning.exception.NotFoundException;
import com.hcmutap.elearning.model.ClassModel;
import com.hcmutap.elearning.service.IClassService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class ClassAPI {
@Resource
private IClassService classService;
@GetMapping("/class/findAll")
public List<ClassModel> findAll() {
return classService.findAll();
}
@GetMapping("/class/findById")
public ClassModel findById(@RequestParam String id) {
private static final Logger logger = LoggerFactory.getLogger(ClassAPI.class);
@Resource
private IClassService classService;
@GetMapping("/class/findAll")
public List<ClassModel> findAll() {
return classService.findAll();
}
@GetMapping("/class/findById")
public ClassModel findById(@RequestParam String id) {
try {
return classService.findById(id);
} catch (NotFoundException e) {
throw new RuntimeException(e);
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
return null;
}
}
@PostMapping("/class")
public String save(@RequestBody ClassModel classModel) { return classService.save(classModel);}
@PutMapping("/class")
public void update(@RequestBody ClassModel classModel) {
// need to handler not found exception in dao -> service -> controller
@PostMapping("/class")
public String save(@RequestBody ClassModel classModel) { return classService.save(classModel);}
@PutMapping("/class")
public void update(@RequestBody ClassModel classModel) {
// need to handler not found exception in dao -> service -> controller
try {
classService.update(classModel);
} catch (NotFoundException e) {
throw new RuntimeException(e);
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
// return null;
}
}
@DeleteMapping("/class")
public void delete(@RequestBody List<String> ids) {
@DeleteMapping("/class")
public void delete(@RequestBody List<String> ids) {
try {
classService.delete(ids);
} catch (NotFoundException e) {
throw new RuntimeException(e);
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
// return null;
}
}
}
37 changes: 24 additions & 13 deletions src/main/java/com/hcmutap/elearning/controller/api/CourseAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

Expand All @@ -17,6 +19,7 @@
@RestController
@RequestMapping("/api")
public class CourseAPI {
private static final Logger logger = LoggerFactory.getLogger(CourseAPI.class);
@Resource
private ICourseService courseService;
@GetMapping("/courses/findAll")
Expand All @@ -25,27 +28,35 @@ public List<CourseModel> findAll() {
}
@GetMapping("/courses/findById")
public CourseModel findById(@RequestParam String id) {
try {
return courseService.findById(id);
} catch (NotFoundException e) {
throw new RuntimeException(e);
}
}
try {
return courseService.findById(id);
} catch (NotFoundException e) {
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
return null;
}
}
@PostMapping("/courses")
public String save(@RequestBody CourseModel courseModel) {
return courseService.save(courseModel);
}
@PutMapping("/courses")
public void update(@RequestBody CourseModel courseModel) {
// need to handler not found exception in dao -> service -> controller
try {
courseService.update(courseModel);
} catch (NotFoundException e) {
throw new RuntimeException(e);
}
}
try {
courseService.update(courseModel);
} catch (NotFoundException e) {
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
}
}
@DeleteMapping("/courses")
public void delete(@RequestBody List<String> ids) {
ids.forEach(id -> courseService.delete(id));
try {
ids.forEach(id -> courseService.delete(id));
} catch (Exception e) {
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
}
}
}
56 changes: 37 additions & 19 deletions src/main/java/com/hcmutap/elearning/controller/api/PointAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,63 @@
import com.hcmutap.elearning.model.PointModel;
import com.hcmutap.elearning.service.IPointService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class PointAPI {
@Resource
private IPointService pointService;
@GetMapping("/points/findAll")
public List<PointModel> findAll() {
return pointService.findAll();
}
@GetMapping("/points/findById")
public PointModel findById(@RequestParam String id) {
private static final Logger logger = LoggerFactory.getLogger(PointAPI.class);
@Resource
private IPointService pointService;
@GetMapping("/points/findAll")
public List<PointModel> findAll() {
try{
return pointService.findAll();
}catch (Exception e) {
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
return null;
}
}
@GetMapping("/points/findById")
public PointModel findById(@RequestParam String id) {
try {
return pointService.findById(id);
} catch (NotFoundException e) {
throw new RuntimeException(e);
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
return null;
}
}
@PostMapping("/points")
public void save(@RequestBody PointModel pointModel) {
try{
pointService.save(pointModel);
}catch (Exception e) {
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
}
}
@PostMapping("/points")
public void save(@RequestBody PointModel pointModel) {
pointService.save(pointModel);
}
@PutMapping("/points")
public void update(@RequestBody PointModel pointModel) {
@PutMapping("/points")
public void update(@RequestBody PointModel pointModel) {
try {
pointService.update(pointModel);
} catch (NotFoundException e) {
throw new RuntimeException(e);
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
}
}
@DeleteMapping("/points")
public void delete(@RequestBody List<String> ids) {
@DeleteMapping("/points")
public void delete(@RequestBody List<String> ids) {
try {
pointService.delete(ids);
} catch (NotFoundException e) {
throw new RuntimeException(e);
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@
import com.hcmutap.elearning.service.IRegisterService;

import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api")
public class RegisterAPI {
private static final Logger logger = LoggerFactory.getLogger(RegisterAPI.class);
@Resource
private IRegisterService registerService;
@PostMapping("/register")
public void register(@RequestBody ModelMap model) {
try {
registerService.register(model);
} catch (NotFoundException e) {
throw new RuntimeException(e);
// throw new RuntimeException(e);
logger.error(String.valueOf(new RuntimeException(e)));
}
}

Expand Down
Loading