diff --git a/.env.sample b/.env.sample
new file mode 100644
index 00000000..659928a1
--- /dev/null
+++ b/.env.sample
@@ -0,0 +1,17 @@
+DB_NAME=skilltree
+MYSQL_DB_USERNAME=testuser
+MYSQL_DB_PASSWORD=testpassword
+MYSQL_ROOT_PASSWORD=password
+DB_DDL_POLICY=update
+RDS_BACKEND_BASE_URL=http://localhost:3000
+SKILL_TREE_FRONTEND_BASE_URL=https://localhost
+SKILL_TREE_BACKEND_BASE_URL=http://localhost:8080
+RDS_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAg5HrGgKFmH485DXLG4fG
+ 1mKNXceWthXgAozsUGHxLIM3Fa5wU+tLi7tLDZ6LRKo4ZZV2gJJdDqFSNsvn1Uvr
+ XygvkCCRD/DYjxpG/qNiq9kgv7G8gjVI394oJWgx9uWTmDp4DmEVi7rIviyqVimE
+ V1nzdlKfGeLckagsetPS28rqULVGXaIAOL52vzrk3O74MnvCSVkjH/+cxEHE7XGg
+ ryy1fcH9CXvgrXxOLG2xrIdHrV39WBaMC4KOt5piCXgz2tAfhy47x6tIaEj5URx/
+ jxQoSPZJ5TAf27pjPvUkGVs726RlO0tBLteNzTAWCVZ0QeMoMzBwtdloouC+Rzj2
+ 8QIDAQAB
+ -----END PUBLIC KEY-----"
\ No newline at end of file
diff --git a/.github/workflows/deploy-to-ec2.yml b/.github/workflows/deploy-to-ec2.yml
index c31820d5..c7af87a2 100644
--- a/.github/workflows/deploy-to-ec2.yml
+++ b/.github/workflows/deploy-to-ec2.yml
@@ -5,7 +5,6 @@ on:
branches:
- main
- develop
- - feat/aws-deploy # Remove before merting this PR to dev
jobs:
build-and-push:
@@ -53,5 +52,14 @@ jobs:
--name ${{ github.event.repository.name }}-${{ vars.ENV }} \
--network=${{ vars.DOCKER_NETWORK }} \
-e RDS_PUBLIC_KEY="${{ secrets.RDS_PUBLIC_KEY }}" \
+ -e MYSQL_HOST="${{ secrets.MYSQL_HOST }}" \
+ -e MYSQL_PORT="${{ secrets.MYSQL_PORT }}" \
+ -e DB_NAME="${{ vars.DB_NAME }}" \
+ -e MYSQL_DB_USERNAME="${{ secrets.MYSQL_DB_USERNAME }}" \
+ -e MYSQL_DB_PASSWORD="${{ secrets.MYSQL_DB_PASSWORD }}" \
+ -e RDS_BACKEND_BASE_URL="${{ vars.RDS_BACKEND_BASE_URL }}" \
+ -e SKILL_TREE_BACKEND_BASE_URL="${{ vars.SKILL_TREE_BACKEND_BASE_URL }}" \
+ -e SKILL_TREE_FRONTEND_BASE_URL="${{ vars.SKILL_TREE_FRONTEND_BASE_URL }}" \
+ -e SPRING_PROFILES_ACTIVE="${{ vars.SPRING_PROFILES_ACTIVE }}" \
-e API_V1_PREFIX=/api/v1 \
${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}
diff --git a/Makefile b/Makefile
index a8e5ceb6..62e3ca5e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,6 @@
+copy-env:
+ cp .env.sample .env
+
# Setup MySql Database
docker-run:
@if command -v docker > /dev/null; then \
@@ -21,5 +24,8 @@ setup:
@echo "--- Setting up docker ---"
@make docker-run
+ @echo "--- Copying env ---"
+ @make copy-env
+
@echo "\n"
@echo "Setup complete!"
\ No newline at end of file
diff --git a/README.md b/README.md
index 3ac54c6d..53a67505 100644
--- a/README.md
+++ b/README.md
@@ -1,197 +1,78 @@
# Skill Tree Backend
-## Steps to Run the Service Locally
-
-### Required Tools
-
-- [Maven](https://maven.apache.org/download.cgi) version 3.9.6 or higher
-
-Installing Maven on macOS using Homebrew:
-
-1. Open your terminal.
-2. Type the following command and press Enter to install Homebrew (if not installed):
-
-```bash
-/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-```
-
-3. Once Homebrew is installed, run the following command to install Maven:
+## Required Tools
+- [Homebrew](https://brew.sh/) (If you're using macOS)
+- [Maven](https://maven.apache.org/download.cgi) (version 3.9.6 or higher)
+- [Java](https://www.oracle.com/in/java/technologies/downloads/#java17) (version 17)
+- [IntelliJ Community or Ultimate Edition](https://www.jetbrains.com/idea/download/other.html)
+- [Docker Desktop](https://www.docker.com/products/docker-desktop/)
+
+## Development Setup
+### Install Maven
+#### macOS
+1. To install maven type the following command in your terminal:
+ ```bash
brew install maven
-
-4. Wait for the installation process to complete.
-
-5. Verify the Maven installation by typing:
+ ```
+2. Verify your installation using the following command:
+ ```bash
mvn -version
+ ```
+ If maven is installed correctly you should see the maven version in the terminal:
+ ```bash
+ Apache Maven 3.9.7
+ ```
-This should display information about the installed Maven version.
-
-Installing Maven on Windows:
-
+#### Windows
1. To install Maven on Windows, we head over to the Apache Maven site to download the latest version and select the Maven zip file, for example, apache-maven-3.9.6-bin.zip.
-
2. Adding Maven to the Environment Path
We add both M2_HOME and MAVEN_HOME variables to the Windows environment using system properties and point them to our Maven folder.
-
3. Verify the Maven installation by typing:
mvn -version
+4. Then, we update the PATH variable by appending the Maven bin folder — %M2_HOME%\bin — so that we can run the Maven command everywhere.
+
+### Setup database and configure env
+- To setup the database & create a `.env` file run the following command in your terminal:
+ ```bash
+ make setup
+ ```
+ - To edit your environment variables edit the `.env` file.
+
+#### NOTE:
+- If you do not have `make` installed, run the `docker-run` and `copy-env` commands from the `Makefile` manually.
+
+### Install EnvFile Plugin in IntelliJ
+- To read the values from your `.env` you will need install the `EnvFile` plugin.
+- To Install the plugin to go `settings` > `Plugins` > `Marketplace` > EnvFile.
+ ![img.png](public/highlight-env-file-plugin.png)
+
+### Create a configuration in IntelliJ
+- Press the Edit configurations button on the top right of your screen
+ ![img.png](public/highlight-edit-config.png)
+- Create a new application
+ ![img.png](public/create-new-application.png)
+- Select `Java version 17`, `Skill tree` and `SkillTreeApplication`
+ ![img.png](public/highlight-java-version-main-class.png)
+- Check `EnvFile` and `Substitute Environment Variables`
+ ![img.png](public/highlight-check-env.png)
+- Add path to the `.env` file you created above
+ ![img.png](public/highlight-add-new-env-cta.png)
+ - You should a new entry like so:
+ ![img.png](public/highlight-env-list.png)
+ - Click on `Apply` and then `Ok`
+
+### Running your application
+- Press the `Run` button on the top right of your screen to run the application.
+ ![img.png](public/highlight-run-application.png)
+
+## Steps to authenticate a user during development
+- Run RDS backend on your local machine
+- Copy the `public key` from `local.js` (if not in `local.js` copy it from `development.js`) and add it in your `.env` file.
+- Run skill tree frontend, click on `signin with github` button
+ - Once authenticated you will be redirected to `localhost:4000` (skill tree frontend homepage) and a `rds-session-v2-development` cookie will be set in the browser which will be used for authentication when making API calls.
+ - NOTE:
+ - make sure that `incompleteUserDetails` is false for the user in firestore, else the redirect will not work as intended.
-Then, we update the PATH variable by appending the Maven bin folder — %M2_HOME%\bin — so that we can run the Maven command everywhere.
-
-Then, we unzip it to the folder where we want Maven to live.
-
-- Java (version 17 or higher) [Link](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html)
-- Any text editor of your choice (Preferred - IntelliJ Community or Ultimate Edition).
-- Docker Desktop: [Installation steps](https://docs.docker.com/engine/install/)
-- MySQL Docker Image: [Installation steps](https://hub.docker.com/_/mysql)
-
-### Steps to Login to MySQL
-
-1. Go to Docker Desktop
-
-2. You'll see skill-tree-backed (If the process is running)
-
-3. skill-tree-backend > skill-tree-backend-db-1 > open in terminal
-
-To login to MySQL
-
-```
-mysql -u root -p
-```
-
-(in terminal)
-password : password
-
-Reference Screenshots:
-
-If the project is started with `docker compose up`, this can be seen once you open Docker Desktop:
-
-
-
-Terminal needs to be opened here:
-
-![image](https://github.com/ashifkhn/skill-tree-backend/assets/54736284/d66166ae-b931-40ab-914f-f42615323a32)
-
-## Steps for Creating the Database (To be executed in order)
-
-Semicolon is important in the commands
-
-Username: testuser
-Password: testpassword
-
-```
-CREATE DATABASE skilltree;
-SHOW DATABASES;
-CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'testpassword';
-GRANT ALL ON skilltree.* TO testuser;
-```
-
-## Steps for setting up skill-tree in Intellij
-
-1. After creating the database project needs to be compiled.
-2. Open skill-tree-backend in intellij.
-3. Java_Home path needs to be added here.
-4. You can either add the existing path and JDK 17 can be downloaded inside intellij.
-5. If adding from the existing path, go to Settings > Project Structure > Choose the earlier installed Java 17 SDK.
-6. Install Lombok plug-in, if you see annotation errors
-
-## Creating Run/Debug Configuration
-
-1. Create a .env file inside the skill-tree folder with content mentioned in the Additional Configuration Steps below
-2. Click on "Edit Configurations" > Add new "Application" Configuration
-3. Choose "Java 17" and "skill-tree" folder in the dropdown
-4. Choose com.RDS.skilltree.SkillTreeApplication as the Main class
-5. Add the .env file you created in the first step for the environment variables and click "OK"
-
-(Below steps are not required as of now.)
-
-### Steps to Connect the Service to MySQL Running in Docker
-
-Refer to this [link](https://find10archived.medium.com/how-to-connect-a-mysql-docker-container-with-a-local-spring-boot-application-9366707dce0d) for detailed steps.
-
-1. Create a database user with full access for table creation, deletion, and modification (for development only in local MySQL).
-2. After creating the database user, enter the credentials in the Skill Tree Spring Boot application.
-3. Attempt to connect to the database using the URL "jdbc:mysql://${MYSQL_HOST:localhost}:3306/${DB_NAME}".
-4. Create a simple API to test the database connection and data retrieval. For example, create a `/test` route in `skill-tree/src/main/java/com/RDS/skilltree/User/UserController.java`.
-
- ```java
- package com.RDS.skilltree.User;
-
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RestController;
-
- @RestController
- public class UserController {
- @GetMapping("/test")
- public void test(){
- System.out.println("test123");
- }
- }
- ```
-
-### Steps to Generate a JWT Token (Similar to [Website Backend Repo](https://github.com/Real-Dev-Squad/website-backend/issues))
-
-1. If you've already generated the public and private keys during the website backend setup, you can proceed directly to step 5.
-2. Ensure the website-backend is running locally.
-3. Generate Public and Private keys using openssl with the following commands:
- - `openssl genrsa -out ./private.key 4096`
- - `openssl rsa -in private.key -pubout -outform PEM -out public.key`
-4. Obtain a user token (private and public key stored in `local.js` file).
-5. After calling `localhost:3000/auth/github/login`, the backend will generate the JWT token.
-6. Validate the token using [jwt.io](https://jwt.io/) by entering the public and private keys stored in the website backend.
-7. Use the public key in the Skill Tree repo to decrypt the JWT token passed for authentication.
-
-## Steps for connecting mysql workbench to run mysql inside docker
-
-1. `docker exec -it skill-tree-db-1 bin/bash`
-2. bash-4.4# `mysql -u root -p -A`
-
-By default after deployment MySQL has following connection restrictions:
-
-```
-mysql> select host, user from mysql.user;
-+-----------+---------------+
-| host | user |
-+-----------+---------------+
-| localhost | healthchecker |
-| localhost | mysql.session |
-| localhost | mysql.sys |
-| localhost | root |
-+-----------+---------------+
-4 rows in set (0.00 sec)
-```
-
-Apparently, for security purposes, you will not be able to connect to it from outside of the docker container. If you need to change that to allow root to connect from any host (say, for development purposes), do the following:
-
-3. update mysql.user set host='%' where user='root';
-4. Quit the mysql client.
-5. Restart the docker container
-
-Now you can connect to the mysql running in the docker container, also to connect to it on the terminal type `mysql -utestuser -p -P3306 -h127.0.0.1`
-
-## Additional Configuration Steps
-
-1. Download the EnvFile plugin from the marketplace.
-2. Create a new Env file with the provided content and fill in the RDS public key value.
- ```env
- DB_NAME=${DB_NAME}
- MYSQL_DB_USERNAME=testuser
- MYSQL_DB_PASSWORD=testpassword
- MYSQL_ROOT_PASSWORD=password
- DB_DDL_POLICY=update
- RDS_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
- -----END PUBLIC KEY-----"
- ```
- > Note : Publickey in both [RDS backend](https://github.com/Real-Dev-Squad/website-backend) and skilltree backend should be the same.
-3. Click "Edit Configurations" -> Create a new application.
-4. Give it a name instead of "Unnamed".
-5. In "Build and Run", select Java 17.
-6. In the class , check "Enable Env file" and "Substitute env var" checkboxes.
-7. Click "Apply" and "OK".
-8. Click "Build and Run".
-9. Retrieve the Bearer token by accessing `http://localhost:3000/auth/github/login` and locating the key `rds-session-development` in the application. The value associated with this key is the `Bearer token`.
-10. Click the green "Run" button or "Shift + F10" to start the application
-11. After starting the Tomcat server on port `8080`, attempt to access the dummy route `http://localhost:8080/test` using the `GET` method in Postman or ThunderClient while providing the `bearer token`. If the terminal displays `test123`, it indicates that the setup has been successful.
## To Authenticate Yourself
@@ -212,10 +93,3 @@ Please build using `mvn compile` in local or run `mvn spotless:apply` before pus
To check if the codebase is formatted, you can explicitly use `mvn spotless:check`
The Continuous Integration build for pushed commits may fail when a Pull Request is created if your code doesn't follow project's formatting guideline.
-
-## Known Issues Faced by Other Developers
-
-1. Port 8080 Conflict: Make sure there is no other process running on the 8080 port where we are going to run our server check this with lsof -p PID (PID - port id)
-2. Local MySQL Conflict: Make sure there is no local Mysql running on the local machine
-
----
diff --git a/public/create-new-application.png b/public/create-new-application.png
new file mode 100644
index 00000000..625fc9f7
Binary files /dev/null and b/public/create-new-application.png differ
diff --git a/public/highlight-add-new-env-cta.png b/public/highlight-add-new-env-cta.png
new file mode 100644
index 00000000..b5bd64d9
Binary files /dev/null and b/public/highlight-add-new-env-cta.png differ
diff --git a/public/highlight-check-env.png b/public/highlight-check-env.png
new file mode 100644
index 00000000..fc25934e
Binary files /dev/null and b/public/highlight-check-env.png differ
diff --git a/public/highlight-edit-config.png b/public/highlight-edit-config.png
new file mode 100644
index 00000000..7f362182
Binary files /dev/null and b/public/highlight-edit-config.png differ
diff --git a/public/highlight-env-file-plugin.png b/public/highlight-env-file-plugin.png
new file mode 100644
index 00000000..25aba38c
Binary files /dev/null and b/public/highlight-env-file-plugin.png differ
diff --git a/public/highlight-env-list.png b/public/highlight-env-list.png
new file mode 100644
index 00000000..adac3344
Binary files /dev/null and b/public/highlight-env-list.png differ
diff --git a/public/highlight-java-version-main-class.png b/public/highlight-java-version-main-class.png
new file mode 100644
index 00000000..742a0e8b
Binary files /dev/null and b/public/highlight-java-version-main-class.png differ
diff --git a/public/highlight-run-application.png b/public/highlight-run-application.png
new file mode 100644
index 00000000..0c729b38
Binary files /dev/null and b/public/highlight-run-application.png differ
diff --git a/skill-tree/pom.xml b/skill-tree/pom.xml
index 167467e8..ac132714 100644
--- a/skill-tree/pom.xml
+++ b/skill-tree/pom.xml
@@ -5,7 +5,7 @@
org.springframework.boot
spring-boot-starter-parent
- 3.1.2
+ 3.3.2
com.RDS
@@ -114,6 +114,16 @@
5.3.1
test
+
+ org.flywaydb
+ flyway-core
+ 10.17.1
+
+
+ org.flywaydb
+ flyway-mysql
+ 10.17.1
+
diff --git a/skill-tree/skilltree-database-script.sql b/skill-tree/skilltree-database-script.sql
deleted file mode 100644
index 2c9afbb9..00000000
--- a/skill-tree/skilltree-database-script.sql
+++ /dev/null
@@ -1,90 +0,0 @@
-CREATE DATABASE IF NOT EXISTS skilltree;
-USE skilltree;
-
-CREATE TABLE `users` (
- `id` binary(16) NOT NULL,
- `created_at` datetime(6) DEFAULT NULL,
- `updated_at` datetime(6) DEFAULT NULL,
- `first_name` varchar(255) NOT NULL,
- `image_url` varchar(255) NOT NULL,
- `last_name` varchar(255) DEFAULT NULL,
- `rds_user_id` varchar(255) DEFAULT NULL,
- `user_role` enum('MAVEN','MEMBER','SUPERUSER','USER') NOT NULL,
- `created_by` binary(16) DEFAULT NULL,
- `updated_by` binary(16) DEFAULT NULL,
- `user_type` tinyint DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `FKibk1e3kaxy5sfyeekp8hbhnim` (`created_by`),
- KEY `FKci7xr690rvyv3bnfappbyh8x0` (`updated_by`),
- CONSTRAINT `FKci7xr690rvyv3bnfappbyh8x0` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`),
- CONSTRAINT `FKibk1e3kaxy5sfyeekp8hbhnim` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-
-CREATE TABLE `skill` (
- `id` binary(16) NOT NULL,
- `created_at` datetime(6) DEFAULT NULL,
- `updated_at` datetime(6) DEFAULT NULL,
- `is_deleted` bit(1) NOT NULL,
- `name` varchar(255) NOT NULL,
- `skill_type` enum('ATOMIC','DERIVED') NOT NULL,
- `created_by` binary(16) DEFAULT NULL,
- `updated_by` binary(16) DEFAULT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `uc_skill_name` (`name`),
- KEY `FKk9ihlls00bo5ljvdgnsgf7r5w` (`created_by`),
- KEY `FKga0cp46ei9oe50sknbkty2xh7` (`updated_by`),
- CONSTRAINT `FKga0cp46ei9oe50sknbkty2xh7` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`),
- CONSTRAINT `FKk9ihlls00bo5ljvdgnsgf7r5w` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-CREATE TABLE `endorsements` (
- `id` binary(16) NOT NULL,
- `created_at` datetime(6) DEFAULT NULL,
- `updated_at` datetime(6) DEFAULT NULL,
- `endorsement_status` enum('APPROVED','PENDING','REJECTED') DEFAULT NULL,
- `created_by` binary(16) DEFAULT NULL,
- `updated_by` binary(16) DEFAULT NULL,
- `skill_id` binary(16) DEFAULT NULL,
- `user_id` binary(16) DEFAULT NULL,
- PRIMARY KEY (`id`),
- KEY `FK3sf16mlcqdyg1onb1jc6mxeio` (`created_by`),
- KEY `FK6emgcd942r9a82xxexnqnylq1` (`updated_by`),
- KEY `FKjuhgii7d9bdgjke3oj23bekjr` (`skill_id`),
- KEY `FKqifr4ov88b3t52y9y0ulyuk84` (`user_id`),
- CONSTRAINT `FK3sf16mlcqdyg1onb1jc6mxeio` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
- CONSTRAINT `FK6emgcd942r9a82xxexnqnylq1` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`),
- CONSTRAINT `FKjuhgii7d9bdgjke3oj23bekjr` FOREIGN KEY (`skill_id`) REFERENCES `skill` (`id`),
- CONSTRAINT `FKqifr4ov88b3t52y9y0ulyuk84` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-CREATE TABLE `endorsement_list` (
- `id` binary(16) NOT NULL,
- `created_at` datetime(6) DEFAULT NULL,
- `updated_at` datetime(6) DEFAULT NULL,
- `is_deleted` bit(1) NOT NULL,
- `description` varchar(255) DEFAULT NULL,
- `type` enum('NEGATIVE','POSITIVE') NOT NULL,
- `created_by` binary(16) DEFAULT NULL,
- `updated_by` binary(16) DEFAULT NULL,
- `endorsement_id` binary(16) DEFAULT NULL,
- `user_id` binary(16) DEFAULT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `UK_b2pke547fdyxfb3oxigi5pjm3` (`user_id`),
- KEY `FKqqxe0t3a2s23kgb2f48holnkk` (`created_by`),
- KEY `FKpegfdaa9fjc38wu10554ib3bj` (`updated_by`),
- KEY `FK1b6wybyeg8g4h5ov6pku3or7x` (`endorsement_id`),
- CONSTRAINT `FK1b6wybyeg8g4h5ov6pku3or7x` FOREIGN KEY (`endorsement_id`) REFERENCES `endorsements` (`id`),
- CONSTRAINT `FKpegfdaa9fjc38wu10554ib3bj` FOREIGN KEY (`updated_by`) REFERENCES `users` (`id`),
- CONSTRAINT `FKqqxe0t3a2s23kgb2f48holnkk` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`),
- CONSTRAINT `FKr2uc9u9bi64lae1hiy61v206h` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-
-CREATE TABLE `user_skill` (
- `user_id` binary(16) NOT NULL,
- `skill_id` binary(16) NOT NULL,
- PRIMARY KEY (`user_id`,`skill_id`),
- KEY `FKj53flyds4vknyh8llw5d7jdop` (`skill_id`),
- CONSTRAINT `FKc2o84wspod5se9pa8lxmhig0q` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`),
- CONSTRAINT `FKj53flyds4vknyh8llw5d7jdop` FOREIGN KEY (`skill_id`) REFERENCES `skill` (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Authentication/UserAuthenticationToken.java b/skill-tree/src/main/java/com/RDS/skilltree/Authentication/UserAuthenticationToken.java
index e2efea72..7780b9b4 100644
--- a/skill-tree/src/main/java/com/RDS/skilltree/Authentication/UserAuthenticationToken.java
+++ b/skill-tree/src/main/java/com/RDS/skilltree/Authentication/UserAuthenticationToken.java
@@ -1,7 +1,7 @@
package com.RDS.skilltree.Authentication;
-import com.RDS.skilltree.User.UserModel;
-import com.RDS.skilltree.User.UserRole;
+import com.RDS.skilltree.enums.UserRoleEnum;
+import com.RDS.skilltree.models.JwtUser;
import java.util.List;
import javax.security.auth.Subject;
import org.springframework.security.authentication.AbstractAuthenticationToken;
@@ -9,11 +9,12 @@
public class UserAuthenticationToken extends AbstractAuthenticationToken {
- private final UserModel user;
+ private final JwtUser user;
public UserAuthenticationToken(String role, String rdsUserId) {
- super(List.of(new SimpleGrantedAuthority(UserRole.fromString(role).name())));
- this.user = UserModel.builder().rdsUserId(rdsUserId).role(UserRole.fromString(role)).build();
+ super(List.of(new SimpleGrantedAuthority(UserRoleEnum.fromString(role).name())));
+
+ this.user = new JwtUser(rdsUserId, UserRoleEnum.fromString(role));
setAuthenticated(true);
}
@@ -23,7 +24,7 @@ public Object getCredentials() {
}
@Override
- public UserModel getPrincipal() {
+ public JwtUser getPrincipal() {
return user;
}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementController.java b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementController.java
deleted file mode 100644
index 7b154118..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementController.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package com.RDS.skilltree.Endorsement;
-
-import com.RDS.skilltree.Common.Response.GenericResponse;
-import jakarta.persistence.EntityNotFoundException;
-import jakarta.validation.Valid;
-import jakarta.validation.constraints.Min;
-import java.io.IOException;
-import java.util.UUID;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
-
-@RestController
-@RequestMapping("/v1/endorsements")
-@Slf4j
-@RequiredArgsConstructor
-public class EndorsementController {
- private final EndorsementService endorsementService;
-
- @GetMapping(value = "")
- public ResponseEntity> getAllEndorsements(
- @RequestParam(name = "offset", defaultValue = "0", required = false) @Min(0) int offset,
- @RequestParam(name = "limit", defaultValue = "10", required = false) @Min(1) int limit,
- @RequestParam(name = "skillID", required = false) String skillID,
- @RequestParam(name = "userID", required = false) String userID,
- @RequestParam(name = "dummyData", required = false) boolean dummyData)
- throws IOException {
- PageRequest pageRequest = PageRequest.of(offset, limit);
- if (dummyData) {
- Page pagedEndorsements =
- endorsementService.getEndorsementsFromDummyData(pageRequest, skillID, userID);
- if (pagedEndorsements.isEmpty()) {
- return ResponseEntity.noContent().build();
- } else {
- return ResponseEntity.ok(pagedEndorsements);
- }
- } else {
- return ResponseEntity.ok(endorsementService.getEndorsements(pageRequest));
- }
- }
-
- @GetMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity> getEndorsementById(
- @PathVariable(value = "id", required = true) String id) {
- try {
- UUID uuid = UUID.fromString(id);
- EndorsementDTO response = endorsementService.getEndorsementById(uuid);
- return ResponseEntity.ok()
- .body(new GenericResponse(response, "Data retrieved successfully"));
- } catch (IllegalArgumentException e) {
- String message = "Invalid UUID: " + id;
- return ResponseEntity.status(HttpStatus.BAD_REQUEST)
- .body(new GenericResponse(null, message));
- } catch (EntityNotFoundException e) {
- return ResponseEntity.status(HttpStatus.NOT_FOUND)
- .body(new GenericResponse(null, e.getMessage()));
- } catch (Exception e) {
- String message = "Something went wrong. Please contact admin.";
- return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
- .body(new GenericResponse(null, message));
- }
- }
-
- @PostMapping(value = "")
- public ResponseEntity> postEndorsement(
- @RequestBody @Valid EndorsementDRO endorsementDRO) {
-
- EndorsementModel endorsementModel = endorsementService.createEndorsement(endorsementDRO);
- if (endorsementModel != null)
- return new ResponseEntity<>(
- new GenericResponse(EndorsementDTO.toDto(endorsementModel), ""),
- HttpStatus.CREATED);
- return new ResponseEntity<>(
- new GenericResponse(null, "Failed to create endorsement"),
- HttpStatus.BAD_REQUEST);
- }
-
- @PatchMapping(value = "/{id}")
- public ResponseEntity> updateEndorsementStatus(
- @PathVariable(value = "id") UUID id, @RequestParam String status) {
- return ResponseEntity.ok().body(endorsementService.updateEndorsementStatus(id, status));
- }
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementDRO.java b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementDRO.java
deleted file mode 100644
index d0910431..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementDRO.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.RDS.skilltree.Endorsement;
-
-import jakarta.validation.constraints.NotNull;
-import java.util.UUID;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@NoArgsConstructor
-@AllArgsConstructor
-@Data
-@Builder
-public class EndorsementDRO {
- @NotNull(message = "user id cannot be null")
- private UUID endorseeId;
-
- @NotNull(message = "skill id cannot be null")
- private UUID skillId;
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementDTO.java b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementDTO.java
deleted file mode 100644
index 3047e63f..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementDTO.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.RDS.skilltree.Endorsement;
-
-import com.RDS.skilltree.EndorsementList.EndorsementListModel;
-import com.RDS.skilltree.Skill.SkillDTO;
-import com.RDS.skilltree.utils.TrackedProperties;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import java.util.List;
-import java.util.UUID;
-import lombok.*;
-
-@Getter
-@Builder
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class EndorsementDTO extends TrackedProperties {
- private UUID id;
- private UUID endorseeId;
- private SkillDTO skill;
- private EndorsementStatus status;
- private List endorsersList;
-
- public static EndorsementDTO toDto(EndorsementModel endorsementModel) {
- EndorsementDTO endorsementDTO =
- EndorsementDTO.builder()
- .id(endorsementModel.getId())
- .endorseeId(endorsementModel.getEndorseeId())
- .skill(SkillDTO.toDto(endorsementModel.getSkill()))
- .status(endorsementModel.getStatus())
- .endorsersList(endorsementModel.getEndorsersList())
- .build();
- endorsementDTO.setCreatedAt(endorsementModel.getCreatedAt());
- endorsementDTO.setUpdatedAt(endorsementModel.getUpdatedAt());
- endorsementDTO.setCreatedBy(endorsementModel.getCreatedBy());
- endorsementDTO.setUpdatedBy(endorsementModel.getUpdatedBy());
- return endorsementDTO;
- }
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementModel.java b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementModel.java
deleted file mode 100644
index 68a3faec..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementModel.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.RDS.skilltree.Endorsement;
-
-import com.RDS.skilltree.EndorsementList.EndorsementListModel;
-import com.RDS.skilltree.Skill.SkillModel;
-import com.RDS.skilltree.utils.TrackedProperties;
-import com.fasterxml.jackson.annotation.JsonManagedReference;
-import jakarta.persistence.*;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-import lombok.*;
-
-@AllArgsConstructor
-@NoArgsConstructor
-@Entity
-@Builder
-@Getter
-@Table(name = "endorsements")
-public class EndorsementModel extends TrackedProperties {
- @Id
- @GeneratedValue
- @Column(name = "id", columnDefinition = "BINARY(16)")
- private UUID id;
-
- @Column(name = "endorsee_id")
- private UUID endorseeId;
-
- @ManyToOne(targetEntity = SkillModel.class, cascade = CascadeType.ALL)
- @JoinColumn(name = "skill_id", referencedColumnName = "id")
- private SkillModel skill;
-
- @OneToMany(mappedBy = "endorsement")
- @JsonManagedReference
- private List endorsersList = new ArrayList<>();
-
- @Column(name = "endorsement_status")
- @Enumerated(value = EnumType.STRING)
- private EndorsementStatus status = EndorsementStatus.PENDING;
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementModelFromJSON.java b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementModelFromJSON.java
deleted file mode 100644
index c399043d..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementModelFromJSON.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.RDS.skilltree.Endorsement;
-
-import com.fasterxml.jackson.annotation.JsonFormat;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import java.time.LocalDateTime;
-import java.util.UUID;
-import lombok.*;
-
-/* TODO:Dummy JSON code, needs to be changed as part of #103 */
-@Data
-@NoArgsConstructor
-@AllArgsConstructor
-@Getter
-@Setter
-public class EndorsementModelFromJSON {
- private UUID id;
-
- @JsonProperty("user_id")
- private UUID userID;
-
- @JsonProperty("skill_id")
- private UUID skillId;
-
- private String status;
-
- @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS")
- @JsonProperty("created_at")
- private LocalDateTime createdAt;
-
- @JsonProperty("created_by")
- private UUID createdBy;
-
- @JsonProperty("updated_at")
- @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss.SSSSSS")
- private LocalDateTime updatedAt;
-
- @JsonProperty("updated_by")
- private UUID updatedBy;
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementRepository.java b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementRepository.java
deleted file mode 100644
index 6da326dd..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementRepository.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.RDS.skilltree.Endorsement;
-
-import java.util.List;
-import java.util.UUID;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.stereotype.Repository;
-
-@Repository
-public interface EndorsementRepository extends JpaRepository {
- List findByEndorseeId(UUID userId);
-
- List findBySkillId(UUID skillId);
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementService.java b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementService.java
deleted file mode 100644
index a7254a48..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementService.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.RDS.skilltree.Endorsement;
-
-import com.RDS.skilltree.Common.Response.GenericResponse;
-import java.io.IOException;
-import java.util.UUID;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-
-public interface EndorsementService {
- EndorsementDTO getEndorsementById(UUID id);
-
- Page getEndorsements(PageRequest pageRequest);
-
- /* TODO:Dummy JSON code, needs to be changed as part of #103 */
- Page getEndorsementsFromDummyData(
- PageRequest pageRequest, String skillID, String userID) throws IOException;
-
- EndorsementModel createEndorsement(EndorsementDRO endorsementDRO);
-
- GenericResponse updateEndorsementStatus(UUID id, String status);
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementServiceImpl.java b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementServiceImpl.java
deleted file mode 100644
index fce1ed63..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementServiceImpl.java
+++ /dev/null
@@ -1,166 +0,0 @@
-package com.RDS.skilltree.Endorsement;
-
-import com.RDS.skilltree.Common.Response.GenericResponse;
-import com.RDS.skilltree.Exceptions.EntityAlreadyExistsException;
-import com.RDS.skilltree.Exceptions.InvalidParameterException;
-import com.RDS.skilltree.Exceptions.NoEntityException;
-import com.RDS.skilltree.Skill.SkillModel;
-import com.RDS.skilltree.Skill.SkillRepository;
-import com.RDS.skilltree.User.UserModel;
-import com.RDS.skilltree.User.UserRole;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import jakarta.persistence.EntityNotFoundException;
-import java.io.IOException;
-import java.util.List;
-import java.util.Optional;
-import java.util.UUID;
-import java.util.stream.Collectors;
-import lombok.RequiredArgsConstructor;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageImpl;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.security.access.AccessDeniedException;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.stereotype.Service;
-
-@Service
-@RequiredArgsConstructor
-public class EndorsementServiceImpl implements EndorsementService {
- private final EndorsementRepository endorsementRepository;
- private final SkillRepository skillRepository;
-
- private final ObjectMapper objectMapper;
-
- @Value("${endorsements.dummmy-data.path}")
- private String dummyEndorsementDataPath;
-
- private static final Logger logger = LoggerFactory.getLogger(EndorsementServiceImpl.class);
-
- @Override
- public EndorsementDTO getEndorsementById(UUID id) throws IllegalStateException {
- Optional endorsementModel = endorsementRepository.findById(id);
- return EndorsementDTO.toDto(
- endorsementModel.orElseThrow(
- () -> new EntityNotFoundException("No endorsement with the id " + id + " found")));
- }
-
- @Override
- public Page getEndorsements(PageRequest pageRequest) {
- return endorsementRepository.findAll(pageRequest);
- }
-
- /* TODO:Dummy JSON code, needs to be changed as part of #103 */
- @Override
- public Page getEndorsementsFromDummyData(
- PageRequest pageRequest, String skillID, String userID) throws IOException {
-
- try {
- List endorsementModelFromJSONList = readEndorsementsFromJSON();
-
- if (endorsementModelFromJSONList.isEmpty()) {
- return Page.empty(pageRequest);
- }
-
- List filteredEndorsements =
- filterEndorsements(endorsementModelFromJSONList, skillID, userID);
- return createPagedEndorsements(filteredEndorsements, pageRequest);
- } catch (IOException e) {
- logger.error("Error reading endorsements JSON data: {}", e.getMessage());
- throw new IOException("Error reading endorsements JSON data", e);
- }
- }
-
- private List readEndorsementsFromJSON() throws IOException {
- ClassPathResource resource = new ClassPathResource(dummyEndorsementDataPath);
- return objectMapper.readValue(
- resource.getInputStream(), new TypeReference>() {});
- }
-
- private List filterEndorsements(
- List endorsements, String skillID, String userID) {
- return endorsements.stream()
- .filter(endorsement -> isMatchingSkillId(endorsement, skillID))
- .filter(endorsement -> isMatchingUserId(endorsement, userID))
- .collect(Collectors.toList());
- }
-
- private boolean isMatchingSkillId(EndorsementModelFromJSON endorsement, String skillID) {
- return skillID == null
- || skillID.isEmpty()
- || endorsement.getSkillId().equals(UUID.fromString(skillID));
- }
-
- private boolean isMatchingUserId(EndorsementModelFromJSON endorsement, String userID) {
- return userID == null
- || userID.isEmpty()
- || endorsement.getUserID().equals(UUID.fromString(userID));
- }
-
- private Page createPagedEndorsements(
- List endorsements, PageRequest pageRequest) {
- int startIdx = (int) pageRequest.getOffset();
- int totalEndorsements = endorsements.size();
-
- if (startIdx >= totalEndorsements) {
- return Page.empty(pageRequest);
- }
-
- int endIdx = Math.min(startIdx + pageRequest.getPageSize(), endorsements.size());
- List currentPageEndorsements = endorsements.subList(startIdx, endIdx);
- return new PageImpl<>(currentPageEndorsements, pageRequest, endorsements.size());
- }
-
- @Override
- public EndorsementModel createEndorsement(EndorsementDRO endorsementDRO) {
- UUID userId = endorsementDRO.getEndorseeId();
- UUID skillId = endorsementDRO.getSkillId();
-
- Optional skillOptional = skillRepository.findById(skillId);
- if (skillOptional.isPresent()) {
- EndorsementModel endorsementModel =
- EndorsementModel.builder().endorseeId(userId).skill(skillOptional.get()).build();
-
- return endorsementRepository.save(endorsementModel);
- } else {
-
- throw new NoEntityException("Skill with id:" + skillId + " not found");
- }
- }
-
- @Override
- public GenericResponse updateEndorsementStatus(UUID id, String status) {
- UserModel user =
- (UserModel) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
- if (!user.getRole().equals(UserRole.SUPERUSER)) {
- throw new AccessDeniedException("Unauthorized, Access is only available to super users");
- }
-
- EndorsementStatus endorsementStatus = EndorsementStatus.fromString(status);
- if (endorsementStatus.equals(EndorsementStatus.PENDING)) {
- throw new InvalidParameterException("endorsement status", status);
- }
- Optional optionalEndorsementModel = endorsementRepository.findById(id);
- if (optionalEndorsementModel.isPresent()) {
- if (optionalEndorsementModel.get().getStatus() != EndorsementStatus.PENDING) {
- throw new EntityAlreadyExistsException(
- "Endorsement is already updated. Cannot modify status");
- }
- EndorsementModel updatedEndorsementModel =
- EndorsementModel.builder()
- .id(optionalEndorsementModel.get().getId())
- .endorseeId(optionalEndorsementModel.get().getEndorseeId())
- .skill(optionalEndorsementModel.get().getSkill())
- .endorsersList(optionalEndorsementModel.get().getEndorsersList())
- .status(EndorsementStatus.valueOf(status))
- .build();
- endorsementRepository.save(updatedEndorsementModel);
- return new GenericResponse<>(null, "Successfully updated endorsement status");
- }
- throw new NoEntityException("No endorsement with id " + id + " was found");
- }
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementStatus.java b/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementStatus.java
deleted file mode 100644
index 9300b618..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Endorsement/EndorsementStatus.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.RDS.skilltree.Endorsement;
-
-import com.RDS.skilltree.Exceptions.InvalidParameterException;
-import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-public enum EndorsementStatus {
- APPROVED,
- PENDING,
- REJECTED;
-
- private static final Map endorsementStatusMap =
- Stream.of(values())
- .collect(Collectors.toMap(EndorsementStatus::toString, Function.identity()));
-
- public static EndorsementStatus fromString(final String name) {
- EndorsementStatus endorsementStatus = endorsementStatusMap.get(name);
- if (endorsementStatus == null) {
- throw new InvalidParameterException("endorsement status", name);
- }
- return endorsementStatus;
- }
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListDRO.java b/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListDRO.java
deleted file mode 100644
index 99ad11b2..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListDRO.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.RDS.skilltree.EndorsementList;
-
-import java.util.UUID;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@AllArgsConstructor
-@NoArgsConstructor
-@Data
-@Builder
-public class EndorsementListDRO {
- private String description;
- private UUID endorsementId;
- private UUID endorserId;
- private EndorsementType type;
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListDTO.java b/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListDTO.java
deleted file mode 100644
index d840d6c9..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListDTO.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.RDS.skilltree.EndorsementList;
-
-import com.RDS.skilltree.User.UserModel;
-import java.util.UUID;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-
-@Builder
-@Data
-@AllArgsConstructor
-public class EndorsementListDTO {
- private UUID id;
- private String description;
- private UserModel endorser;
- private EndorsementType type;
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListModel.java b/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListModel.java
deleted file mode 100644
index c734925d..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListModel.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.RDS.skilltree.EndorsementList;
-
-import com.RDS.skilltree.Endorsement.EndorsementModel;
-import com.RDS.skilltree.utils.TrackedProperties;
-import com.fasterxml.jackson.annotation.JsonBackReference;
-import jakarta.persistence.*;
-import java.util.UUID;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.NoArgsConstructor;
-
-@EqualsAndHashCode(callSuper = true)
-@Entity
-@NoArgsConstructor
-@Data
-@Table(name = "endorsement_list")
-public class EndorsementListModel extends TrackedProperties {
- @Id
- @GeneratedValue
- @Column(name = "id", columnDefinition = "BINARY(16)")
- private UUID id;
-
- @JoinColumn(name = "endorsement_id", referencedColumnName = "id")
- @ManyToOne(targetEntity = EndorsementModel.class, cascade = CascadeType.ALL)
- @JsonBackReference
- private EndorsementModel endorsement;
-
- @Column(name = "endorser_id")
- private UUID endorserId;
-
- @Column(name = "description")
- private String description;
-
- @Column(name = "is_deleted", nullable = false)
- private boolean deleted;
-
- @Column(name = "type", nullable = false)
- @Enumerated(value = EnumType.STRING)
- private EndorsementType type;
-
- public EndorsementListModel(
- EndorsementModel endorsement, UUID endorserId, String description, EndorsementType type) {
- this.endorsement = endorsement;
- this.endorserId = endorserId;
- this.description = description;
- this.type = type;
- this.deleted = false;
- }
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListRepository.java b/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListRepository.java
deleted file mode 100644
index ce372c5f..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListRepository.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.RDS.skilltree.EndorsementList;
-
-import java.util.UUID;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.stereotype.Repository;
-
-@Repository
-public interface EndorsementListRepository extends JpaRepository {}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListService.java b/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListService.java
deleted file mode 100644
index c26308b2..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementListService.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.RDS.skilltree.EndorsementList;
-
-import com.RDS.skilltree.Endorsement.EndorsementModel;
-import com.RDS.skilltree.Endorsement.EndorsementRepository;
-import com.RDS.skilltree.Exceptions.NoEntityException;
-import java.util.Optional;
-import java.util.UUID;
-import org.springframework.stereotype.Service;
-
-@Service
-public class EndorsementListService {
-
- private final EndorsementListRepository endorsementListRepository;
- private final EndorsementRepository endorsementRepository;
-
- public EndorsementListService(
- EndorsementListRepository endorsementListRepository,
- EndorsementRepository endorsementRepository) {
- this.endorsementListRepository = endorsementListRepository;
- this.endorsementRepository = endorsementRepository;
- }
-
- public EndorsementListModel createEndorsementListEntry(EndorsementListDRO endorsementListDRO) {
- EndorsementListModel endorsementListEntry = new EndorsementListModel();
-
- UUID endorserId = endorsementListDRO.getEndorserId();
- UUID endorsementId = endorsementListDRO.getEndorsementId();
-
- Optional endorsementOptional = endorsementRepository.findById(endorsementId);
- if (endorsementOptional.isPresent()) {
-
- endorsementListEntry.setEndorserId(endorserId);
- endorsementListEntry.setEndorsement(endorsementOptional.get());
- endorsementListEntry.setDescription(endorsementListDRO.getDescription());
- endorsementListEntry.setType(endorsementListDRO.getType());
- endorsementListRepository.save(endorsementListEntry);
- return endorsementListEntry;
-
- } else {
- throw new NoEntityException("Endorsement with id:" + endorsementId + " not found");
- }
- }
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementType.java b/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementType.java
deleted file mode 100644
index 1d028fc8..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/EndorsementList/EndorsementType.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.RDS.skilltree.EndorsementList;
-
-public enum EndorsementType {
- POSITIVE,
- NEGATIVE
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Health/HealthCheckController.java b/skill-tree/src/main/java/com/RDS/skilltree/Health/HealthCheckController.java
deleted file mode 100644
index 854ddece..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Health/HealthCheckController.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.RDS.skilltree.Health;
-
-import com.RDS.skilltree.metrics.MetricService;
-import java.util.Map;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-@RestController
-@RequestMapping("/v1/health")
-@Slf4j
-public class HealthCheckController {
-
- private final MetricService metricService;
-
- @Autowired
- public HealthCheckController(MetricService metricService) {
- this.metricService = metricService;
- }
-
- @GetMapping("")
- public Map checkHealth() {
- double uptime = metricService.getUptime();
- return Map.of("uptimeInSeconds", uptime);
- }
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillDRO.java b/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillDRO.java
deleted file mode 100644
index 543c4ace..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillDRO.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.RDS.skilltree.Skill;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import jakarta.validation.constraints.NotNull;
-import java.util.UUID;
-import lombok.Builder;
-import lombok.Getter;
-
-@Getter
-@Builder
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class SkillDRO {
- @NotNull(message = "Name cannot be null")
- private String name;
-
- @NotNull(message = "SkillType cannot be null")
- private SkillType type;
-
- @NotNull(message = "Created by user Id cannot be null")
- private UUID createdBy;
-
- public static SkillModel toModel(SkillDRO skillDRO) {
- return SkillModel.builder()
- .name(skillDRO.getName())
- .type(skillDRO.getType())
- .deleted(false)
- .build();
- }
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillDTO.java b/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillDTO.java
deleted file mode 100644
index a6304e2b..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillDTO.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.RDS.skilltree.Skill;
-
-import com.RDS.skilltree.User.UserDTO;
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.UUID;
-import java.util.stream.Collectors;
-import lombok.Builder;
-import lombok.Getter;
-
-@Getter
-@Builder
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class SkillDTO {
- private UUID id;
- private SkillType type;
- private String name;
- private Set users;
-
- public static SkillDTO toDto(SkillModel skillModel) {
- return SkillDTO.builder()
- .id(skillModel.getId())
- .name(skillModel.getName())
- .type(skillModel.getType())
- .build();
- }
-
- public static SkillDTO getSkillsWithUsers(SkillModel skillModel) {
- Set users = new HashSet<>();
- if (skillModel.getUsers() != null) {
- users = skillModel.getUsers().stream().map(UserDTO::toDTO).collect(Collectors.toSet());
- }
- return SkillDTO.builder()
- .id(skillModel.getId())
- .name(skillModel.getName())
- .type(skillModel.getType())
- .users(users)
- .build();
- }
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillModel.java b/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillModel.java
deleted file mode 100644
index 0074c602..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillModel.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.RDS.skilltree.Skill;
-
-import com.RDS.skilltree.User.UserModel;
-import com.RDS.skilltree.utils.TrackedProperties;
-import com.fasterxml.jackson.annotation.JsonBackReference;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import jakarta.persistence.*;
-import java.util.Set;
-import java.util.UUID;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Getter;
-import lombok.NoArgsConstructor;
-
-@AllArgsConstructor
-@NoArgsConstructor
-@Entity
-@Builder
-@Getter
-@Table(name = "Skill")
-public class SkillModel extends TrackedProperties {
- @Id
- @GeneratedValue
- @Column(name = "id", columnDefinition = "BINARY(16)")
- private UUID id;
-
- @Column(name = "name", unique = true, nullable = false)
- private String name;
-
- @Column(name = "skill_type", nullable = false)
- @Enumerated(value = EnumType.STRING)
- private SkillType type = SkillType.ATOMIC;
-
- @Column(name = "is_deleted", nullable = false)
- private boolean deleted;
-
- @JsonBackReference
- @JsonIgnore
- @ManyToMany(mappedBy = "skills", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
- private Set users;
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillRepository.java b/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillRepository.java
deleted file mode 100644
index a523a3b0..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillRepository.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.RDS.skilltree.Skill;
-
-import java.util.Optional;
-import java.util.UUID;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.stereotype.Repository;
-
-@Repository
-public interface SkillRepository extends JpaRepository {
- Optional findByName(String name);
-
- Page findAll(Pageable pageable);
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillType.java b/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillType.java
deleted file mode 100644
index 32500383..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillType.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.RDS.skilltree.Skill;
-
-public enum SkillType {
- ATOMIC,
- DERIVED
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillsController.java b/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillsController.java
deleted file mode 100644
index 00e9f669..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillsController.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.RDS.skilltree.Skill;
-
-import com.RDS.skilltree.utils.MessageResponse;
-import jakarta.validation.Valid;
-import jakarta.validation.constraints.Min;
-import java.util.UUID;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.dao.DataIntegrityViolationException;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.data.domain.Pageable;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.util.ObjectUtils;
-import org.springframework.web.bind.annotation.*;
-
-@RestController
-@Slf4j
-@RequestMapping("/v1/skills")
-public class SkillsController {
- private final SkillsService skillsService;
-
- public SkillsController(SkillsService skillsService) {
- this.skillsService = skillsService;
- }
-
- @PostMapping("/")
- public ResponseEntity> createSkill(@RequestBody(required = true) @Valid SkillDRO skillDRO) {
- try {
- return ResponseEntity.status(HttpStatus.CREATED).body(skillsService.createSkill(skillDRO));
- } catch (DataIntegrityViolationException ex) {
- return ResponseEntity.status(HttpStatus.CONFLICT)
- .body(new MessageResponse("Cannot create entry for Skill as Skill name is duplicate"));
- } catch (Exception ex) {
- log.error(
- "There is some error in storing the skills, error message: {}", ex.getMessage(), ex);
- throw ex;
- }
- }
-
- @GetMapping("/")
- public Page getAllSkills(
- @RequestParam(value = "offset", defaultValue = "0", required = false) @Min(0) int offset,
- @RequestParam(value = "limit", defaultValue = "10", required = false) @Min(1) int limit) {
- Pageable pageable = PageRequest.of(offset, limit);
- return skillsService.getAllSkills(pageable);
- }
-
- @GetMapping("/name/{name}")
- public ResponseEntity> getSkillByName(
- @PathVariable(value = "name", required = true) String name) {
- SkillDTO skillDTO = skillsService.getSkillByName(name);
- if (ObjectUtils.isEmpty(skillDTO)) {
- return ResponseEntity.status(HttpStatus.NOT_FOUND)
- .body(new MessageResponse("Skill not found with the given name"));
- }
- return ResponseEntity.ok(skillDTO);
- }
-
- @GetMapping("/{id}")
- public ResponseEntity> getSkillById(@PathVariable(value = "id", required = true) UUID id) {
- SkillDTO skillDTO = skillsService.getSkillById(id);
- if (ObjectUtils.isEmpty(skillDTO)) {
- return ResponseEntity.status(HttpStatus.NOT_FOUND)
- .body(new MessageResponse("Skill not found with given Id"));
- }
- return ResponseEntity.ok(skillDTO);
- }
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillsService.java b/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillsService.java
deleted file mode 100644
index b8a4e015..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillsService.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.RDS.skilltree.Skill;
-
-import java.util.UUID;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-
-public interface SkillsService {
- SkillDTO getSkillById(UUID id);
-
- SkillDTO getSkillByName(String skillName);
-
- Page getAllSkills(Pageable pageable);
-
- SkillDTO createSkill(SkillDRO skillDRO);
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillsServiceImpl.java b/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillsServiceImpl.java
deleted file mode 100644
index 61943723..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/Skill/SkillsServiceImpl.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.RDS.skilltree.Skill;
-
-import com.RDS.skilltree.User.UserRepository;
-import java.time.Instant;
-import java.util.Optional;
-import java.util.UUID;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.dao.DataIntegrityViolationException;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.stereotype.Service;
-
-@Service
-@Slf4j
-@RequiredArgsConstructor
-public class SkillsServiceImpl implements SkillsService {
- private final SkillRepository skillRepository;
- private final UserRepository userRepository;
-
- @Override
- public SkillDTO getSkillById(UUID id) {
- Optional skillModel = skillRepository.findById(id);
- return skillModel.map(SkillDTO::getSkillsWithUsers).orElse(null);
- }
-
- @Override
- public SkillDTO getSkillByName(String skillName) {
- Optional skillModel = skillRepository.findByName(skillName);
- return skillModel.map(SkillDTO::getSkillsWithUsers).orElse(null);
- }
-
- @Override
- public Page getAllSkills(Pageable pageable) {
- Page skillModels = skillRepository.findAll(pageable);
- return skillModels.map(SkillDTO::getSkillsWithUsers);
- }
-
- @Override
- public SkillDTO createSkill(SkillDRO skillDRO) {
- SkillModel newSkill = SkillDRO.toModel(skillDRO);
- newSkill.setCreatedAt(Instant.now());
- newSkill.setUpdatedAt(Instant.now());
-
- try {
- skillRepository.save(newSkill);
- } catch (DataIntegrityViolationException ex) {
- log.error(
- "Error saving the skills object with name : {}, with exception :{}",
- skillDRO.getName(),
- ex.getMessage(),
- ex);
- throw ex;
- }
- return SkillDTO.toDto(newSkill);
- }
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/User/UserDRO.java b/skill-tree/src/main/java/com/RDS/skilltree/User/UserDRO.java
deleted file mode 100644
index c0141963..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/User/UserDRO.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.RDS.skilltree.User;
-
-import java.net.URL;
-import java.time.Instant;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-@AllArgsConstructor
-@NoArgsConstructor
-@Data
-@Builder
-public class UserDRO {
- private String rdsUserId;
-
- private String firstName;
-
- private String lastName;
-
- private URL imageUrl;
-
- private UserRole role;
-
- public static UserModel toModel(UserDRO user) {
- return UserModel.builder()
- .rdsUserId(user.getRdsUserId())
- .firstName(user.getFirstName())
- .lastName(user.getLastName())
- .role(user.getRole())
- .imageUrl(user.getImageUrl())
- .build();
- }
-
- public static UserDRO fromModel(UserModel user) {
- return UserDRO.builder()
- .rdsUserId(user.getRdsUserId())
- .role(user.getRole())
- .firstName(user.getFirstName())
- .lastName(user.getLastName())
- .imageUrl(user.getImageUrl())
- .build();
- }
-
- public static UserModel compareAndUpdateModel(UserModel user, UserDRO userDRO) {
- if (userDRO.getRdsUserId() != null) {
- user.setRdsUserId(user.getRdsUserId());
- }
- if (userDRO.getFirstName() != null) {
- user.setFirstName(user.getFirstName());
- }
- if (userDRO.getLastName() != null) {
- user.setLastName(user.getLastName());
- }
- if (userDRO.getImageUrl() != null) {
- user.setImageUrl(user.getImageUrl());
- }
- if (userDRO.getRole() != null) {
- user.setRole(user.getRole());
- }
- user.setUpdatedAt(Instant.now());
- return user;
- }
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/User/UserDTO.java b/skill-tree/src/main/java/com/RDS/skilltree/User/UserDTO.java
deleted file mode 100644
index fedccf7b..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/User/UserDTO.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package com.RDS.skilltree.User;
-
-import com.RDS.skilltree.Skill.SkillDTO;
-import java.net.URL;
-import java.util.Set;
-import java.util.UUID;
-import java.util.stream.Collectors;
-import lombok.Builder;
-import lombok.Getter;
-
-@Getter
-@Builder
-public class UserDTO {
-
- private UUID id;
-
- private String rdsUserId;
-
- private String firstName;
-
- private String lastName;
-
- private URL imageUrl;
-
- private UserRole role;
-
- private Set skills;
-
- public static UserDTO toDTO(UserModel user) {
-
- return UserDTO.builder()
- .id(user.getId())
- .rdsUserId(user.getRdsUserId())
- .firstName(user.getFirstName())
- .lastName(user.getLastName())
- .imageUrl(user.getImageUrl())
- .role(user.getRole())
- .build();
- }
-
- public static UserDTO getUsersWithSkills(UserModel user) {
- Set skills =
- user.getSkills().stream().map(SkillDTO::toDto).collect(Collectors.toSet());
-
- return UserDTO.builder()
- .id(user.getId())
- .rdsUserId(user.getRdsUserId())
- .firstName(user.getFirstName())
- .lastName(user.getLastName())
- .imageUrl(user.getImageUrl())
- .skills(skills)
- .role(user.getRole())
- .build();
- }
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/User/UserModel.java b/skill-tree/src/main/java/com/RDS/skilltree/User/UserModel.java
deleted file mode 100644
index 42776846..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/User/UserModel.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.RDS.skilltree.User;
-
-import com.RDS.skilltree.Skill.SkillModel;
-import com.RDS.skilltree.utils.TrackedProperties;
-import com.fasterxml.jackson.annotation.JsonManagedReference;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import jakarta.persistence.*;
-import java.net.URL;
-import java.util.Set;
-import java.util.UUID;
-import lombok.*;
-
-@Entity
-@Getter
-@Setter
-@Builder
-@JsonSerialize
-@NoArgsConstructor
-@AllArgsConstructor
-@Table(name = "Users")
-public class UserModel extends TrackedProperties {
- @Id
- @GeneratedValue
- @Column(name = "id", columnDefinition = "BINARY(16)")
- private UUID id;
-
- @Column(name = "rds_user_id", unique = true)
- private String rdsUserId;
-
- @Column(name = "first_name", nullable = false)
- private String firstName;
-
- @Column(name = "last_name")
- private String lastName;
-
- @Column(name = "image_url", nullable = false)
- private URL imageUrl;
-
- @Column(name = "user_role", nullable = false)
- @Enumerated(value = EnumType.STRING)
- private UserRole role = UserRole.USER;
-
- @JsonManagedReference
- @ManyToMany(targetEntity = SkillModel.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
- @JoinTable(
- name = "user_skill",
- joinColumns = @JoinColumn(name = "user_id"),
- inverseJoinColumns = @JoinColumn(name = "skill_id"))
- private Set skills;
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/User/UserRepository.java b/skill-tree/src/main/java/com/RDS/skilltree/User/UserRepository.java
deleted file mode 100644
index a557c19e..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/User/UserRepository.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.RDS.skilltree.User;
-
-import java.util.UUID;
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.stereotype.Repository;
-
-@Repository
-public interface UserRepository extends JpaRepository {}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/User/UserService.java b/skill-tree/src/main/java/com/RDS/skilltree/User/UserService.java
deleted file mode 100644
index f853bf04..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/User/UserService.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.RDS.skilltree.User;
-
-import java.util.List;
-import java.util.UUID;
-
-public interface UserService {
- UserDTO createUser(UserDRO user);
-
- void updateUser(UUID id, UserDRO user);
-
- UserDTO getUserById(UUID id);
-
- List getAllUsers();
-
- void addSkill(UUID skill, UUID userId);
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/User/UserServiceImpl.java b/skill-tree/src/main/java/com/RDS/skilltree/User/UserServiceImpl.java
deleted file mode 100644
index c85f9d94..00000000
--- a/skill-tree/src/main/java/com/RDS/skilltree/User/UserServiceImpl.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package com.RDS.skilltree.User;
-
-import com.RDS.skilltree.Exceptions.NoEntityException;
-import com.RDS.skilltree.Skill.SkillModel;
-import com.RDS.skilltree.Skill.SkillRepository;
-import jakarta.transaction.Transactional;
-import java.util.List;
-import java.util.Optional;
-import java.util.UUID;
-import org.springframework.stereotype.Service;
-
-@Service
-public class UserServiceImpl implements UserService {
- private final UserRepository userRepository;
- private final SkillRepository skillRepository;
-
- public UserServiceImpl(UserRepository userRepository, SkillRepository skillRepository) {
- this.userRepository = userRepository;
- this.skillRepository = skillRepository;
- }
-
- @Override
- public UserDTO createUser(UserDRO user) {
- UserModel userModel = UserDRO.toModel(user);
- userRepository.save(userModel);
- return UserDTO.toDTO(userModel);
- }
-
- @Override
- public void updateUser(UUID id, UserDRO user) {}
-
- @Override
- public UserDTO getUserById(UUID id) {
- Optional userModel = userRepository.findById(id);
- return userModel.map(UserDTO::getUsersWithSkills).orElse(null);
- }
-
- @Override
- public List getAllUsers() {
- return null;
- }
-
- /**
- * updates the user and skill both
- * @param skillId
- * @param userId
- */
- @Override
- @Transactional
- public void addSkill(UUID skillId, UUID userId) {
- Optional userOptional = userRepository.findById(userId);
- Optional skillOptional = skillRepository.findById(skillId);
-
- if (userOptional.isPresent() && skillOptional.isPresent()) {
- UserModel userModel = userOptional.get();
- SkillModel skillModel = skillOptional.get();
-
- userModel.getSkills().add(skillModel);
- skillModel.getUsers().add(userModel);
-
- userRepository.save(userModel);
- skillRepository.save(skillModel);
- } else {
- if (skillOptional.isEmpty()) {
- throw new NoEntityException("Skill Id is not passed in the input");
- }
- throw new NoEntityException("User with Id doesn't exists");
- }
- }
-}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/annotations/AuthorizedRoles.java b/skill-tree/src/main/java/com/RDS/skilltree/annotations/AuthorizedRoles.java
new file mode 100644
index 00000000..c788b99c
--- /dev/null
+++ b/skill-tree/src/main/java/com/RDS/skilltree/annotations/AuthorizedRoles.java
@@ -0,0 +1,13 @@
+package com.RDS.skilltree.annotations;
+
+import com.RDS.skilltree.enums.UserRoleEnum;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface AuthorizedRoles {
+ UserRoleEnum[] value() default {};
+}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/apis/EndorsementsApi.java b/skill-tree/src/main/java/com/RDS/skilltree/apis/EndorsementsApi.java
new file mode 100644
index 00000000..cd3d5212
--- /dev/null
+++ b/skill-tree/src/main/java/com/RDS/skilltree/apis/EndorsementsApi.java
@@ -0,0 +1,28 @@
+package com.RDS.skilltree.apis;
+
+import com.RDS.skilltree.annotations.AuthorizedRoles;
+import com.RDS.skilltree.enums.UserRoleEnum;
+import com.RDS.skilltree.services.EndorsementService;
+import com.RDS.skilltree.viewmodels.EndorsementViewModel;
+import com.RDS.skilltree.viewmodels.UpdateEndorsementViewModel;
+import jakarta.validation.Valid;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+@Slf4j
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("v1/endorsements")
+@AuthorizedRoles({UserRoleEnum.USER, UserRoleEnum.SUPERUSER})
+public class EndorsementsApi {
+ private final EndorsementService endorsementService;
+
+ @PatchMapping("/{id}")
+ public ResponseEntity update(
+ @PathVariable Integer id, @Valid @RequestBody UpdateEndorsementViewModel body) {
+ return new ResponseEntity<>(endorsementService.update(id, body), HttpStatus.OK);
+ }
+}
diff --git a/skill-tree/src/main/java/com/RDS/skilltree/apis/HealthApi.java b/skill-tree/src/main/java/com/RDS/skilltree/apis/HealthApi.java
new file mode 100644
index 00000000..88dd1d20
--- /dev/null
+++ b/skill-tree/src/main/java/com/RDS/skilltree/apis/HealthApi.java
@@ -0,0 +1,25 @@
+package com.RDS.skilltree.apis;
+
+import com.RDS.skilltree.services.MetricService;
+import java.util.Map;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@Slf4j
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("v1/health")
+public class HealthApi {
+ private final MetricService metricService;
+
+ @GetMapping
+ public ResponseEntity