Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions api/ctxutil/user_context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ctxutil

import (
"api/models"

"github.com/labstack/echo/v4"
)

func GetUser(c echo.Context) *models.User {
user, ok := c.Get("user").(*models.User)
if !ok {
return nil
}
return user
}
4 changes: 3 additions & 1 deletion api/database/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ func main() {
}
configs.InitDatabase()
db := configs.DB()
db.AutoMigrate(&models.User{})
if err := db.AutoMigrate(&models.User{}); err != nil {
log.Fatalf("error auto migrating database: %v\n", err)
}
}
110 changes: 80 additions & 30 deletions api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,33 +68,33 @@ const docTemplate = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/notify.CallRequest"
"$ref": "#/definitions/models.CallRequest"
}
}
],
"responses": {
"200": {
"description": "Called",
"description": "OK",
"schema": {
"type": "string"
"$ref": "#/definitions/models.SuccessResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "string"
"$ref": "#/definitions/models.BadRequestResponse"
}
},
"403": {
"description": "Forbidden",
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/notify.ErrorResponse"
"$ref": "#/definitions/models.NotifyErrorResponse"
}
}
}
}
},
"/user/create": {
"/user": {
"post": {
"description": "Create a new user with FCM token and get API key",
"consumes": [
Expand All @@ -114,38 +114,75 @@ const docTemplate = `{
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/user.CreateUserRequest"
"$ref": "#/definitions/models.CreateUserRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/user.CreateUserResponse"
"$ref": "#/definitions/models.CreateUserResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "string"
"$ref": "#/definitions/models.BadRequestResponse"
}
}
}
}
},
"/user/api-key": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Regenerates the API key for the authenticated user",
"produces": [
"application/json"
],
"tags": [
"user"
],
"summary": "Regenerate API key",
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/models.CreateUserResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/models.BadRequestResponse"
}
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/models.BadRequestResponse"
}
}
}
}
}
},
"definitions": {
"models.HealthCheckResponse": {
"models.BadRequestResponse": {
"type": "object",
"properties": {
"status": {
"error": {
"type": "string",
"example": "active"
"example": "Bad Request"
}
}
},
"notify.CallRequest": {
"models.CallRequest": {
"type": "object",
"required": [
"text"
Expand All @@ -157,16 +194,7 @@ const docTemplate = `{
}
}
},
"notify.ErrorResponse": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"example": "Token no longer valid"
}
}
},
"user.CreateUserRequest": {
"models.CreateUserRequest": {
"type": "object",
"required": [
"fcmToken"
Expand All @@ -178,17 +206,13 @@ const docTemplate = `{
}
}
},
"user.CreateUserResponse": {
"models.CreateUserResponse": {
"type": "object",
"properties": {
"apiKey": {
"type": "string",
"example": "00000000-0000-0000-0000-000000000000"
},
"fcmKey": {
"type": "string",
"example": "fcm-token-example"
},
"fcmKeyUpdated": {
"type": "string",
"example": "2025-01-01T00:00:00Z"
Expand All @@ -202,6 +226,32 @@ const docTemplate = `{
"example": "2025-01-01T00:00:00Z"
}
}
},
"models.HealthCheckResponse": {
"type": "object",
"properties": {
"status": {
"type": "string",
"example": "active"
}
}
},
"models.NotifyErrorResponse": {
"type": "object",
"properties": {
"reason": {
"type": "string",
"example": "Token no longer valid"
}
}
},
"models.SuccessResponse": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
}
}
},
"securityDefinitions": {
Expand Down
Loading