package controllers import ( "github.com/dungnt11/senflow_app/internal/services" "github.com/gin-gonic/gin" ) // UserController triển khai IUserController type UserController struct { userService services.IUserService } // NewUserController tạo một instance mới của UserController func NewUserController(userService services.IUserService) *UserController { return &UserController{ userService: userService, } } // Register xử lý đăng ký người dùng func (uc *UserController) Register(c *gin.Context) { // Gọi service để thực hiện logic đăng ký result, err := uc.userService.Register(c) if err != nil { c.JSON(400, gin.H{ "error": err.Error(), }) return } c.JSON(200, result) } // Login xử lý đăng nhập func (uc *UserController) Login(c *gin.Context) { // Gọi service để thực hiện logic đăng nhập result, err := uc.userService.Login(c) if err != nil { c.JSON(400, gin.H{ "error": err.Error(), }) return } c.JSON(200, result) } // GetProfile xử lý lấy thông tin profile func (uc *UserController) GetProfile(c *gin.Context) { // Lấy user ID từ token hoặc param (giả định) userID := uint(1) // Trong thực tế, bạn sẽ lấy từ JWT token hoặc param // Gọi service để lấy thông tin profile result, err := uc.userService.GetProfile(userID) if err != nil { c.JSON(400, gin.H{ "error": err.Error(), }) return } c.JSON(200, result) } // UpdateProfile xử lý cập nhật profile func (uc *UserController) UpdateProfile(c *gin.Context) { // Lấy user ID từ token hoặc param (giả định) userID := uint(1) // Trong thực tế, bạn sẽ lấy từ JWT token hoặc param // Đọc dữ liệu từ request var data map[string]interface{} if err := c.ShouldBindJSON(&data); err != nil { c.JSON(400, gin.H{ "error": err.Error(), }) return } // Gọi service để cập nhật profile result, err := uc.userService.UpdateProfile(userID, data) if err != nil { c.JSON(400, gin.H{ "error": err.Error(), }) return } c.JSON(200, result) }