Skip to content

Commit

Permalink
Merge pull request #10 from jason810496/Feat/restful
Browse files Browse the repository at this point in the history
fix : rename routes by Restful API guideline
  • Loading branch information
peterxcli authored Jan 17, 2024
2 parents 722f57c + 9d51e38 commit 44636df
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 44 deletions.
20 changes: 10 additions & 10 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const docTemplate = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/event": {
"/events": {
"get": {
"description": "Retrieves a list of all events with pagination",
"consumes": [
Expand Down Expand Up @@ -107,7 +107,7 @@ const docTemplate = `{
}
}
},
"/event/user": {
"/events/user": {
"get": {
"security": [
{
Expand Down Expand Up @@ -141,7 +141,7 @@ const docTemplate = `{
}
}
},
"/event/{event_id}": {
"/events/{event_id}": {
"delete": {
"security": [
{
Expand Down Expand Up @@ -191,7 +191,7 @@ const docTemplate = `{
}
}
},
"/event/{id}": {
"/events/{id}": {
"get": {
"description": "Retrieves an event using its unique ID",
"consumes": [
Expand Down Expand Up @@ -367,7 +367,7 @@ const docTemplate = `{
}
}
},
"/user/login/{user_id}": {
"/users/login/{user_id}": {
"get": {
"description": "Simulates a login process for a user by generating fake access and refresh tokens",
"consumes": [
Expand Down Expand Up @@ -405,7 +405,7 @@ const docTemplate = `{
}
}
},
"/user/logout": {
"/users/logout": {
"post": {
"security": [
{
Expand Down Expand Up @@ -454,7 +454,7 @@ const docTemplate = `{
}
}
},
"/user/profile": {
"/users/profile": {
"get": {
"security": [
{
Expand Down Expand Up @@ -497,7 +497,7 @@ const docTemplate = `{
}
}
},
"/user/refresh_token": {
"/users/refresh_token": {
"post": {
"description": "Refreshes the access and refresh tokens for a user",
"consumes": [
Expand Down Expand Up @@ -549,7 +549,7 @@ const docTemplate = `{
}
}
},
"/user/register": {
"/users/register": {
"post": {
"description": "Register a fake user for testing purposes",
"consumes": [
Expand Down Expand Up @@ -595,7 +595,7 @@ const docTemplate = `{
}
}
},
"/user/{user_id}": {
"/users/{user_id}": {
"get": {
"description": "Retrieves a user's information by their ID",
"consumes": [
Expand Down
20 changes: 10 additions & 10 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"contact": {}
},
"paths": {
"/event": {
"/events": {
"get": {
"description": "Retrieves a list of all events with pagination",
"consumes": [
Expand Down Expand Up @@ -96,7 +96,7 @@
}
}
},
"/event/user": {
"/events/user": {
"get": {
"security": [
{
Expand Down Expand Up @@ -130,7 +130,7 @@
}
}
},
"/event/{event_id}": {
"/events/{event_id}": {
"delete": {
"security": [
{
Expand Down Expand Up @@ -180,7 +180,7 @@
}
}
},
"/event/{id}": {
"/events/{id}": {
"get": {
"description": "Retrieves an event using its unique ID",
"consumes": [
Expand Down Expand Up @@ -356,7 +356,7 @@
}
}
},
"/user/login/{user_id}": {
"/users/login/{user_id}": {
"get": {
"description": "Simulates a login process for a user by generating fake access and refresh tokens",
"consumes": [
Expand Down Expand Up @@ -394,7 +394,7 @@
}
}
},
"/user/logout": {
"/users/logout": {
"post": {
"security": [
{
Expand Down Expand Up @@ -443,7 +443,7 @@
}
}
},
"/user/profile": {
"/users/profile": {
"get": {
"security": [
{
Expand Down Expand Up @@ -486,7 +486,7 @@
}
}
},
"/user/refresh_token": {
"/users/refresh_token": {
"post": {
"description": "Refreshes the access and refresh tokens for a user",
"consumes": [
Expand Down Expand Up @@ -538,7 +538,7 @@
}
}
},
"/user/register": {
"/users/register": {
"post": {
"description": "Register a fake user for testing purposes",
"consumes": [
Expand Down Expand Up @@ -584,7 +584,7 @@
}
}
},
"/user/{user_id}": {
"/users/{user_id}": {
"get": {
"description": "Retrieves a user's information by their ID",
"consumes": [
Expand Down
20 changes: 10 additions & 10 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ definitions:
info:
contact: {}
paths:
/event:
/events:
get:
consumes:
- application/json
Expand Down Expand Up @@ -193,7 +193,7 @@ paths:
summary: Subscribe to an event
tags:
- Event
/event/{event_id}:
/events/{event_id}:
delete:
consumes:
- application/json
Expand Down Expand Up @@ -225,7 +225,7 @@ paths:
summary: Delete event
tags:
- Event
/event/{id}:
/events/{id}:
get:
consumes:
- application/json
Expand Down Expand Up @@ -286,7 +286,7 @@ paths:
summary: Update an event
tags:
- Event
/event/user:
/events/user:
get:
consumes:
- application/json
Expand Down Expand Up @@ -362,7 +362,7 @@ paths:
summary: Handle LINE OAuth callback
tags:
- OAuth
/user/{user_id}:
/users/{user_id}:
get:
consumes:
- application/json
Expand All @@ -387,7 +387,7 @@ paths:
summary: Get user by ID
tags:
- User
/user/login/{user_id}:
/users/login/{user_id}:
get:
consumes:
- application/json
Expand All @@ -413,7 +413,7 @@ paths:
summary: Fake Login
tags:
- User
/user/logout:
/users/logout:
post:
consumes:
- application/json
Expand Down Expand Up @@ -444,7 +444,7 @@ paths:
summary: User logout
tags:
- User
/user/profile:
/users/profile:
get:
consumes:
- application/json
Expand All @@ -471,7 +471,7 @@ paths:
summary: Profile
tags:
- User
/user/refresh_token:
/users/refresh_token:
post:
consumes:
- application/json
Expand Down Expand Up @@ -505,7 +505,7 @@ paths:
summary: Refresh User Token
tags:
- Authentication
/user/register:
/users/register:
post:
consumes:
- application/json
Expand Down
12 changes: 6 additions & 6 deletions pkg/controller/event_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewEventController(eventService model.EventService) *EventController {
// @Param limit query int false "Number of items per page for pagination"
// @Success 200 {object} model.EventListResponse "List of events"
// @Failure 500 {object} model.Response "Internal Server Error"
// @Router /event [get]
// @Router /events [get]
func (ctrl *EventController) GetAllEvent(c *gin.Context) {
page, limit := RetrievePagination(c)
events, err := ctrl.eventService.FindAll(c, page, limit)
Expand All @@ -48,7 +48,7 @@ func (ctrl *EventController) GetAllEvent(c *gin.Context) {
// @Param id path string true "Event ID"
// @Success 200 {object} model.EventResponse "Event successfully retrieved"
// @Failure 500 {object} model.Response "Internal Server Error"
// @Router /event/{id} [get]
// @Router /events/{id} [get]
func (ctrl *EventController) GetEventByID(c *gin.Context) {
id := c.Param("id")
userID := c.GetString("user_id")
Expand Down Expand Up @@ -80,7 +80,7 @@ func (ctrl *EventController) GetEventByID(c *gin.Context) {
// @Security ApiKeyAuth // include this line if the endpoint is protected by an API key or other security mechanism
// @Success 200 {object} model.EventListResponse "List of events associated with the user"
// @Failure 500 {object} model.Response "Internal Server Error"
// @Router /event/user [get] // adjust the path and HTTP method according to your routing
// @Router /events/user [get] // adjust the path and HTTP method according to your routing
func (ctrl *EventController) GetUserEvent(c *gin.Context) {
userID := c.GetString("user_id")
events, err := ctrl.eventService.FindByUserID(c, userID)
Expand All @@ -106,7 +106,7 @@ func (ctrl *EventController) GetUserEvent(c *gin.Context) {
// @Success 200 {object} model.EventResponse "Successfully subscribed to the event"
// @Failure 400 {object} model.Response "Bad Request - Invalid input"
// @Failure 500 {object} model.Response "Internal Server Error"
// @Router /event [post]
// @Router /events [post]
func (ctrl *EventController) SubscribeEvent(c *gin.Context) {
userID := c.GetString("user_id")
var request model.CreateEventRequest
Expand Down Expand Up @@ -148,7 +148,7 @@ func (ctrl *EventController) SubscribeEvent(c *gin.Context) {
// @Success 200 {object} model.EventResponse "Event successfully updated"
// @Failure 400 {object} model.Response "Bad Request - Invalid input"
// @Failure 500 {object} model.Response "Internal Server Error"
// @Router /event/{id} [put]
// @Router /events/{id} [put]
func (ctrl *EventController) UpdateEvent(c *gin.Context) {
id := c.Param("id")
userID := c.GetString("user_id")
Expand Down Expand Up @@ -197,7 +197,7 @@ func (ctrl *EventController) UpdateEvent(c *gin.Context) {
// @Param event_id path string true "Event ID"
// @Success 200 {object} model.Response "Event successfully deleted"
// @Failure 500 {object} model.Response "Internal Server Error"
// @Router /event/{event_id} [delete]
// @Router /events/{event_id} [delete]
func (ctrl *EventController) DeleteEvent(c *gin.Context) {
userID := c.GetString("user_id")
eventID := c.Param("event_id")
Expand Down
12 changes: 6 additions & 6 deletions pkg/controller/user_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewUserController(userSvc model.UserService, env *bootstrap.Env) *UserContr
// @Param user_id path string true "User ID"
// @Success 200 {object} model.UserResponse "Profile successfully retrieved"
// @Failure 500 {object} model.Response "Internal Server Error"
// @Router /user/profile [get]
// @Router /users/profile [get]
func (ctrl *UserController) Profile(c *gin.Context) {
userID, _ := c.Get("user_id")
profile, err := ctrl.userSvc.GetUserByID(c, userID.(string))
Expand All @@ -57,7 +57,7 @@ func (ctrl *UserController) Profile(c *gin.Context) {
// @Param user_id path string true "User ID"
// @Success 200 {object} model.UserResponse "User successfully retrieved"
// @Failure 500 {object} model.Response "Internal Server Error"
// @Router /user/{user_id} [get]
// @Router /users/{user_id} [get]
func (ctrl *UserController) GetUserByID(c *gin.Context) {
userID := c.Param("user_id")
user, err := ctrl.userSvc.GetUserByID(c, userID)
Expand All @@ -84,7 +84,7 @@ func (ctrl *UserController) GetUserByID(c *gin.Context) {
// @Failure 400 {object} model.Response "Bad Request - Invalid request format"
// @Failure 401 {object} model.Response "Unauthorized - Invalid or expired refresh token"
// @Failure 500 {object} model.Response "Internal Server Error - Error generating tokens"
// @Router /user/refresh_token [post]
// @Router /users/refresh_token [post]
func (ctrl *UserController) RefreshToken(c *gin.Context) {
var request model.RefreshTokenRequest

Expand Down Expand Up @@ -164,7 +164,7 @@ func (ctrl *UserController) GetUsers(c *gin.Context) {
// @Success 200 {object} model.Response "Logout successful"
// @Failure 401 {object} model.Response "Unauthorized: Invalid token format"
// @Failure 500 {object} model.Response "Internal Server Error"
// @Router /user/logout [post]
// @Router /users/logout [post]
func (ctrl *UserController) Logout(c *gin.Context) {
// TODO: need to discuss where to read the token from (header or body or cookie)
authHeader := c.GetHeader("Authorization")
Expand Down Expand Up @@ -197,7 +197,7 @@ func (ctrl *UserController) Logout(c *gin.Context) {
// @Param user_id path string true "User ID"
// @Success 200 {object} model.TokenResponse "Login successful, tokens generated"
// @Failure 500 {object} model.Response "Internal Server Error"
// @Router /user/login/{user_id} [get]
// @Router /users/login/{user_id} [get]
func (ctrl *UserController) FakeLogin(c *gin.Context) {
userID := c.Param("user_id")

Expand Down Expand Up @@ -241,7 +241,7 @@ func (ctrl *UserController) FakeLogin(c *gin.Context) {
// @Success 200 {object} model.Response "Fake register successful"
// @Failure 400 {object} model.Response "Bad Request - Invalid input data"
// @Failure 500 {object} model.Response "Internal Server Error"
// @Router /user/register [post]
// @Router /users/register [post]
func (ctrl *UserController) FakeRegister(c *gin.Context) {
var request model.CreateFakeUserRequest

Expand Down
2 changes: 1 addition & 1 deletion pkg/router/event_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func RegisterEventRouter(app *bootstrap.Application, controller *controller.EventController) {
r := app.Engine.Group("/event")
r := app.Engine.Group("/events")
authMiddleware := middleware.AuthMiddleware(app.Env.JWT.AccessTokenSecret, app.Cache)

r.GET("", controller.GetAllEvent)
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/user_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func RegisterUserRoutes(app *bootstrap.Application, controller *controller.UserController) {
r := app.Engine.Group("/user")
r := app.Engine.Group("/users")
authMiddleware := middleware.AuthMiddleware(app.Env.JWT.AccessTokenSecret, app.Cache)

r.GET("/profile", authMiddleware, controller.Profile)
Expand Down

0 comments on commit 44636df

Please sign in to comment.