Education System based on SpringBoot and REST
- Maven
- JDK-8(not compatible with JDK-9)
-
Create Database
$ mysql -uroot -p 12345 $ create database EAS
-
Edit
application.yml
to set your database name, username and password.spring: datasource: url: jdbc:mysql://localhost:3306/EAS username: root password: 123456
-
Start server
$ mvn spring-boot:run
Then open the address http://localhost:8080 to open the HAL browser.
-
Or you can use the command below to package the application into jar
$ mvn package $ java -jar *.jar # run the application
- SpringBoot
- JPA Hibernate
- Spring Data
- Spring Security
This project use well formatted HAL JSON as response, you can quickly understand them with HAL browser.
There are 5 root resources in current api version, all of this resource support below actions:
-
GET: get REST resouce.
- Paging: request a page of resource.
- Sorting: sort the resource with some of it's properties.
-
POST: create a new REST resource.
-
PATCH: update an existent REST resource with some resouce properties
-
DELETE: delete an existent REST resource.
-
exams{?page,size,sort}
This api exposed all the exams.
-
marks{?page,size,sort}
This api exposed all the marks.
-
users{?page,size,sort}
This api exposed all the users.
-
resources{?page,size,sort}
This api exposed all the course resource.
-
courses{?page,size,sort}
This api exposed all the course.
Take users
resource as an example:
-
GET all the users
GET http://localhost:8080/users
-
GET user by id
GET http://localhost:8080/users/58
-
GET with sorting
Ascending with
email
GET http://localhost:8080/users?sort=email
Decending with
email
:GET http://localhost:8080/users?sort=-email
-
GET with paging
page
specify the page number.size
specify the number of resource in one page.GET http://localhost:8080/users?page=0&size=10
-
GET with search parameter
Not all the resource support search parameters:
GET http://localhost:8080/users/search/[email protected]
To find out all avaliable search parameter under
users
resource:GET http://localhost:8080/users/search/
The response body should be:
{ "_links": { "findByEmail": { "href": "http://69.171.71.251:8080/users/search/findByEmail{?email}", "templated": true }, "self": { "href": "http://69.171.71.251:8080/users/search/" } } }
-
GET subresource
get user with id 58's learning courses:
GET http://localhost:8080/users/58/learning
-
Create user
POST http://localhost:8080/api/users
Body
{ "email": "[email protected]", "password": "$2a$10$x0Qw0EdwJTNnY9DF8xNYfebahJ./8vEOkd0b8sacHJhSVcrnK50t.", "firstName": "test", "lastName": "test", "phone": "12345678901", "roles": [ { "name": "ROLE_TEACHER" }, { "name": "ROLE_USER" } ] }
-
Update user
Update user with id 58
PATCH http://localhost:8080/api/users/58
Body
{ "phone": "10086" }
-
Delete a user
DELETE http://localhost:8080/users/58
-
==Update Subresource==
Add a course with id 59 to user with id 58's learning courses:
$ curl -i -X PUT -d "http://localhost:8080/courses/59"
-H "Content-Type:text/uri-list" http://localhost:8080/users/58/learning
There are 3 levels of users in this application: Admin > Teacher > User
Admin was granted authority to access all api, while Teacher and User only have limited access. Here's a table to demonstrate the auchorities:
"√" denotes full authorities: create, update, delete, query all or single REST resource.
Resource | Admin | Teacher | User |
---|---|---|---|
users | √ | Get/Query single/all User | Get himself |
exams | √ | √ | √ |
resources | √ | √ | √ |
courses | √ | √ | √ |
marks | √ | √ | Get himself |