Added endpoints

This commit is contained in:
Filip Izydorczyk 2020-08-08 14:14:42 +02:00
parent ac0851ae29
commit 2e40e33545
7 changed files with 77 additions and 0 deletions

View File

@ -22,6 +22,10 @@ public class Course {
public Course() {
}
public Long getId() {
return this.id;
}
public String getName() {
return name;
}

View File

@ -44,4 +44,7 @@ public class Lecturer {
this.surname = surname;
}
public Lecturer() {
}
}

View File

@ -1,5 +1,7 @@
package com.plannaplan.repositories;
import java.util.List;
import com.plannaplan.entities.Groups;
import org.springframework.data.jpa.repository.JpaRepository;
@ -11,4 +13,8 @@ import org.springframework.stereotype.Repository;
public interface GroupRepository extends JpaRepository<Groups, Long> {
@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);
@Query(value = "SELECT * FROM groups WHERE course_id = :id", nativeQuery = true)
List<Groups> getByCourse(@Param("id") Long id);
}

View File

@ -1,5 +1,7 @@
package com.plannaplan.services;
import java.util.List;
import com.plannaplan.entities.Course;
import com.plannaplan.repositories.CourseRepository;
@ -15,6 +17,10 @@ public class CourseService {
return this.repo.findByName(name);
}
public List<Course> getAllCourses() {
return this.repo.findAll();
}
public void save(Course course) {
this.repo.save(course);
}

View File

@ -1,5 +1,7 @@
package com.plannaplan.services;
import java.util.List;
import com.plannaplan.entities.Groups;
import com.plannaplan.repositories.GroupRepository;
@ -18,6 +20,10 @@ public class GroupService {
return this.repo.find(time, room, capacity);
}
public List<Groups> getGroupsByCourse(Long id) {
return this.repo.getByCourse(id);
}
public void save(Groups group) {
this.repo.save(group);
}

View File

@ -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);
}
}

View File

@ -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);
}
}