♻️ Use the new dealer BaseUser and remove ExternalID
This commit is contained in:
@ -88,7 +88,7 @@ func NotifyPosterAccount(user models.Account, title, body string, subtitle *stri
|
||||
return err
|
||||
}
|
||||
_, err = proto.NewNotifierClient(pc).NotifyUser(ctx, &proto.NotifyUserRequest{
|
||||
UserId: uint64(user.ExternalID),
|
||||
UserId: uint64(user.ID),
|
||||
Notify: &proto.NotifyRequest{
|
||||
Topic: "interactive.feedback",
|
||||
Title: title,
|
||||
@ -101,7 +101,7 @@ func NotifyPosterAccount(user models.Account, title, body string, subtitle *stri
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("An error occurred when notify account...")
|
||||
} else {
|
||||
log.Debug().Uint("uid", user.ExternalID).Msg("Notified account.")
|
||||
log.Debug().Uint("uid", user.ID).Msg("Notified account.")
|
||||
}
|
||||
|
||||
return err
|
||||
|
@ -1,51 +0,0 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/models"
|
||||
"gorm.io/gorm"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func LinkAccount(userinfo *proto.UserInfo) (models.Account, error) {
|
||||
var account models.Account
|
||||
if userinfo == nil {
|
||||
return account, fmt.Errorf("remote userinfo was not found")
|
||||
}
|
||||
if err := database.C.Where(&models.Account{
|
||||
ExternalID: uint(userinfo.Id),
|
||||
}).First(&account).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
account = models.Account{
|
||||
Name: userinfo.Name,
|
||||
Nick: userinfo.Nick,
|
||||
Avatar: userinfo.Avatar,
|
||||
Banner: userinfo.Banner,
|
||||
Description: userinfo.GetDescription(),
|
||||
EmailAddress: userinfo.Email,
|
||||
PowerLevel: 0,
|
||||
ExternalID: uint(userinfo.Id),
|
||||
}
|
||||
return account, database.C.Save(&account).Error
|
||||
}
|
||||
return account, err
|
||||
}
|
||||
|
||||
prev := account
|
||||
account.Name = userinfo.Name
|
||||
account.Nick = userinfo.Nick
|
||||
account.Avatar = userinfo.Avatar
|
||||
account.Banner = userinfo.Banner
|
||||
account.Description = userinfo.GetDescription()
|
||||
account.EmailAddress = userinfo.Email
|
||||
|
||||
var err error
|
||||
if !reflect.DeepEqual(prev, account) {
|
||||
err = database.C.Save(&account).Error
|
||||
}
|
||||
|
||||
return account, err
|
||||
}
|
@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/models"
|
||||
"gorm.io/gorm"
|
||||
@ -27,7 +28,7 @@ func GetCategory(alias string) (models.Category, error) {
|
||||
func GetCategoryWithID(id uint) (models.Category, error) {
|
||||
var category models.Category
|
||||
if err := database.C.Where(models.Category{
|
||||
BaseModel: models.BaseModel{ID: id},
|
||||
BaseModel: hyper.BaseModel{ID: id},
|
||||
}).First(&category).Error; err != nil {
|
||||
return category, err
|
||||
}
|
||||
|
@ -310,7 +310,7 @@ func NewPost(user models.Account, item models.Post) (models.Post, error) {
|
||||
|
||||
if item.RealmID != nil {
|
||||
log.Debug().Uint("id", *item.RealmID).Msg("Looking for post author realm...")
|
||||
_, err := GetRealmMember(*item.RealmID, user.ExternalID)
|
||||
_, err := GetRealmMember(*item.RealmID, user.ID)
|
||||
if err != nil {
|
||||
return item, fmt.Errorf("you aren't a part of that realm: %v", err)
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/database"
|
||||
@ -11,7 +13,6 @@ import (
|
||||
"git.solsynth.dev/hydrogen/interactive/pkg/internal/models"
|
||||
"github.com/samber/lo"
|
||||
"gorm.io/gorm"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func GetRealmWithExtID(id uint) (models.Realm, error) {
|
||||
@ -54,7 +55,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.ExternalID),
|
||||
RealmId: uint64(realm.ID),
|
||||
UserId: lo.ToPtr(uint64(userId)),
|
||||
})
|
||||
if err != nil {
|
||||
@ -69,17 +70,10 @@ func LinkRealm(info *proto.RealmInfo) (models.Realm, error) {
|
||||
if info == nil {
|
||||
return realm, fmt.Errorf("remote realm info was not found")
|
||||
}
|
||||
if err := database.C.Where(&models.Realm{
|
||||
ExternalID: uint(info.Id),
|
||||
}).First(&realm).Error; err != nil {
|
||||
if err := database.C.Where("id = ?", info.Id).First(&realm).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
realm = models.Realm{
|
||||
Alias: info.Alias,
|
||||
Name: info.Name,
|
||||
Description: info.Description,
|
||||
IsPublic: info.IsPublic,
|
||||
IsCommunity: info.IsCommunity,
|
||||
ExternalID: uint(info.Id),
|
||||
BaseRealm: hyper.LinkRealm(info),
|
||||
}
|
||||
return realm, database.C.Save(&realm).Error
|
||||
}
|
||||
@ -90,6 +84,8 @@ func LinkRealm(info *proto.RealmInfo) (models.Realm, error) {
|
||||
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
|
||||
|
||||
|
Reference in New Issue
Block a user