import lab3 files

This commit is contained in:
Голиков Maximillian Антон
2026-10-18 21:14:01 +03:00
parent ec540a1a72
commit 76322040e5
64 changed files with 4446 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
package handler
import (
"net/http"
"github.com/gin-gonic/gin"
"high-loud-apps-labs/internal/httpapi/dto"
"high-loud-apps-labs/internal/httpapi/middleware"
"high-loud-apps-labs/internal/service"
)
type UserHandler struct {
users *service.UserService
}
func NewUserHandler(users *service.UserService) *UserHandler {
return &UserHandler{users: users}
}
func (h *UserHandler) Create(c *gin.Context) {
var req dto.CreateUserRequest
if err := bindStrictJSON(c, &req); err != nil {
respondError(c, err)
return
}
u, err := h.users.Create(c.Request.Context(), req.Username, req.DisplayName, req.Password)
if err != nil {
respondError(c, err)
return
}
c.JSON(http.StatusCreated, dto.UserFromDomain(u))
}
func (h *UserHandler) Current(c *gin.Context) {
u := middleware.CurrentUser(c)
if u == nil {
respondError(c, &badRequestError{msg: "нет текущего пользователя"})
return
}
c.JSON(http.StatusOK, dto.UserFromDomain(u))
}