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 /assets
creates an asset.PUT /assets
updates 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}/view
returns the image as PNG.GET /assets/{id}/download
returns 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 /exercises
returns 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 /exercises
creates the task from the requestbody.PUT /exercises
processes the task in the requestbody.DELETE /exercises/{exerciseID}
deletes tasks with ID.
Task types
Task types can be requested:
GET /exercises/types
returns 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 /modules
returns all modules.GET /modules/pages/{pageSize}/{pageNr}
returns a page of all modulesGET /modules/{moduleID}
returns module with requested ID.POST /modules
creates the module from the requestbody.PUT /modules
processes 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 /notifications
creates a notification that is sent to all users.POST /notifications/module
creates 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/types
returns 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 /ratings
processes rating in request body.POST /ratings
creates 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 /roles
returns 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 /settings
processes 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 /submissions
returns all submissions.GET /submissions/pages/{pageSize}/{pageNr}
returns a page of all submissionsGET /exercises/{exerciseID}/submissions
returns all submissions for an exercise.GET /exercises/{exerciseID}/submissions/pages/{pageSize}/{pageNr}
returns a page of all submissions to an exerciseGET /users/{subUserID}/submissions
returns 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}/submission
returns the submission of the logged-in user.GET /submissions/code/languages
returns 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 /submissions
processes submission in requestbody.PUT /submissions/grade
processes grade of a submission in requestbody.POST /submissions
creates 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 /tags
returns all tags.GET /tags/pages/{pageSize}/{pageNr}
returns a page of all tags.GET /exercises/{exerciseID}/tags
returns all tags of a task.GET /modules/{moduleID}/tags
returns tags of a module.PUT /tags
processes tag in requestbody.POST /tags
creates 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 /users
returns all users.GET /users/pages/{pageSize}/{pageNr}
returns a page of all users.GET /users/me
returns logged in user.GET /users/{id}
returns user with ID.PUT /users
processes users in Requestbody.POST /users
creates user from Requestbody.POST /users/multiple
creates multiple users from Requestbody.DELETE /users/{id}
deletes users with ID.DELETE /users/multiple
deletes 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 /icons
returns all IconsPOST /icons
creates an IconDELETE /icons/{idconID}
deletes an Icon