This API provides endpoints to manage phone reviews, comments, and likes. It includes user authentication and role-based access control.
- Gin HTTP Framework
- GORM Library
- Swaggo Documentation Framework
- MySQL
- JWT Authentication
- godotenv
To run this application locally:
- Clone the repository:
git clone https://github.com/diazlp/golang-phone-review-api.git
- Install dependencies
go mod tidy
- Create a
.env
file with neccessary environment variablesAPI_SECRET=<your_secret> TOKEN_HOUR_LIFESPAN=<token_lifespan>
- Change
database configuration
on/configs/database.go
username := <your_db_username> password := <your_db_password> host := <your_db_host> database := <project_db_name>
- Run the application:
go run main.go
Note: Kindly run swag init
after you make codebase changes to update swagger API documentation
POST /register
: Register a new user.POST /login
: Log in with existing credentials.POST /change-password
: Change user password.
GET /phones
: Get all phones.GET /phones/:phone_id
: Get details of a specific phone.GET /phones/:phone_id/reviews
: Get reviews for a specific phone.POST /phones/:phone_id/reviews
: Create a review for a phone.POST /phones
: Create a new phone.
GET /reviews
: Get all reviews.GET /reviews/:review_id/comments
: Get comments for a review.GET /reviews/:review_id/likes
: Get likes for a review.PUT /reviews/:review_id
: Update a review.DELETE /reviews/:review_id
: Delete a review.POST /reviews/:review_id/comments
: Create a comment for a review.POST /reviews/:review_id/likes
: Like a review.
GET /comments
: Get all comments.GET /comments/:comment_id/likes
: Get likes for a comment.PUT /comments/:comment_id
: Update a comment.DELETE /comments/:comment_id
: Delete a comment.POST /comments/:comment_id/likes
: Like a comment.
GET /likes
: Get all likes.DELETE /likes/:like_id
: Delete a like.
- User registration is open to everyone.
- User authentication is required for some endpoints.
- All user can use
GET
endpoints. - Role-based access control is implemented:
- "Guest" role: Can like reviews and comments.
- "Writer" role: Can create and edit reviews and comments.
- "Admin" role: Can create phone, create review and delete review.