⬆️ Upgrade dealer
This commit is contained in:
parent
b226409caf
commit
277f1ee05f
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.solsynth.dev/hydrogen/interactive
|
||||
go 1.21.6
|
||||
|
||||
require (
|
||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240914133539-4a48b980f0b3
|
||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240917083841-b14c0240a75f
|
||||
github.com/go-playground/validator/v10 v10.17.0
|
||||
github.com/gofiber/fiber/v2 v2.52.4
|
||||
github.com/json-iterator/go v1.1.12
|
||||
|
2
go.sum
2
go.sum
@ -1,5 +1,7 @@
|
||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240914133539-4a48b980f0b3 h1:ucko8l9rC/XD/Gfk9lcQftyqb9tvHjL5f+aW3ydf1OI=
|
||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240914133539-4a48b980f0b3/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
|
||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240917083841-b14c0240a75f h1:3jLpcws4/zmNUA60w1RtAtGNjcQd5NZCcbW5HQcUcvw=
|
||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240917083841-b14c0240a75f/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
|
||||
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
|
@ -2,9 +2,6 @@ package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
@ -12,7 +9,7 @@ import (
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/gap"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/models"
|
||||
"github.com/samber/lo"
|
||||
"gorm.io/gorm"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func GetRealmWithExtID(id uint) (models.Realm, error) {
|
||||
@ -27,7 +24,9 @@ func GetRealmWithExtID(id uint) (models.Realm, error) {
|
||||
if err != nil {
|
||||
return realm, err
|
||||
}
|
||||
return LinkRealm(response)
|
||||
prefix := viper.GetString("database.prefix")
|
||||
rm, err := hyper.LinkRealm(database.C, prefix+"realms", response)
|
||||
return models.Realm{BaseRealm: rm}, err
|
||||
}
|
||||
|
||||
func GetRealmWithAlias(alias string) (models.Realm, error) {
|
||||
@ -42,7 +41,9 @@ func GetRealmWithAlias(alias string) (models.Realm, error) {
|
||||
if err != nil {
|
||||
return realm, err
|
||||
}
|
||||
return LinkRealm(response)
|
||||
prefix := viper.GetString("database.prefix")
|
||||
rm, err := hyper.LinkRealm(database.C, prefix+"realms", response)
|
||||
return models.Realm{BaseRealm: rm}, err
|
||||
}
|
||||
|
||||
func GetRealmMember(realmId uint, userId uint) (*proto.RealmMemberInfo, error) {
|
||||
@ -55,7 +56,7 @@ func GetRealmMember(realmId uint, userId uint) (*proto.RealmMemberInfo, error) {
|
||||
return nil, err
|
||||
}
|
||||
response, err := proto.NewRealmClient(pc).GetRealmMember(context.Background(), &proto.RealmMemberLookupRequest{
|
||||
RealmId: uint64(realm.ID),
|
||||
RealmId: lo.ToPtr(uint64(realm.ID)),
|
||||
UserId: lo.ToPtr(uint64(userId)),
|
||||
})
|
||||
if err != nil {
|
||||
@ -64,35 +65,3 @@ func GetRealmMember(realmId uint, userId uint) (*proto.RealmMemberInfo, error) {
|
||||
return response, nil
|
||||
}
|
||||
}
|
||||
|
||||
func LinkRealm(info *proto.RealmInfo) (models.Realm, error) {
|
||||
var realm models.Realm
|
||||
if info == nil {
|
||||
return realm, fmt.Errorf("remote realm info was not found")
|
||||
}
|
||||
if err := database.C.Where("id = ?", info.Id).First(&realm).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
realm = models.Realm{
|
||||
BaseRealm: hyper.LinkRealm(info),
|
||||
}
|
||||
return realm, database.C.Save(&realm).Error
|
||||
}
|
||||
return realm, err
|
||||
}
|
||||
|
||||
prev := realm
|
||||
realm.Alias = info.Alias
|
||||
realm.Name = info.Name
|
||||
realm.Description = info.Description
|
||||
realm.Avatar = info.Avatar
|
||||
realm.Banner = info.Banner
|
||||
realm.IsPublic = info.IsPublic
|
||||
realm.IsCommunity = info.IsCommunity
|
||||
|
||||
var err error
|
||||
if !reflect.DeepEqual(prev, realm) {
|
||||
err = database.C.Save(&realm).Error
|
||||
}
|
||||
|
||||
return realm, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user