// CreateUser creates a new user in the database
CreateUser creates a new user in the database
// CreateUser creates a new user in the database
func (r repository) CreateUser(user *entities.User, ctx context.Context) error {
	hash, err := bcrypt.GenerateFromPassword([]byte(user.
		Password),
		utils.PasswordEncryptionCost)
	user.Password = string(hash)
	if err != nil {
		return err
	}
	user.CreatedAt = time.Now()
	_, err = r.Collection.InsertOne(context.Background(), user)
	if err != nil {
		if mongo.IsDuplicateKeyError(err) {
			return utils.ErrUserExists
		}
		return err
	}
	return nil
}
func ( r repository ) CreateUser ( user * entities . User , ctx context . Context ) error { hash , err := bcrypt . GenerateFromPassword ( [ ] byte ( user . Password ) , utils . PasswordEncryptionCost ) user . Password = string ( hash ) if err != nil { return err } user . CreatedAt = time . Now ( ) _ , err = r . Collection . InsertOne ( context . Background ( ) , user ) if err != nil { if mongo . IsDuplicateKeyError ( err ) { return utils . ErrUserExists } return err } return nil }
CreateUser creates a new user in the database
CreateUser creates a new user in the database