finclip-app-manager/infrastructure/db/repo/mysql/privacy_setting_info.go

81 lines
2.9 KiB
Go

package mysql
import (
"context"
"finclip-app-manager/domain/entity"
"finclip-app-manager/domain/repository"
"finclip-app-manager/infrastructure/db/entity/sql"
"gorm.io/gorm"
)
var _ repository.IPrivacySettingRepo = new(PrivacySettingRepoMysqlRepo)
type PrivacySettingRepoMysqlRepo struct {
}
func NewPrivacySettingRepoMysqlRepo() *PrivacySettingRepoMysqlRepo {
return &PrivacySettingRepoMysqlRepo{}
}
func (a *PrivacySettingRepoMysqlRepo) Insert(ctx context.Context, item entity.PrivacySettingInfo) error {
err := DB.Model(&sql.PrivacySettingInfo{}).Create(tr.CovertPrivacySettingInfoToSql(&item)).Error
return err
}
func (a *PrivacySettingRepoMysqlRepo) Count(ctx context.Context, appId string) (int, error) {
query := "app_id = ?"
args := []interface{}{appId}
var count int64
err := DB.Model(&sql.PrivacySettingInfo{}).Where(query, args...).Count(&count).Error
return int(count), err
}
func (a *PrivacySettingRepoMysqlRepo) GetInfoByAppId(ctx context.Context, appId string) (*entity.PrivacySettingInfo, error) {
query := "app_id = ?"
args := []interface{}{appId}
privacySettingInfoMysql := sql.PrivacySettingInfo{}
err := DB.Model(&sql.PrivacySettingInfo{}).Where(query, args...).First(&privacySettingInfoMysql).Error
if err != nil {
return nil, err
}
result := tr.CovertPrivacySettingInfoToEntity(&privacySettingInfoMysql)
return result, err
}
func (a *PrivacySettingRepoMysqlRepo) UpdateInfo(ctx context.Context, info entity.PrivacySettingInfo) error {
query := "app_id = ?"
args := []interface{}{info.AppId}
params := map[string]interface{}{
"app_id": info.AppId,
"commit_type": info.CommitType,
"user_message_type": info.UserMessageType,
"sdk_message": info.SdkMessage,
"contact_info_phone": info.ContactInfoPhone,
"contact_info_email": info.ContactInfoEmail,
"contact_info_wechat": info.ContactInfoWeChat,
"contact_info_other": info.ContactInfoOther,
"fixed_storage_time": info.FixedStorageTime,
"is_shortest_time": info.IsShortestTime,
"additional_doc_name": info.AdditionalDocName,
"additional_doc_net_disk_id": info.AdditionalDocNetDiskId,
"additional_doc_content": info.AdditionalDocContent,
"is_first_save": info.IsFirstSave,
"effective_time": info.EffectiveTime,
"create_time": info.CreateTime,
"update_time": info.UpdateTime,
}
return DB.Model(&sql.PrivacySettingInfo{}).Where(query, args...).Updates(params).Error
}
func (a PrivacySettingRepoMysqlRepo) DelInfoByAppId(ctx context.Context, appId string) error {
query := "app_id = ?"
args := []interface{}{appId}
return DB.Model(&sql.PrivacySettingInfo{}).Where(query, args...).Delete(&sql.PrivacySettingInfo{}).Error
}
func (a PrivacySettingRepoMysqlRepo) NotFound(err error) bool {
return err == gorm.ErrRecordNotFound
}