KNF Recruitment Task
Original task
Zadaniem jest stworzenie systemu ankietowego. System ten ma umożliwić definiowanie ankiety z następującymi typami pytań:
- Pytanie tekstowe otwarte – ankietowany wprowadza tekst o maksymalnej długości 250 znaków.
- Pytanie o wartość – ankietowany wprowadza wartość liczbową, np. osiągnięty dochód za ubiegły rok.
- Pytanie logiczne – TAK/NIE – ankietowany wybiera określoną wartość
- Pytanie jednokrotnego wyboru
- Pytanie wielokrotnego wyboru
Pytania mogą być grupowane w strony.
Celem zadania jest przygotowanie modelu bazy danych umożliwiającego zaprojektowanie ankiet składających się z wskazanego typu pytań, oraz zebrania danych z wypełnionych ankiet. Przygotowanie frontend jak i backend tak aby było możliwe wypełnienie i zapisanie ankiety przez użytkownika.
Dla uproszczenia zadania można pominąć panel do tworzenia ankiet, przyjąć można, że wzór ankiety może zostać ręcznie utworzony w bazie danych.
Można pominąć kwestie autoryzacji użytkownika. Mile widziane opisanie w jaki sposób zrealizować autoryzacje.
Wymagane technologie:
- Frontend – Angular
- Backend - .NET Core
- baza danych – sugerowany MS SQL, wraz z Entity Framework Core
Dowolność jeśli chodzi o wykorzystanie wzorców projektowych oraz użytych bibliotek.
Designed database schema
For more details see src/Emzi0767.R01.API/Services/DatabaseContext.cs
Test credentials
- user:
user
, password:hunter2
- user:
admin
, password:hunter3
There is extremely basic (albeit functional) authentication implemented. Tokens expire after 10 minutes. The JWT mechanism, however, can be extended to support refresh tokens and external authentication sources (such as OAuth2).
The JWT can encode user data and roles, which can facilitate both authentication and authorization. The roles can be used in conjunction with ASP.NET authorization policies via claims. Leveraging these, access control can be implemented.
In the API project, access control uses presence of the admin claim to determine whether a user has access to certain resources (specifically user enumeration and viewing other users' poll responses).
Available functionality
- Log in
- View available polls
- View a poll
- Create a poll response
- View own poll response
Poll responses are tied to user. Only one response is allowed per user.
How to run
Run the backend component (.NET project). It will provide swagger at http://localhost:5017/swagger.
Don't forget to set the following environment variables:
-
R01__DATABASEFILE
- path to LocalDB database file, should have .mdf extension. -
R01__LOGSENSITIVE
- (optional) whether to log sensitive data in EFCore. True or false. -
R01__JWT__KEY
- base64 key to sign JWTs with. Should be minimum 32 bytes after decoding. -
R01__JWT__ISSUER
- name of the JWT issuer. This will be validated against. -
R01__JWT__AUDIENCE
- name of the JWT audience. This will be validated against.
To run the frontend component, make sure you npm i -g @angular/cli
then npm i --save
first, then ng serve --proxy-config proxy.conf.json
.
Application will then be available at http://localhost:4200.
Libraries and frameworks used
- .NET 8
- Entity Framework Core
- Microsoft SQL Server LocalDB
- JWT Authentication
- Angular 18
- Angular Material
The API project is set up to migrate the database on startup. This will create and/or update the database schema, if necessary.
Backend design
The backend uses Dependency Injection for service resolution. The application is implemented using MVC pattern.
The data models use DTO pattern (meaning there are 2 data model layers: database and DTO). Providing the data to controllers happens via the repository pattern.