From f8886d3270d3f10f25f369552d58e5f352954160 Mon Sep 17 00:00:00 2001 From: AaronR92 <86726028+AaronR92@users.noreply.github.com> Date: Mon, 27 Jun 2022 17:36:48 +0300 Subject: [PATCH] Added readme file --- .gitignore | 57 +++-- README.md | 207 ++++++++++++++++++ build.gradle | 18 +- .../controllers/AdminController.java | 3 +- 4 files changed, 248 insertions(+), 37 deletions(-) create mode 100644 README.md diff --git a/.gitignore b/.gitignore index c2065bc..69d934f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,37 +1,30 @@ -HELP.md -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ +############################## +## Java +############################## +.mtj.tmp/ +*.class +*.jar +*.war +*.ear +*.nar +hs_err_pid* -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache +############################## +## Gradle +############################## bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ +build/ +.gradle +.gradletasknamecache +gradle-app.setting +!gradle-wrapper.jar -### IntelliJ IDEA ### -.idea -*.iws +############################## +## IntelliJ +############################## +out/ +.idea/ +.idea_modules/ *.iml *.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ +*.iws \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..fedae58 --- /dev/null +++ b/README.md @@ -0,0 +1,207 @@ + +# Account Service + +API for company to handle employees, their authorities and payrolls. +All regitred emails must end with @acme.com +Service also has breached passwords table in the database. +## Tech Stack + +**Spring Boot** + +**Spring Security** + +**Spring Data JPA** + +**Project lombok** + +**MySQL database** + + + +## Requests and authorization + +Security requirements based on the **ASVS** + +| | Anonymous | User | Accountant | Administrator | +| :-------------------------- | :-------- | :--- | :--------- | :------------ | +| `POST api/auth/signup` | + | + | + | + | +| `POST api/auth/changepass` | - | + | + | + | +| `GET api/empl/payment` | - | + | + | - | +| `POST api/acct/payments` | - | - | + | - | +| `PUT api/acct/payments` | - | - | + | - | +| `GET api/admin/user` | - | - | - | + | +| `DELETE api/admin/user` | - | - | - | + | +| `PUT api/admin/user/role` | - | - | - | + | + + + +## API + +### Sign up + +``` + POST api/auth/signup +``` +#### Request body +```json +{ + "name": "", + "lastname": "", + "email": "", + "password": "" +} +``` + +#### Description +Saves new employee in the database, password must be longer than 12 chars. +First registred user gets administrator authorities. + + +### Change password + +``` + POST api/auth/changepass +``` +#### Request body +```json +{ + "email": "", + "new_password": "" +} +``` +#### Description +Saves new employees password in the database, password must be longer than 12 chars. + + +### Get payrolls + +``` + GET api/empl/payment +``` +#### Request parameters +| Parameter | Type | Description | +| :-------- | :------- | :------------------------------------------- | +| `period` | `string` | **Not required**. Period of payment to fetch | + +#### Description +Returns all payments of user that send the request, if a period is specified returns his payroll. + + +### Add new payrolls + +``` + POST api/acct/payments +``` +#### Request body +```json +[ + { + "employee": "", + "period": "", + "salary": + }, + { + "employee": "", + "period": "", + "salary": + }, + ... + { + "employee": "", + "period": "", + "salary": + } +] +``` + +#### Description +Adds new payrolls into database, must not be non-repetitive. + + +### Update payroll + +``` + PUT api/acct/payments +``` +#### Request body +```json +{ + "employee": "", + "period": "", + "salary": +} +``` + +#### Description +Updates the payroll with specified period. + + +### Get all users and thier roles + +``` + GET api/admin/user +``` + +#### Description +Returns a list of all registred users and thier authorities. + +### Delete user + +``` + DELETE api/admin/user/{email} +``` + +#### Request parameters +| Parameter | Type | Description | +| :-------- | :------- | :---------------------------------- | +| `period` | `@path` | **Required**. Users email to delete | + +#### Description +Deletes from database user with specified email. + + +### Update user authorities + +``` + PUT api/acct/payments +``` +#### Request body +```json +{ + "user": "", + "role": "", + "operation": "<[GRANT, REMOVE]>" +} +``` + +#### Description +Updates user roles + +## Requirements +* Java 11 or higher +* Gradle 7.4.1 +## Run + +#### 1. Download repository files + +#### 2. Open Command Prompt or PowerShell + +#### 3. Change directory to project + +#### 4. Execute command + +``` +gradle build +``` + +#### 5. Navigate to jars + +``` +cd build/libs +``` + +#### 6. Run jar + +``` +java -jar account-service-0.5.jar +``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index 63527e9..c825e8f 100644 --- a/build.gradle +++ b/build.gradle @@ -4,9 +4,23 @@ plugins { id 'java' } +apply plugin: 'application' + group = 'com.aaronr92' version = '0.5' sourceCompatibility = '11' +mainClassName = "com.aaronr92.accountservice.AccountServiceApplication" + +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} + +jar { + manifest { + attributes "Main-Class" : "com.aaronr92.accountservice.AccountServiceApplication" + } +} configurations { compileOnly { @@ -33,7 +47,3 @@ dependencies { testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' } - -tasks.named('test') { - useJUnitPlatform() -} diff --git a/src/main/java/com/aaronr92/accountservice/controllers/AdminController.java b/src/main/java/com/aaronr92/accountservice/controllers/AdminController.java index 54d020e..358895d 100644 --- a/src/main/java/com/aaronr92/accountservice/controllers/AdminController.java +++ b/src/main/java/com/aaronr92/accountservice/controllers/AdminController.java @@ -4,6 +4,7 @@ import com.aaronr92.accountservice.services.UserService; import com.aaronr92.accountservice.util.RoleOperation; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -15,7 +16,7 @@ public class AdminController { @Autowired - UserService userService; + private UserService userService; @GetMapping("/user") ResponseEntity> getAllRoles() {