174 lines
5.5 KiB
Go
174 lines
5.5 KiB
Go
|
package mongo
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"finclip-app-manager/domain/entity"
|
||
|
"finclip-app-manager/domain/repository"
|
||
|
"finclip-app-manager/infrastructure/db/entity/mongo"
|
||
|
|
||
|
mgo "gitlab.finogeeks.club/finclip-backend-v2/finclip-mgo"
|
||
|
"gitlab.finogeeks.club/finclip-backend-v2/finclip-mgo/bson"
|
||
|
)
|
||
|
|
||
|
var _ repository.IAppBuildInfoRepo = new(AppBuildInfoMongoRepo)
|
||
|
|
||
|
type AppBuildInfoMongoRepo struct {
|
||
|
}
|
||
|
|
||
|
func NewAppBuildInfoMongoRepo() *AppBuildInfoMongoRepo {
|
||
|
return &AppBuildInfoMongoRepo{}
|
||
|
}
|
||
|
|
||
|
func (a *AppBuildInfoMongoRepo) Insert(ctx context.Context, item entity.AppBuildInfo) error {
|
||
|
mgoInfo := tr.CovertAppBuildInfoToMgo(&item)
|
||
|
return appBuildInfoTable.Insert(ctx, mgoInfo)
|
||
|
}
|
||
|
|
||
|
func (a *AppBuildInfoMongoRepo) GetInfoById(ctx context.Context, id string) (*entity.AppBuildInfo, error) {
|
||
|
filter := bson.M{"id": id}
|
||
|
item := mongo.AppBuildInfo{}
|
||
|
err := appBuildInfoTable.GetOne(ctx, filter, &item)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return tr.CovertAppBuildInfoToEntity(&item), nil
|
||
|
}
|
||
|
|
||
|
func (a *AppBuildInfoMongoRepo) GetInfoByBuildInfoId(ctx context.Context, buildInfoId string) (*entity.AppBuildInfo, error) {
|
||
|
filter := bson.M{"buildInfoId": buildInfoId}
|
||
|
item := mongo.AppBuildInfo{}
|
||
|
err := appBuildInfoTable.GetOne(ctx, filter, &item)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return tr.CovertAppBuildInfoToEntity(&item), nil
|
||
|
}
|
||
|
|
||
|
func (a *AppBuildInfoMongoRepo) GetInfoByBuildId(ctx context.Context, id string) (*entity.AppBuildInfo, error) {
|
||
|
filter := bson.M{"buildInfoId": id}
|
||
|
item := mongo.AppBuildInfo{}
|
||
|
err := appBuildInfoTable.GetOne(ctx, filter, &item)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return tr.CovertAppBuildInfoToEntity(&item), nil
|
||
|
}
|
||
|
|
||
|
func (a *AppBuildInfoMongoRepo) GetLatestInfoByAppId(ctx context.Context, appId string) (*entity.AppBuildInfo, error) {
|
||
|
|
||
|
filter := bson.M{"appId": appId}
|
||
|
|
||
|
item := mongo.AppBuildInfo{}
|
||
|
err := appBuildInfoTable.GetSortOne(ctx, filter, []string{"-created"}, &item)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return tr.CovertAppBuildInfoToEntity(&item), nil
|
||
|
}
|
||
|
|
||
|
func (a *AppBuildInfoMongoRepo) GetTrialInfoByAppId(ctx context.Context, appId string) (*entity.AppBuildInfo, error) {
|
||
|
|
||
|
filter := bson.M{"appId": appId, "source": entity.APP_BUILD_SOURCE_TRIAL}
|
||
|
|
||
|
item := mongo.AppBuildInfo{}
|
||
|
err := appBuildInfoTable.GetOne(ctx, filter, &item)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return tr.CovertAppBuildInfoToEntity(&item), nil
|
||
|
}
|
||
|
func (a *AppBuildInfoMongoRepo) GetTrialInfoById(ctx context.Context, id string) (*entity.AppBuildInfo, error) {
|
||
|
filter := bson.M{"id": id, "source": entity.APP_BUILD_SOURCE_TRIAL}
|
||
|
|
||
|
item := mongo.AppBuildInfo{}
|
||
|
err := appBuildInfoTable.GetOne(ctx, filter, &item)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return tr.CovertAppBuildInfoToEntity(&item), nil
|
||
|
}
|
||
|
func (a *AppBuildInfoMongoRepo) AddTrial(ctx context.Context, id string) error {
|
||
|
|
||
|
filter := bson.M{"id": id}
|
||
|
update := bson.M{"$set": bson.M{"source": entity.APP_BUILD_SOURCE_TRIAL}}
|
||
|
|
||
|
return appBuildInfoTable.UpdateOne(ctx, filter, update)
|
||
|
}
|
||
|
func (a *AppBuildInfoMongoRepo) CancelTrial(ctx context.Context, id string) error {
|
||
|
|
||
|
filter := bson.M{"id": id}
|
||
|
update := bson.M{"$set": bson.M{"source": entity.APP_BUILD_SOURCE_BUILD, "startParams.path_and_query": ""}}
|
||
|
|
||
|
return appBuildInfoTable.UpdateOne(ctx, filter, update)
|
||
|
|
||
|
}
|
||
|
func (a *AppBuildInfoMongoRepo) UpdateTrialStartParams(ctx context.Context, id string, params entity.AppStartParams) error {
|
||
|
|
||
|
filter := bson.M{"id": id}
|
||
|
update := bson.M{"$set": bson.M{"startParams.path_and_query": params.PathAndQuery}}
|
||
|
|
||
|
return appBuildInfoTable.UpdateOne(ctx, filter, update)
|
||
|
}
|
||
|
func (a *AppBuildInfoMongoRepo) UpdateTrialPath(ctx context.Context, id, path string) error {
|
||
|
|
||
|
filter := bson.M{"id": id}
|
||
|
update := bson.M{"$set": bson.M{"path": path}}
|
||
|
|
||
|
return appBuildInfoTable.UpdateOne(ctx, filter, update)
|
||
|
}
|
||
|
|
||
|
func (a *AppBuildInfoMongoRepo) UpdateOneStatus(ctx context.Context, id string, status bool) error {
|
||
|
filter := bson.M{"id": id}
|
||
|
update := bson.M{"$set": bson.M{"status": status}}
|
||
|
return appBuildInfoTable.UpdateOne(ctx, filter, update)
|
||
|
}
|
||
|
|
||
|
func (a *AppBuildInfoMongoRepo) GetList(ctx context.Context, appId string, pageNo, pageSize int) (int64, []entity.AppBuildInfo, error) {
|
||
|
list := make([]mongo.AppBuildInfo, 0)
|
||
|
filter := bson.M{"appId": appId}
|
||
|
|
||
|
total, err := appBuildInfoTable.GetSome(ctx, filter, []string{"-created"}, pageSize, pageNo, &list)
|
||
|
if err != nil {
|
||
|
return 0, nil, err
|
||
|
}
|
||
|
result := make([]entity.AppBuildInfo, 0)
|
||
|
for _, v := range list {
|
||
|
temp := v
|
||
|
result = append(result, *tr.CovertAppBuildInfoToEntity(&temp))
|
||
|
}
|
||
|
return int64(total), result, nil
|
||
|
}
|
||
|
func (a *AppBuildInfoMongoRepo) GetAll(ctx context.Context) ([]entity.AppBuildInfo, error) {
|
||
|
list := make([]mongo.AppBuildInfo, 0)
|
||
|
_, err := appBuildInfoTable.GetAll(ctx, bson.M{}, []string{}, &list)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
result := make([]entity.AppBuildInfo, 0)
|
||
|
for _, v := range list {
|
||
|
temp := v
|
||
|
result = append(result, *tr.CovertAppBuildInfoToEntity(&temp))
|
||
|
}
|
||
|
return result, nil
|
||
|
}
|
||
|
|
||
|
func (a *AppBuildInfoMongoRepo) GetAppBuilds(ctx context.Context, groupID, appId string, pageSize, pageNo int) (int64, []entity.AppBuildInfo, error) {
|
||
|
list := make([]mongo.AppBuildInfo, 0)
|
||
|
|
||
|
filter := bson.M{"appId": appId, "groupId": groupID}
|
||
|
total, err := appBuildInfoTable.GetSome(ctx, filter, []string{"-created"}, pageSize, pageNo, &list)
|
||
|
if err != nil {
|
||
|
return 0, nil, err
|
||
|
}
|
||
|
result := make([]entity.AppBuildInfo, 0)
|
||
|
for _, v := range list {
|
||
|
temp := v
|
||
|
result = append(result, *tr.CovertAppBuildInfoToEntity(&temp))
|
||
|
}
|
||
|
return int64(total), result, nil
|
||
|
}
|
||
|
|
||
|
func (a *AppBuildInfoMongoRepo) NotFound(err error) bool {
|
||
|
return err == mgo.ErrNotFound
|
||
|
}
|