Skip to content
Snippets Groups Projects
Commit e5e9f15b authored by Martin Gargalovič's avatar Martin Gargalovič
Browse files

changed Course to work with User-Course mapping

parent 2d087e5f
No related branches found
No related tags found
3 merge requests!31M2,!28M2 user,!27Draft: M2 user
......@@ -9,6 +9,7 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import org.fuseri.model.dto.common.DomainObjectDto;
import org.fuseri.model.dto.user.UserDto;
import java.util.ArrayList;
import java.util.List;
......@@ -41,7 +42,7 @@ public class CourseDto extends DomainObjectDto {
@NotNull(message = "Student's list is required")
@Valid
private List<Long> studentIds;
private List<UserDto> students;
public CourseDto(Long id, String name, Integer capacity, LanguageTypeDto languageTypeDto, ProficiencyLevelDto proficiencyLevelDto) {
this.setId(id);
......@@ -49,6 +50,6 @@ public class CourseDto extends DomainObjectDto {
this.capacity = capacity;
this.language = languageTypeDto;
this.proficiency = proficiencyLevelDto;
this.studentIds = new ArrayList<>();
this.students = new ArrayList<>();
}
}
......@@ -28,6 +28,7 @@ public class Course extends DomainObject {
@ManyToMany
private Set<User> students;
private boolean finished = false;
public void enrolStudent(User student) {
students.add(student);
}
......
......@@ -128,8 +128,8 @@ public class CourseController {
*/
@ApiOperation(value = "Add student to the existing course")
@PatchMapping("/enrol/{id}")
public CourseDto enrol(@PathVariable Long id, @RequestBody UserDto student) {
return courseFacade.enrol(id, student);
public CourseDto enrol(@PathVariable Long id, @RequestParam Long studentId) {
return courseFacade.enrol(id, studentId);
}
/**
......
......@@ -6,6 +6,7 @@ import org.fuseri.model.dto.course.LanguageTypeDto;
import org.fuseri.model.dto.course.ProficiencyLevelDto;
import org.fuseri.model.dto.user.UserDto;
import org.fuseri.modulelanguageschool.user.UserMapper;
import org.fuseri.modulelanguageschool.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
......@@ -19,12 +20,15 @@ import java.util.List;
@Transactional
public class CourseFacade {
private final CourseService courseService;
private final UserService userService;
private final CourseMapper courseMapper;
private final UserMapper userMapper;
@Autowired
public CourseFacade(CourseService courseService, CourseMapper courseMapper, UserMapper userMapper) {
public CourseFacade(CourseService courseService, UserService userService, CourseMapper courseMapper, UserMapper userMapper) {
this.courseService = courseService;
this.userService = userService;
this.courseMapper = courseMapper;
this.userMapper = userMapper;
}
......@@ -63,8 +67,9 @@ public class CourseFacade {
return courseMapper.mapToList(courseService.findAll(Language.valueOf(lang.name()), ProficiencyLevel.valueOf(prof.name())));
}
public CourseDto enrol(Long id, UserDto student) {
return courseMapper.mapToDto(courseService.enrol(id, userMapper.fromDto(student)));
public CourseDto enrol(Long id, Long studentId) {
var student = userService.find(studentId);
return courseMapper.mapToDto(courseService.enrol(id, student));
}
public CourseDto expel(Long id, UserDto student) {
......
......@@ -9,6 +9,10 @@ import java.util.List;
@Repository
public interface CourseRepository extends JpaRepository<Course, Long> {
@Query("SELECT c FROM Course c left join fetch User u WHERE c.language = ?1 AND u.userType!=\"ADMIN\"")
Course getById(Long id);
@Query("SELECT c FROM Course c WHERE c.language = ?1")
List<Course> findAllByLang(Language language);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment