github.com/ars0915/glossika-exercise@v0.0.0-20240904180321-a5617a00d892/README.md (about) 1 # glossika-exercise 2 3 This is a backend service project built with Go, MySQL, and Redis. It provides functionality for user registration, login, email verification, and retrieving recommended products. 4 5 ## Running the Project 6 7 1. **Build and Start the Services** 8 9 Use `docker-compose` to build and start all the services: 10 11 ```bash 12 docker-compose up -d 13 ``` 14 15 This will start the following services: 16 - `app`: The main application service 17 - `mysql`: MySQL database service 18 - `redis`: Redis cache service 19 20 The `app` service will be accessible at `http://localhost:8080`, the `mysql` service will be available on port `3306`, and the `redis` service will be available on port `6379`. 21 22 ## API Documentation 23 24 ### 1. User Registration 25 26 **Request:** 27 28 ```bash 29 curl --location 'http://localhost:8080/register' \ 30 --header 'Content-Type: application/json' \ 31 --data-raw '{ 32 "email": "aaa@gmail.com", 33 "password": "!Qaz2wsx" 34 }' 35 ``` 36 37 **Description:** 38 - `email` is the user's email address. 39 - `password` is the user's password. The password requirements are: 6 to 16 characters, containing at least one uppercase letter, one lowercase letter, and one special character. 40 41 ### 2. Verify Email 42 43 **Request:** 44 45 ```bash 46 curl --location 'http://localhost:8080/verify' \ 47 --header 'Content-Type: application/json' \ 48 --data-raw '{ 49 "email": "aaa@gmail.com", 50 "verificationCode": "d27a81" 51 }' 52 ``` 53 54 **Description:** 55 - `email` is the user's email address. 56 - `verificationCode` is the verification code obtained from the database. Although the API is supposed to get this code from the email, the actual email sending functionality is not implemented. Therefore, you need to retrieve the `verification_code` from the `users` table in the database for testing. 57 58 ### 3. User Login 59 60 **Request:** 61 62 ```bash 63 curl --location 'http://localhost:8080/login' \ 64 --header 'Content-Type: application/json' \ 65 --data-raw '{ 66 "email": "aaa@gmail.com", 67 "password": "!Qaz2wsx" 68 }' 69 ``` 70 71 **Description:** 72 - `email` is the user's email address. 73 - `password` is the user's password. You must verify the email (`verify`) before logging in, otherwise, an error will be returned. 74 75 76 77 78 ### 4. Get Recommendations 79 80 **Request:** 81 82 ```bash 83 curl --location 'http://localhost:8080/recommendation' \ 84 --header 'Authorization: ••••••' 85 ``` 86 87 **Description:** 88 - The `Authorization` header needs to contain a valid JWT token. 89 - Ensure the user is verified (`verify`) and logged in (`login`) before making this request, otherwise, an error will be returned. 90 91 92 93 ## Notes 94 95 1. **You need to verify the email (`verify`) before logging in.** Otherwise, the login request will return an error. 96 2. **The verification code (`verificationCode`) should be obtained from the `users` table in the database.** The project does not implement actual email sending, so for testing, you need to retrieve the `verification_code` from the database. 97 98 ## Development and Testing 99 100 - Ensure Docker and Docker Compose are installed and running. 101 - Use `docker-compose up -d` to start the services. 102 - Test the API using the provided curl commands.