Controller - HeilOliver/Timeify GitHub Wiki

The controllers used for the individual rest APIs are all derived from the Mvc controller class. They are also provided with the attributes "[ApiController]" which generates default responses for errors and other api related responses.

Furthermore the controllers are provided with the attributes for the respective API route.

[ApiController]
[Route("api/[controller]")]
public class JobController : Controller

The routers are divided into functional groups and thus reflect a domain-specific grouping.

Any API methode uses an atribute to distinct between different HTTP request types. This HTTP types are related to what this methode is doing.

  • [HttpPut] For creating new resources on the API
  • [HttpPost] For updateing data and sending data to the API
  • [HttpGet] For getting data from the API
  • [HttpDelete] For deleting resources from the API

If possible, the JSON Body variant was selected for parameter transfer. This means that the parameter is not sent via HTTP parameters ("example?par1=20,par2=30") instead it is sent as a JSON object in the HTTP body.

As a response, an IActionResult can be found for all API methods. In addition to the HTTP status code, the Action Result contains a JSON body which contains further information such as errors.

In order for Swagger to display the response types, there is an attribute required which specifies the respective return type. [ProducesResponseType(typeof(ReturnType), StatusCodes.Status200OK)]

AccountsController

The AccountController is responsible for registering new users. He offers a method to create a new user.

AuthController

The AuthController offers a method for an already registered user to log in. This method sends back a JWT token and the corresponding refreshtoken after a successful login. Since JWT tokens are only valid for a limited time, they must be updated after a certain time. For this the controller offers a second method which allows the user to refresh the token. For this the refresh token is needed which will also be refreshed. Both will be refreshed and returned.

JobController

The JobController offers the user the possibility to create, delete or update new jobs. Furthermore, its jobs can be loaded. The user is only allowed to delete or update his own jobs. In case a user wants to update/delete another job, he is not allowed to do so. In addition to the methods mentioned above, the controller also provides the ability to load all jobs. All jobs means that only jobs that are owned and/or assigned to the user will be loaded.

TaskController

The TaskController offers like the JobController the possibility to create, delete or update tasks. As with the jobs, it is of course a prerequisite that only your own tasks can be updated or deleted. In addition to the above mentioned methods the controller offers the possibility to get tasks for a certain job. Here only the tasks are sent which are either your own or you have been assigned to.

UsersController

The UserController offers the possibility to return all registered users. The own username is included.

SessionController

Since data about your own user is never returned during login, the SessionController offers the possibility to load your own user data. The passed JWT token is used as username source.

WorkController

The WorkController is required to assign tasks to users. It offers two methods to assign or remove a task from a user. To do this, the user must be the owner of the task. Furthermore the WorkController offers the possibility to mark tasks as finished and open. A user assigned to the task can mark a task as finished or undo its action with unfinish.