72 lines
2.7 KiB
Go
72 lines
2.7 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.IPrivacySettingRepo = new(PrivacySettingRepoMongoRepo)
|
|
|
|
type PrivacySettingRepoMongoRepo struct {
|
|
}
|
|
|
|
func NewPrivacySettingRepoMongoRepo() *PrivacySettingRepoMongoRepo {
|
|
return &PrivacySettingRepoMongoRepo{}
|
|
}
|
|
|
|
func (a *PrivacySettingRepoMongoRepo) Insert(ctx context.Context, item entity.PrivacySettingInfo) error {
|
|
return privacyTable.Insert(ctx, tr.CovertPrivacySettingInfoToMongo(&item))
|
|
}
|
|
func (a *PrivacySettingRepoMongoRepo) Count(ctx context.Context, appId string) (int, error) {
|
|
return privacyTable.Count(ctx, bson.M{"app_id": appId})
|
|
}
|
|
func (a *PrivacySettingRepoMongoRepo) GetInfoByAppId(ctx context.Context, appId string) (*entity.PrivacySettingInfo, error) {
|
|
privacySettingInfoMongo := mongo.PrivacySettingInfoMongo{}
|
|
err := privacyTable.GetOne(ctx, bson.M{"app_id": appId}, &privacySettingInfoMongo)
|
|
if err != nil {
|
|
if NotFound(err) {
|
|
log.Errorf("GetInfoByTraceId err:%s", err.Error())
|
|
return &entity.PrivacySettingInfo{}, entity.NotFoundErr
|
|
}
|
|
}
|
|
|
|
result := tr.CovertPrivacySettingInfoToEntity(&privacySettingInfoMongo)
|
|
return result, err
|
|
}
|
|
func (a *PrivacySettingRepoMongoRepo) UpdateInfo(ctx context.Context, info entity.PrivacySettingInfo) error {
|
|
params := map[string]interface{}{}
|
|
params["app_id"] = info.AppId
|
|
params["commit_type"] = info.CommitType
|
|
params["user_message_type"] = info.UserMessageType
|
|
params["sdk_message"] = info.SdkMessage
|
|
params["contact_info_phone"] = info.ContactInfoPhone
|
|
params["contact_info_email"] = info.ContactInfoEmail
|
|
params["contact_info_wechat"] = info.ContactInfoWeChat
|
|
params["contact_info_other"] = info.ContactInfoOther
|
|
params["fixed_storage_time"] = info.FixedStorageTime
|
|
params["is_shortest_time"] = info.IsShortestTime
|
|
params["additional_doc_name"] = info.AdditionalDocName
|
|
params["additional_doc_netdiskid"] = info.AdditionalDocNetDiskId
|
|
params["additional_doc_content"] = info.AdditionalDocContent
|
|
params["is_first_save"] = info.IsFirstSave
|
|
params["effective_time"] = info.EffectiveTime
|
|
params["create_time"] = info.CreateTime
|
|
params["update_time"] = info.UpdateTime
|
|
filter := bson.M{
|
|
"app_id": info.AppId,
|
|
}
|
|
return privacyTable.UpdateOne(ctx, filter, bson.M{"$set": params})
|
|
|
|
}
|
|
|
|
func (a PrivacySettingRepoMongoRepo) DelInfoByAppId(ctx context.Context, appId string) error {
|
|
return privacyTable.Del(ctx, bson.M{"app_id": appId})
|
|
}
|
|
func (a PrivacySettingRepoMongoRepo) NotFound(err error) bool {
|
|
return err == mgo.ErrNotFound
|
|
}
|