Skip to content

Commit

Permalink
add coursesCorrelativesShow endpoint to get the correlatives from a c…
Browse files Browse the repository at this point in the history
…ourse (#77)
  • Loading branch information
gibarsin committed Feb 3, 2017
1 parent 324b9fb commit 31548b8
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public interface CourseDao {
* @return List of correlatives for the given course (i.d. The courses that are requiered to enroll a student in the
* given course)
*/
List<String> getCorrelatives(String courseId);
List<String> getCorrelativesIds(String courseId);

/**
* Check if a correlativity loop is formed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ public interface CourseService {

/**
* @param courseId The id of the course.
* @return The id's of correlatives for the given course (i.d. The courses that are requiered to enroll a student in the
* @return The id's of correlatives for the given course (i.d. The courses that are required to enroll a student in the
* given course)
*/
List<String> getCorrelatives(String courseId);
List<String> getCorrelativesIds(String courseId);

/**
* Make the course corresponding to the correlativeId necessary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ public boolean deleteCourse(final String courseId) {
}

@Override
public List<String> getCorrelatives(String courseId) {
Course course = getByCourseID(courseId);
List<String> correlatives = new ArrayList<>();
public List<String> getCorrelativesIds(final String courseId) {
final Course course = getByCourseID(courseId);
final List<String> correlatives = new ArrayList<>();

for(Course correlative: course.getCorrelatives()){
correlatives.add(correlative.getCourseId());
Expand Down Expand Up @@ -188,7 +188,7 @@ public boolean checkCorrelativityLoop(final String id, final String correlativeI
toAdd = new HashSet<>();
prevSize = current.size();
for(Course auxCourse: current){
//current.addAll(auxCourse.getCorrelatives());
//current.addAll(auxCourse.getCorrelativesIds());
toAdd.addAll(auxCourse.getCorrelatives());
}
current.addAll(toAdd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@
// }
//
// @Test
// public void getCorrelatives(){
// public void getCorrelativesIds(){
// final Map<String, Object> correlativeArgs = new HashMap<>();
// final Map<String, Object> correlativeArgs2 = new HashMap<>();
//
Expand All @@ -568,7 +568,7 @@
// correlativeArgs2.put(CORRELATIVE__CORRELATIVE_ID_COLUMN, COURSE_ID_2);
// correlativeInsert.execute(correlativeArgs2);
//
// List<Integer> list = courseJdbcDao.getCorrelatives(COURSE_ID_3);
// List<Integer> list = courseJdbcDao.getCorrelativesIds(COURSE_ID_3);
//
// assertEquals(list.size(), 2);
// assertTrue( (list.get(0).equals(COURSE_ID_1) || list.get(0).equals(COURSE_ID_2) ));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,16 @@ public boolean addCorrelative(final String courseId, final String correlativeId)

//TODO: IF NOT CALLED FROM CONTROLLER, DELETE IMPLEMENTATION AND DELETE FROM INTERFACE

/**
* Gets the correlatives of a given course.
* It is assumed that the courseId exists
* @param courseId The id of the course.
* @return a list of the course id's of the correlatives in a String manner
*/
@Transactional
@Override
public List<String> getCorrelatives(final String courseId) {
return courseDao.getCorrelatives(courseId);
public List<String> getCorrelativesIds(final String courseId) {
return courseDao.getCorrelativesIds(courseId);
}

@Transactional
Expand All @@ -211,7 +217,7 @@ public boolean deleteCorrelative(final String courseId, final String correlative
@Transactional
@Override
public void deleteCourseCorrelatives(final String courseId) {
List<String> correlatives = getCorrelatives(courseId);
List<String> correlatives = getCorrelativesIds(courseId);
List<String> upperCorrelatives = getUpperCorrelatives(courseId);

/* Adds transitive correlatives:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public boolean enroll(final Student student, final Course course) {
@Transactional
@Override
public boolean checkCorrelatives(final int docket, final String courseId) {
final List<String> correlatives = courseService.getCorrelatives(courseId);
final List<String> correlatives = courseService.getCorrelativesIds(courseId);
final List<String> approvedCourses = getApprovedCourses(docket).stream().map(course -> course.getCourseId()).collect(Collectors.toList());;

for (String correlative : correlatives){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ar.edu.itba.paw.webapp.controllers;

import ar.edu.itba.paw.interfaces.CourseService;
import ar.edu.itba.paw.interfaces.StudentService;
import ar.edu.itba.paw.models.Course;
import ar.edu.itba.paw.models.FinalInscription;
import ar.edu.itba.paw.models.users.Student;
Expand All @@ -22,6 +21,7 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

Expand All @@ -39,9 +39,6 @@ public class CourseController {
@Autowired
private CourseService cs;

@Autowired
private StudentService ss;

@Autowired
private DTOEntityMapper mapper;

Expand Down Expand Up @@ -175,6 +172,24 @@ public Response coursesStudentsPassedIndex(@PathParam("courseId") final String c
return ok(new StudentsList(studentsList)).build();
}

@GET
@Path("/{courseId}/correlatives")
public Response coursesCorrelativesShow(@PathParam("courseId") final String courseId) {
if(cs.getByCourseID(courseId) == null) {
return status(Status.NOT_FOUND).build();
}
final List<String> correlativesIds = cs.getCorrelativesIds(courseId);
final List<Course> correlatives = new ArrayList<>(correlativesIds.size());

for(String correlativeId : correlativesIds) {
correlatives.add(cs.getByCourseID(correlativeId));
}

final List<CourseDTO> correlativesDTO = correlatives.stream().map(correlative -> mapper.convertToCourseDTO(correlative)).collect(Collectors.toList());

return ok(new CoursesList(correlativesDTO)).build();
}

@POST
@Path("/{courseId}/correlatives")
@Consumes(MediaType.APPLICATION_JSON)
Expand Down

0 comments on commit 31548b8

Please sign in to comment.