Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB] Add group creation and registration fuctionality #1680

Merged
merged 24 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
31dd1ba
Add group model and services (#1675)
scmet Jul 3, 2024
12b7242
Refactor GroupRegistrationController API to retrieve current group me…
scmet Jul 3, 2024
5f1fdf5
Update course detail component and sidebar component (#1675)
scmet Jul 3, 2024
2aff82e
Update package dependencies (#1675)
scmet Jul 3, 2024
199f09d
Update app-routing, app.module, and i18n files (#1675)
scmet Jul 3, 2024
4acd8c0
Add new page-components (#1675)
scmet Jul 3, 2024
5fa84ad
Add new dialog for group creation (#1675)
scmet Jul 3, 2024
e5dbbda
Add feature to display current membership count (#1675)
scmet Jul 9, 2024
9dd95e4
Update group-detail component (#1675)
scmet Jul 9, 2024
9f42634
Add menu-bar and functionalities to deregister and delete (#1675)
scmet Jul 17, 2024
d487721
Fixed settings and added visibility restrictions (#1675)
scmet Jul 30, 2024
2ff3638
chore(web): fix linting errors
Zitrone44 Jul 31, 2024
20edd4e
Fix linting errors and the update functionality (#1675)
scmet Aug 17, 2024
2b48c3c
Merge branch '1675-web-add-group-creation-and-registration' of github…
scmet Aug 17, 2024
3057599
Refactor Course API to save group registration settings (#1675)
scmet Aug 17, 2024
a69ab94
Update course model and service (#1675)
scmet Aug 17, 2024
4fd66ca
Add dialog to register and deregister groupmebers (#1675)
scmet Aug 17, 2024
bd03d7f
Update group-selection component and i18n files (#1675)
scmet Aug 17, 2024
2faeed4
Fix linting error (#1675)
scmet Aug 24, 2024
15a4bbd
Update functionality to add groupmembers (#1675)
scmet Aug 24, 2024
5167b15
Merge branch 'dev' into 1675-web-add-group-creation-and-registration
Zitrone44 Aug 28, 2024
861d72a
Fixed course service to save group registration settings (#1675)
scmet Aug 29, 2024
3ab9484
Merge branch '1675-web-add-group-creation-and-registration' of github…
scmet Aug 29, 2024
6e030ca
fix: add missing course select column
Zitrone44 Sep 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,31 @@ class CourseController {
case _ => throw new ForbiddenException()
}
}

/**
* 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,7 +7,7 @@ import de.thm.ii.fbs.services.security.AuthService

import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.MediaType
import org.springframework.http.{MediaType, ResponseEntity}
import org.springframework.web.bind.annotation._

/**
Expand Down Expand Up @@ -142,4 +142,17 @@ class GroupRegistrationController {
throw new ForbiddenException()
}
}

/**
* Get current number of members of a group
*
* @param cid Course id
* @param gid Group id
* @return Number of members
*/
@GetMapping(Array("/courses/{cid}/groups/{gid}/membership"))
def getGroupMembership(@PathVariable("cid") cid: Integer, @PathVariable("gid") gid: Int): ResponseEntity[Int] = {
val membership = groupRegistrationService.getGroupMembership(cid, gid)
ResponseEntity.ok(membership)
}
}
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 @@ -24,7 +24,7 @@ class CourseService {
* @return List of courses
*/
def getAll(ignoreHidden: Boolean = true): List[Course] = DB.query(
"SELECT course_id, semester_id, name, description, visible FROM course" + (if (ignoreHidden) " WHERE visible = 1" else ""),
"SELECT course_id, group_selection, semester_id, name, description, visible FROM course" + (if (ignoreHidden) " WHERE visible = 1" else ""),
(res, _) => parseResult(res))

/**
Expand All @@ -35,7 +35,7 @@ class CourseService {
* @return List of courses
*/
def findByPattern(pattern: String, ignoreHidden: Boolean = true): List[Course] = DB.query(
"SELECT course_id, semester_id, name, description, visible FROM course WHERE name like ?" + (if (ignoreHidden) " AND visible = 1" else ""),
"SELECT course_id, group_selection, semester_id, name, description, visible FROM course WHERE name like ?" + (if (ignoreHidden) " AND visible = 1" else ""),
(res, _) => parseResult(res), "%" + pattern + "%")

/**
Expand All @@ -45,7 +45,7 @@ class CourseService {
* @return The found course
*/
def find(id: Int): Option[Course] = DB.query(
"SELECT course_id, semester_id, name, description, visible FROM course WHERE course_id = ?",
"SELECT course_id, group_selection, semester_id, name, description, visible, group_selection FROM course WHERE course_id = ?",
(res, _) => parseResult(res), id).headOption

/**
Expand Down Expand Up @@ -86,6 +86,7 @@ class CourseService {

private def parseResult(res: ResultSet): Course = Course(
semesterId = maybeInt(res, "semester_id"),
groupSelection = maybeBoolean(res, "group_selection"),
name = res.getString("name"),
description = res.getString("description"),
visible = res.getBoolean("visible"),
Expand All @@ -100,4 +101,25 @@ class CourseService {
Some(tmp)
}
}

private def maybeBoolean(res: ResultSet, columnName: String): Option[Boolean] = {
val tmp = res.getBoolean(columnName)
if (res.wasNull()) {
null
} else {
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)
}
}
Loading
Loading