feat: add USER_ID_MIDDLEWARE constant and update AuthMiddleware to use it
This commit is contained in:
@@ -33,3 +33,7 @@ const (
|
||||
API_PATH_AUTH_LOGIN = "/login"
|
||||
API_PATH_PROFILE = "/profile"
|
||||
)
|
||||
|
||||
const (
|
||||
USER_ID_MIDDLEWARE = "user_id"
|
||||
)
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"wm-backend/configs/constants"
|
||||
"wm-backend/pkg/helper"
|
||||
"wm-backend/response"
|
||||
|
||||
@@ -48,7 +49,7 @@ func AuthMiddleware() gin.HandlerFunc {
|
||||
}
|
||||
|
||||
// 5. Set user_id in gin context for downstream handlers
|
||||
c.Set("user_id", userID)
|
||||
c.Set(constants.USER_ID_MIDDLEWARE, userID)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
"wm-backend/configs/constants"
|
||||
"wm-backend/global"
|
||||
"wm-backend/internal/models"
|
||||
"wm-backend/internal/models/requests"
|
||||
@@ -29,6 +30,7 @@ import (
|
||||
// @Failure 500 {object} response.ErrorResponse
|
||||
// @Router /v1/invoices [post]
|
||||
func InvoiceCreate(c *gin.Context) error {
|
||||
userID, _ := c.Get(constants.USER_ID_MIDDLEWARE)
|
||||
requestBody := requests.CreateInvoiceRequest{}
|
||||
if helper.IsShouldBindJSON(c, &requestBody) {
|
||||
return nil
|
||||
@@ -39,7 +41,7 @@ func InvoiceCreate(c *gin.Context) error {
|
||||
InvoiceConfigID: requestBody.InvoiceConfigID,
|
||||
TotalItems: requestBody.TotalItems,
|
||||
Note: requestBody.Note,
|
||||
CreatedBy: requestBody.CreatedBy,
|
||||
CreatedBy: userID.(string),
|
||||
ApprovedBy: requestBody.ApprovedBy,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user