RestController - THM-ATLAS/spring-backend GitHub Wiki
Overview
Construction
A RestController is a class specified by the @RestController annotation.
RestControllers take a Service as an argument that handles data processing.
Path
src/main/kotlin/com/example/atlasbackend/controller
Mapping
RestControllers specify the mapping of our Restful API.
Every RestController is annotated by @RequestMapping("/api/"), specifying that all subsequent mappings are starting at host/api/ rather than the host URL.
Each route has its specific handler method that is defined by annotating a method with one of the following:
@GetMapping(/route/...)@PostMapping(/route/...)@PutMapping(/route/...)@DeleteMapping(/route/...)
Handler methods
The handler methods pass the deserialized data to its corresponding Service.
A handler can receive the body of the request if annotated with @RequestBody and the path variable with @PathVariable.
Security
To check the permissions of the user who has just sent a request, the AuthenticationPrincipal (currently logged-in user) must be passed in each method, this is done with the annotation @AuthenticationPrincipal user: AtlasUser.
API Documentation
Every handler is also annotated with @ApiResponses which defines the response codes and possible errors for our API Documentation
Our RestControllers
FrontendController
The FrontendController ensures that requests for which no other RESTController exists are forwarded to the frontend.
AssetController
The AssetController deals with raw Assets and their Base64 encoded counterparts.
Path
src/main/kotlin/com/example/atlasbackend/controller/AssetController.kt
Encoded assets
Encoded assets can be returned, created, edited and deleted:
GET /assets/{id}returns an asset.POST /assetscreates an asset.PUT /assetsupdates an asset.DELETE /assets/{id}deletes an asset.
Raw assets
Raw assets may be viewed if they are a picture or downloaded as files:
GET /assets/{id}/viewreturns the image as PNG.GET /assets/{id}/downloadreturns a download prompt containing the file.
ExerciseController
The ExerciseController deals with Tasks and Task Types.
Path
src/main/kotlin/com/example/atlasbackend/controller/ExerciseController.kt
Tasks
Tasks can be returned, created, edited and deleted:
GET /exercisesreturns all tasks.GET /exercises/pages/{pageSize}/{pageNr}returns a page of all tasks.GET /exercises/{exerciseID}returns the task with ID.GET /exercises/user/{userID}returns all tasks to which a user has access.GET /exercises/user/{userID}/pages/{pageSize}/{pageNr}returns a page of all tasks to which a user has access.GET /exercises/module/{modID}returns all tasks that belong to a module.GET /exercises/module/{modID}/pages/{pageSize}/{pageNr}returns a page of all tasks that belong to a module.POST /exercisescreates the task from the requestbody.PUT /exercisesprocesses the task in the requestbody.DELETE /exercises/{exerciseID}deletes tasks with ID.
Task types
Task types can be requested:
GET /exercises/typesreturns all types.
ModuleController
The ModuleController deals with modules, module memberships and module referrals such as links and files.
Path
src/main/kotlin/com/example/atlasbackend/controller/ModuleController.kt
Modules
Modules can be returned, created, edited and deleted:
GET /modulesreturns all modules.GET /modules/pages/{pageSize}/{pageNr}returns a page of all modulesGET /modules/{moduleID}returns module with requested ID.POST /modulescreates the module from the requestbody.PUT /modulesprocesses the module in the requestbody.DELETE /modules/{moduleID}deletes module with ID.
Module memberships
Module memberships can be returned, created, edited and deleted:
GET /modules/users/{moduleID}returns all users that are members of a module.POST /modules/users/{moduleID}adds ModuleUser from RequestBody to module with ID.POST /modules/users/multiple/{moduleID}adds multiple ModuleUser from RequestBody to module with ID.PUT /modules/users/{moduleID}processes ModuleUser in module with ID.DELETE /modules/users/{moduleID}/{userID}removes ModuleUser from module.DELETE /modules/users/{moduleID}removes all ModuleUser from RequestBody from module with ID.
Module referrals
Module referrals can be returned, created and deleted:
GET /modules/referrals/links/{module_id}returns all link referrals.GET /modules/referrals/assets/{module_id}returns all asset referrals.POST /modules/referrals/links/{module_id}creates a link referral.POST /modules/referrals/assets/{module_id}creates an asset referral.DELETE /modules/referrals/links/{module_id}/{referral_id}deletes a link referral by ID.DELETE /modules/referrals/assets/{module_id}/{referral_id}deletes an asset referral by ID.
NotificationController
The NotificationController deals with Notifications and Types of Notifications.
Path
src/main/kotlin/com/example/atlasbackend/controller/NotificationController.kt
Notifications
GET /notifications/user/{userID}returns all notifications of a user.GET /notifications/module/{moduleID}returns all notifications of a module.POST /notificationscreates a notification that is sent to all users.POST /notifications/modulecreates a notification that is sent to all members of a module.PUT /notifications/user/{notification_id}/{user_id}marks a notification as read.DELETE /notifications/user/{notificationID}/{userID}deletes a notification of a user.DELETE /notifications/user/{userID}deletes all notifications of a userDELETE /notifications/module/{notificationID}/{moduleID}deletes a notification of a module for all of themDELETE /notifications/{notificationID}deletes one notification for all
NotificationType
GET notifications/typesreturns all types of notifications
RatingController
The RatingController deals with Ratings of tasks.
Path
src/main/kotlin/com/example/atlasbackend/controller/RatingController.kt
Ratings
Ratings can be returned, created, edited and deleted:
GET /ratings/exercises/{exerciseID}returns all ratings for a task.GET /ratings/users/{userID}returns all the ratings of a user.GET /ratings/{ratingID}returns rating with ID.PUT /ratingsprocesses rating in request body.POST /ratingscreates rating from requestbody.DELETE /ratings/{ratingID}deletes rating with ID.
RoleController
The RoleController deals with Roles
Path
src/main/kotlin/com/example/atlasbackend/controller/RoleController.kt
Roles
Roles can be returned:
GET /rolesreturns all roles.
SettingsController
The SettingsController deals with User settings.
Path
src/main/kotlin/com/example/atlasbackend/controller/SettingsController.kt
Settings
Settings can be returned and created:
GET /settings/{userID}returns settings of a user.PUT /settingsprocesses settings from requestbody.
SubmissionController
The SubmissionController deals with Submission
Path
src/main/kotlin/com/example/atlasbackend/controller/SubmissionController.kt
Submissions
Submissions can be returned, created, edited and deleted:
GET /submissionsreturns all submissions.GET /submissions/pages/{pageSize}/{pageNr}returns a page of all submissionsGET /exercises/{exerciseID}/submissionsreturns all submissions for an exercise.GET /exercises/{exerciseID}/submissions/pages/{pageSize}/{pageNr}returns a page of all submissions to an exerciseGET /users/{subUserID}/submissionsreturns all submissions of a user.GET /users/{subUserID}/submissions/pages/{pageSize}/{pageNr}returns a page of all submissions of a userGET /submissions/{submission_id}returns a submission by ID.GET /exercises/{exerciseID}/submissionreturns the submission of the logged-in user.GET /submissions/code/languagesreturns all code languages for the code-type submission.GET /submissions/code/languages/{language_id}returns a code language for the code-type submission by ID.PUT /submissionsprocesses submission in requestbody.PUT /submissions/gradeprocesses grade of a submission in requestbody.POST /submissionscreates submission from requestbody.DELETE /submissions/{submissionID}deletes submission with ID.
TagController
The TagController deals with TaskTags
Path
src/main/kotlin/com/example/atlasbackend/controller/TagController.kt
Tags
Tags can be returned, created, edited and deleted:
GET /tagsreturns all tags.GET /tags/pages/{pageSize}/{pageNr}returns a page of all tags.GET /exercises/{exerciseID}/tagsreturns all tags of a task.GET /modules/{moduleID}/tagsreturns tags of a module.PUT /tagsprocesses tag in requestbody.POST /tagscreates tag from requestbody.POST /exercises/{exerciseID}/{tagID}adds tag to a task.POST /modules/tags/{moduleID}/{tagID}adds tag to a module.DELETE /tags/{tagID}deletes tag with ID.DELETE /exercises/{exerciseID}/{tagID}removes tag from task.DELETE /module/tags/{moduleID}/{tagID}removes tag from a module.
UserController
The UserController deals with Users
Path
src/main/kotlin/com/example/atlasbackend/controller/UserController.kt
User
Tags can be returned, created, edited and deleted:
GET /usersreturns all users.GET /users/pages/{pageSize}/{pageNr}returns a page of all users.GET /users/mereturns logged in user.GET /users/{id}returns user with ID.PUT /usersprocesses users in Requestbody.POST /userscreates user from Requestbody.POST /users/multiplecreates multiple users from Requestbody.DELETE /users/{id}deletes users with ID.DELETE /users/multipledeletes users from Requestbody.
IconController
The IconController deals with Icons
Path
src/main/kotlin/com/example/atlasbackend/controller/IconController.kt
Icons can be retruned, created and deleted
GET /iconsreturns all IconsPOST /iconscreates an IconDELETE /icons/{idconID}deletes an Icon