Skip to content

Commit

Permalink
Refactor Course API to save group registration settings (#1675)
Browse files Browse the repository at this point in the history
  • Loading branch information
scmet committed Aug 17, 2024
1 parent 2b48c3c commit 3057599
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
BEGIN;

alter table `fbs`.`course`
ADD `group_selection` BOOLEAN NULL DEFAULT NULL;

INSERT INTO migration (number) VALUES (22);

COMMIT;
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,32 @@ class CourseController {
case _ => throw new ForbiddenException()
}
}

Check failure on line 167 in modules/fbs-core/api/src/main/scala/de/thm/ii/fbs/controller/CourseController.scala

View workflow job for this annotation

GitHub Actions / fbs-core.api / Lint

No double blank lines

/**
* Update only the group selection of a course
*
* @param cid Course id
* @param req http request
* @param res http response
* @param body Request Body
*/
@PutMapping(value = Array("/{cid}/groupSelection"))
def updateGroupSelection(@PathVariable("cid") cid: Integer, req: HttpServletRequest, res: HttpServletResponse,
@RequestBody body: JsonNode): Unit = {
val user = authService.authorize(req, res)
val someCourseRole = courseRegistrationService.getParticipants(cid).find(_.user.id == user.id).map(_.role)

(user.globalRole, someCourseRole) match {
case (GlobalRole.ADMIN | GlobalRole.MODERATOR, _) | (_, Some(CourseRole.DOCENT)) =>
(
body.retrive("groupSelection").asBool(),
) match {
case (Some(groupSelection)) =>
courseService.updateGroupSelection(cid, groupSelection)
case _ => throw new BadRequestException("Malformed Request Body")
}
case _ => throw new ForbiddenException()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ package de.thm.ii.fbs.model
* @param description The description of this course
* @param visible The visibility of the course, false = invisible
* @param id The id of the course, if 0, then none was assigned.
* @param groupSelection Whether registration for groups is possible
*/
case class Course(name: String, description: String = "", visible: Boolean = true, id: Int = 0, semesterId: Option[Int] = None)
case class Course(name: String, description: String = "", visible: Boolean = true, id: Int = 0, semesterId: Option[Int] = None,
groupSelection: Option[Boolean] = None)
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,16 @@ class CourseService {
Some(tmp)
}
}

/**
* Update only the group selection of a course
*
* @param cid The course id
* @param groupSelection The new group selection status
* @return True if successful
*/
def updateGroupSelection(cid: Int, groupSelection: Boolean): Boolean = {
1 == DB.update("UPDATE course SET group_selection = ? WHERE course_id = ?",
groupSelection, cid)
}
}

0 comments on commit 3057599

Please sign in to comment.