45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"video-factory/shortdrama/dao"
|
|
"video-factory/shortdrama/model/dto"
|
|
"video-factory/shortdrama/service"
|
|
)
|
|
|
|
type user struct{}
|
|
|
|
var User = new(user)
|
|
|
|
func (c *user) Login(ctx context.Context, req *dto.LoginReq) (res *dto.LoginRes, err error) {
|
|
user, token, err := service.UserService.Login(ctx, req.Account, req.Password)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
u := &dto.LoginUser{
|
|
Id: user.Id,
|
|
Role: user.Role,
|
|
Name: user.Name,
|
|
Province: user.Province,
|
|
Region: user.Region,
|
|
Address: user.Address,
|
|
}
|
|
if user.Role == "customer" {
|
|
u.Balance = service.CustomerService.GetBalance(ctx, user.Id)
|
|
}
|
|
if user.Role == "agent" {
|
|
if ap, _ := dao.AgentProfile.Get(ctx, user.Id); ap != nil {
|
|
if ap.ExpiredAt != nil {
|
|
u.ExpiredAt = ap.ExpiredAt.Format("Y-m-d H:i:s")
|
|
}
|
|
}
|
|
}
|
|
return &dto.LoginRes{Token: token, User: u}, nil
|
|
}
|
|
|
|
func (c *user) ChangePassword(ctx context.Context, req *dto.ChangePasswordReq) (res *struct{}, err error) {
|
|
return nil, errors.New("not implemented yet")
|
|
}
|