Added endpoints
This commit is contained in:
parent
ac0851ae29
commit
2e40e33545
@ -22,6 +22,10 @@ public class Course {
|
|||||||
public Course() {
|
public Course() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Long getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -44,4 +44,7 @@ public class Lecturer {
|
|||||||
this.surname = surname;
|
this.surname = surname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Lecturer() {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package com.plannaplan.repositories;
|
package com.plannaplan.repositories;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.plannaplan.entities.Groups;
|
import com.plannaplan.entities.Groups;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
@ -11,4 +13,8 @@ import org.springframework.stereotype.Repository;
|
|||||||
public interface GroupRepository extends JpaRepository<Groups, Long> {
|
public interface GroupRepository extends JpaRepository<Groups, Long> {
|
||||||
@Query(value = "SELECT * FROM groups WHERE time = :time AND room = :room AND capacity = :capacity ", nativeQuery = true)
|
@Query(value = "SELECT * FROM groups WHERE time = :time AND room = :room AND capacity = :capacity ", nativeQuery = true)
|
||||||
Groups find(@Param("time") int time, @Param("room") String room, @Param("capacity") int capacity);
|
Groups find(@Param("time") int time, @Param("room") String room, @Param("capacity") int capacity);
|
||||||
|
|
||||||
|
@Query(value = "SELECT * FROM groups WHERE course_id = :id", nativeQuery = true)
|
||||||
|
List<Groups> getByCourse(@Param("id") Long id);
|
||||||
|
|
||||||
}
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package com.plannaplan.services;
|
package com.plannaplan.services;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.plannaplan.entities.Course;
|
import com.plannaplan.entities.Course;
|
||||||
import com.plannaplan.repositories.CourseRepository;
|
import com.plannaplan.repositories.CourseRepository;
|
||||||
|
|
||||||
@ -15,6 +17,10 @@ public class CourseService {
|
|||||||
return this.repo.findByName(name);
|
return this.repo.findByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Course> getAllCourses() {
|
||||||
|
return this.repo.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
public void save(Course course) {
|
public void save(Course course) {
|
||||||
this.repo.save(course);
|
this.repo.save(course);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.plannaplan.services;
|
package com.plannaplan.services;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.plannaplan.entities.Groups;
|
import com.plannaplan.entities.Groups;
|
||||||
import com.plannaplan.repositories.GroupRepository;
|
import com.plannaplan.repositories.GroupRepository;
|
||||||
|
|
||||||
@ -18,6 +20,10 @@ public class GroupService {
|
|||||||
return this.repo.find(time, room, capacity);
|
return this.repo.find(time, room, capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Groups> getGroupsByCourse(Long id) {
|
||||||
|
return this.repo.getByCourse(id);
|
||||||
|
}
|
||||||
|
|
||||||
public void save(Groups group) {
|
public void save(Groups group) {
|
||||||
this.repo.save(group);
|
this.repo.save(group);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.plannaplan.controllers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.Course;
|
||||||
|
import com.plannaplan.services.CourseService;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin
|
||||||
|
public class CoursesController {
|
||||||
|
@Autowired
|
||||||
|
private CourseService courseService;
|
||||||
|
|
||||||
|
@GetMapping("/getCourses")
|
||||||
|
public ResponseEntity<List<Course>> getMethodName() {
|
||||||
|
return new ResponseEntity<>(this.courseService.getAllCourses(), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.plannaplan.controllers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.plannaplan.entities.Groups;
|
||||||
|
import com.plannaplan.services.GroupService;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@CrossOrigin
|
||||||
|
public class GroupController {
|
||||||
|
@Autowired
|
||||||
|
private GroupService groupService;
|
||||||
|
|
||||||
|
@GetMapping("/getCourseGroups")
|
||||||
|
public ResponseEntity<List<Groups>> getCourses(@RequestParam("id") Long id) {
|
||||||
|
return new ResponseEntity<>(this.groupService.getGroupsByCourse(id), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user