add users
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"eslogad-be/internal/appcontext"
|
||||
"eslogad-be/internal/constants"
|
||||
@@ -64,12 +66,24 @@ func (h *UserHandler) BulkCreateUsers(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if len(req.Users) > 100 {
|
||||
h.sendValidationErrorResponse(c, "Cannot create more than 100 users at once", constants.MissingFieldErrorCode)
|
||||
// Increased limit to handle 1000+ users
|
||||
if len(req.Users) > 5000 {
|
||||
h.sendValidationErrorResponse(c, "Cannot create more than 5000 users at once", constants.MissingFieldErrorCode)
|
||||
return
|
||||
}
|
||||
|
||||
response, err := h.userService.BulkCreateUsers(c.Request.Context(), &req)
|
||||
// Set a longer timeout for large bulk operations
|
||||
ctx := c.Request.Context()
|
||||
if len(req.Users) > 500 {
|
||||
// Create a context with extended timeout for large operations
|
||||
var cancel context.CancelFunc
|
||||
ctx, cancel = context.WithTimeout(ctx, 10*time.Minute)
|
||||
defer cancel()
|
||||
}
|
||||
|
||||
logger.FromContext(c).Infof("UserHandler::BulkCreateUsers -> Starting bulk creation of %d users", len(req.Users))
|
||||
|
||||
response, err := h.userService.BulkCreateUsers(ctx, &req)
|
||||
if err != nil {
|
||||
logger.FromContext(c).WithError(err).Error("UserHandler::BulkCreateUsers -> Failed to bulk create users")
|
||||
h.sendErrorResponse(c, err.Error(), http.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user