push_app_info_repository.go 1.2 KB
package repository

import (
	"github.com/astaxie/beego/orm"
	"openapi/pkg/domain"
	"openapi/pkg/infrastructure/bgorm/model"
)

type AppInfoRepository struct {
}

func (repository *AppInfoRepository) FindOne(queryOptions map[string]interface{}) (*domain.AppInfo, error) {
	o := orm.NewOrm()
	model := new(models.PushAppInfo)
	qs := o.QueryTable(model).Filter("project_key", queryOptions["project_key"])
	err := qs.One(model)
	if err != nil {
		return nil, err
	}
	return repository.transformBgormModelToDomainModel(model)
}

func (repository *AppInfoRepository) Find(queryOptions map[string]interface{}) (rsp []*domain.AppInfo, err error) {
	return
}

func (repository *AppInfoRepository) transformBgormModelToDomainModel(model *models.PushAppInfo) (*domain.AppInfo, error) {
	return &domain.AppInfo{
		Id:              model.Id,
		AppKey:          model.AppKey,
		AppMasterSecret: model.AppMasterSecret,
		AppId:           model.AppId,
		ProjectName:     model.ProjectName,
		ProjectKey:      model.ProjectKey,
	}, nil
}

func NewAppInfoRepository(transactionContext interface{}) (*AppInfoRepository, error) {
	if transactionContext == nil {
		return &AppInfoRepository{}, nil
	} else {
		return &AppInfoRepository{}, nil
	}
}