|
1 |
| -# University education system Rest-API |
2 |
| -this project only includes the server side of the mentioned system and provides web services. In this document, the term LCRUD or its sub phrases are abbreviations respectively List, Create, Read, Update, Delete |
3 |
| - |
4 |
| -#### Basic design of entities |
5 |
| - |
6 |
| -<br><br> |
7 |
| -#### Description of users: |
8 |
| -• We have four types of users: admin, student, instructor and staff. |
9 |
| -<br> |
10 |
| -• Users have some common information (such as username and password) and some specific information (such as student number that is specific to students). |
11 |
| -<br> |
12 |
| -• A user can be both a student and an instructor. |
13 |
| -<br><br> |
14 |
| -#### Lesson description: |
15 |
| -• We have a number of terms and a number of courses. |
16 |
| -<br> |
17 |
| -• In each term, each instructor can offer a number of lessons, which we call a section. |
18 |
| -<br> |
19 |
| -• Each student can register in a number of study courseSections. |
20 |
| -<br><br> |
21 |
| -### Required web services |
22 |
| -In most of the web services of the system we implemented authentication mechanism, which means that the client should put a suitable header in its request and the server will realize the identity by using it. |
23 |
| -<br> |
24 |
| -Tip: Search for authentication and authorization keywords along with spring. |
25 |
| -<br> |
26 |
| -#### User registration |
27 |
| -Anyone can register by providing username, password, name, phone number and national code. All fields are mandatory. Username, phone number and national code must be unique. If successful, the personal user will be created passively. |
28 |
| -<br> |
29 |
| -Stored users passwords in a hashed form in the database. |
30 |
| -<br> |
31 |
| -#### User Authentication |
32 |
| -Anyone can log in to the system by providing a username and password. If it is correct, the server must provide the necessary information to the client to put in the header in the next requests so that the server can authenticate him. |
33 |
| -<br> |
34 |
| -#### Staff management |
35 |
| -Admin can register another person as a staff in the system by providing the username and personnel ID, and in this case, that user will be activated. |
36 |
| -Explaining that the staff must have registered himself first and then tell the administrator the username so that he can continue the registration. Other LRUD operations must also be enabled by the administrator. |
37 |
| -#### Instructor registration |
38 |
| -Similar to staff registration, with the consideration that CUD operations can be performed by admin and staffs and LR operations can be performed by all users. |
39 |
| -<br> |
40 |
| -#### Student registration |
41 |
| -Similar to instructor registration. |
42 |
| -<br> |
43 |
| -#### Term definition |
44 |
| -In the form of LCRUD, LR can be done by all users and CUD can only be done by admin and staffs. |
45 |
| -<br> |
46 |
| -#### Course definition |
47 |
| -In the form of LCRUD, LR can be done by all users and CUD can only be done by admin and staffs. |
48 |
| -<br> |
49 |
| -#### CourseSection definition |
50 |
| -In the form of LCRUD, LR can be done by all users and C can only be done by the admin. UD operations can be performed by admin, staffs and also by the instructor who himself defined this courseSection. Operation D is conditional on the fact that no student is enrolled in this courseSection. |
51 |
| -<br> |
52 |
| -#### Registration in the courseSection |
53 |
| -It is done by the student and by presenting the class ID. |
54 |
| -<br> |
55 |
| -#### Get the list of class students |
56 |
| -It can be done by the instructor, administrator and staff in such a way that the list of registered students will be presented after receiving the ID of the courseSection. For each student, student ID, name, student number and grade are provided. |
57 |
| -<br> |
58 |
| -#### Grading students |
59 |
| -It can be done by the instructor, in this way, by receiving the class ID, student ID and grade, the grade is registered. |
60 |
| -<br> |
61 |
| -Grading the list of students, in such a way that a courseSection ID and a list of student IDs and grades are received. |
62 |
| -<br> |
63 |
| -#### View term grades |
64 |
| -It can be done by the student, in such a way that upon receiving the term ID, the grade point average of the term as well as the list of student courseSections in that term along with each grade will be provided. For each courseSection, courseSection ID, course name, number of units, instructor's name and grade should be provided. |
65 |
| -<br> |
66 |
| -#### View academic summary |
67 |
| -It can be done by the student, in such a way that it provides the total grade point average of the student as well as the list of terms along with the grade point average of each term. For each term, the term ID, term title and term average should be provided. |
68 |
| -<br> |
69 |
| -### Automated test |
70 |
| -• Write a unit test to calculate the student's GPA in one term. • Write an integration test for this scenario: the instructor defines a courseSection, the student enrolls in that courseSection, |
71 |
| -<br> |
72 |
| -The instructor grades the student, the student sees the term grades correctly (hint: you can use MockMvc if you wish) |
73 |
| -## API Reference |
74 |
| -after building dependencies and running these are some sample endpoints to test |
75 |
| - |
76 |
| -#### Get all users: |
| 1 | +# spring-rest-api-with-jwt |
77 | 2 |
|
78 |
| -```bash |
79 |
| -curl -X GET -w " %{http_code}\n" "http://127.0.0.1:8080/all-users" |
80 |
| -``` |
| 3 | + |
81 | 4 |
|
82 |
| -| Parameter | Type | Description | |
83 |
| -|:--------------------|:------|:-------------------------| |
84 |
| -| `list of all users` | `GET` | No authentication needed | |
| 5 | +## What is this? |
85 | 6 |
|
86 |
| -#### Register a new custom user: |
| 7 | +This is a sample project demos how to use JWT token based authentication to protect the RESTful APIs in a Spring WebMVC application. |
87 | 8 |
|
88 |
| -```bash |
89 |
| -curl -X POST -H "Content-Type: application/json" -d @/absolute/path/to/costumUser.json -w " %{http_code}\n" "http://127.0.0.1:8080/register" |
90 |
| -``` |
| 9 | +## Guide |
| 10 | + |
| 11 | +Check the [full GUIDE](./GUIDE.md) to get the detailed explanation of the example codes. |
| 12 | + |
| 13 | +## Prerequisites |
91 | 14 |
|
92 |
| -| Parameter | Type | Description | |
93 |
| -|:------------------------------------|:-------|:---------------------------------| |
94 |
| -| `customUser json registration file` | `POST` | No authentication needed | |
| 15 | +Make sure you have installed the following software. |
95 | 16 |
|
96 |
| -#### Register a new custom user: |
| 17 | +- Java 17 |
| 18 | +- Apache Maven 3.9.x |
| 19 | + |
| 20 | +## Build |
| 21 | + |
| 22 | +Clone the source codes from Github. |
97 | 23 |
|
98 | 24 | ```bash
|
99 |
| -curl -X POST -H "Content-Type: application/json" -d @/absolute/path/to/userAuth.json -w " %{http_code}\n" "http://127.0.0.1:8080/authenticate" |
| 25 | +git clone https://github.com/clonerplus/rest-api |
100 | 26 | ```
|
101 | 27 |
|
102 |
| -| Parameter | Type | Description | |
103 |
| -|:--------------------------------------|:-------|:-------------------------------------------| |
104 |
| -| `customUser json authentication file` | `POST` | **Required** correct username and password | |
105 |
| - |
106 |
| -| Parameter | Type | Description | |
107 |
| -|:-----------------------|:------|:-------------------------------------------| |
108 |
| -| `authentication token` | `GET` | **Required** correct username and password | |
109 |
| -#### Register a new custom user: |
| 28 | +Open a terminal, and switch to the root folder of the project, and run the following command to build the whole project. |
110 | 29 |
|
111 | 30 | ```bash
|
112 |
| -curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer <access_token>" -d @/absolute/path/to/instructor.json -w " %{http_code}\n" "http://127.0.0.1:8080/authorize/instructor?username=ali" |
| 31 | +mvn clean install // build the project |
113 | 32 | ```
|
114 | 33 |
|
115 |
| -| Parameter | Type | Description | |
116 |
| -|:--------------------------------------|:-------|:-------------------------------------------| |
117 |
| -| `customUser json authentication file` | `POST` | **Required** correct username and password | |
| 34 | +Run the application. |
| 35 | + |
| 36 | +```bash |
| 37 | +mvn spring-boot:run |
| 38 | +// or from command line after building |
| 39 | +java -jar target/xxx.jar |
| 40 | +``` |
118 | 41 |
|
| 42 | +## Contribution |
119 | 43 |
|
120 |
| -**If you found this project helpful, consider giving it a star ⭐️ for others to find! ❤️** |
| 44 | +Any suggestions are welcome, filing an issue or submitting a PR is also highly recommended. |
| 45 | +**If you found this project helpful, consider giving it a star ⭐️ for others to find! ❤️** |
121 | 46 |
|
122 | 47 | [](https://github.com/clonerplus/rest-api)
|
0 commit comments