func (i *UserGuestInter) scopeModel(user *domain.User) error { user.CreatedAt = time.Time{} user.UpdatedAt = time.Time{} user.Account = domain.Account{} return nil }
func (r *UserRepo) UpdateByID(id int, user *domain.User, context usecases.QueryContext) (*domain.User, error) { query, err := r.store.BuildQuery(context.Filter, context.OwnerRelations) if err != nil { return nil, internalerrors.DatabaseError } dbName := utils.ToDBName("users") oldUser := &domain.User{} err = query.Where(dbName+".id = ?", id).First(oldUser).Error if err != nil { if strings.Contains(err.Error(), "record not found") { return nil, internalerrors.NotFound } return nil, internalerrors.DatabaseError } user.ID = oldUser.ID user.CreatedAt = oldUser.CreatedAt err = r.store.GetDB().Save(&user).Error if err != nil { if strings.Contains(err.Error(), "constraint") { return nil, internalerrors.NewViolatedConstraint(err.Error()) } return nil, internalerrors.DatabaseError } return user, nil }
func (i *UserInter) scopeModel(user *domain.User) error { user.CreatedAt = time.Time{} user.UpdatedAt = time.Time{} user.Account = domain.Account{} if user.Password != "" { hashedPassword, err := bcrypt.GenerateFromPassword([]byte(user.Password), 0) if err != nil { return err } user.Password = string(hashedPassword) } return nil }
func (i *AccountGuestInter) Signup(user *domain.User) (*domain.Account, error) { account, err := i.repo.CreateOne(&domain.Account{}) if err != nil { return nil, err } user.AccountID = account.ID user, err = i.userInter.CreateOne(user) if err != nil { return nil, err } account.Users = []domain.User{*user} return account, nil }