fusenapi/model/gmodel/fs_address_logic.go
2023-06-19 10:12:58 +08:00

25 lines
715 B
Go
Executable File

package gmodel
import (
"context"
"errors"
"gorm.io/gorm"
)
func (a *FsAddressModel) GetOne(ctx context.Context, id int64, userId int64) (resp FsAddress, err error) {
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`id` = ? and `user_id` = ? and `status` = ? ", id, userId, 1).First(&resp).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsAddress{}, err
}
return resp, nil
}
func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (resp []FsAddress, err error) {
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = ?", userId, 1).Order("`id` DESC").Find(&resp).Error
if err != nil {
return nil, err
}
return
}