This commit is contained in:
2026-03-20 12:33:37 +01:00
commit ce3925423f
44 changed files with 3143 additions and 0 deletions

32
internal/user/handler.go Normal file
View File

@@ -0,0 +1,32 @@
package user
import "github.com/gin-gonic/gin"
type Handler struct {
service *Service
}
func NewHandler(service *Service) *Handler {
return &Handler{service: service}
}
func (h *Handler) Register(c *gin.Context) {
var req struct {
Username string `json:"username"`
Password string `json:"password"`
Role string `json:"role"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(400, gin.H{"error": "invalid request"})
return
}
user, err := h.service.CreateUser(req.Username, req.Password, req.Role)
if err != nil {
c.JSON(500, gin.H{"error": err.Error()})
return
}
c.JSON(201, gin.H{"id": user.ID, "username": user.Username, "role": user.Role})
}