♻️ Use dealer's BaseModel
This commit is contained in:
parent
f962376f42
commit
14e3750bd9
6
go.sum
6
go.sum
@ -1,9 +1,3 @@
|
|||||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240823105014-4f93800f7283 h1:dfSqc32SSIBsUkhRTKzk90C4v8YCQObavUIrw/+ZfQc=
|
|
||||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240823105014-4f93800f7283/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
|
|
||||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240823110807-df5676cbe4d8 h1:2uoqdm2Z5yhJck0udcx9EAPHaoNse0pPZihJG5J8Q8A=
|
|
||||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240823110807-df5676cbe4d8/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
|
|
||||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240823113302-208da7e90fdb h1:dv4uVDMe53eBprW2Q8ocAhZuO+DKWlWyxGiJMiwE62E=
|
|
||||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240823113302-208da7e90fdb/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
|
|
||||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240911145828-d734d617bfc8 h1:kWheneSdSySG5tz9TAXrtr546JdMpQZTyWDFk4jeGwg=
|
git.solsynth.dev/hydrogen/dealer v0.0.0-20240911145828-d734d617bfc8 h1:kWheneSdSySG5tz9TAXrtr546JdMpQZTyWDFk4jeGwg=
|
||||||
git.solsynth.dev/hydrogen/dealer v0.0.0-20240911145828-d734d617bfc8/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
|
git.solsynth.dev/hydrogen/dealer v0.0.0-20240911145828-d734d617bfc8/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
|
||||||
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
|
||||||
|
@ -2,10 +2,11 @@ package gap
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
@ -2,8 +2,9 @@ package grpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
health "google.golang.org/grpc/health/grpc_health_v1"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
health "google.golang.org/grpc/health/grpc_health_v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (v *Server) Check(ctx context.Context, request *health.HealthCheckRequest) (*health.HealthCheckResponse, error) {
|
func (v *Server) Check(ctx context.Context, request *health.HealthCheckRequest) (*health.HealthCheckResponse, error) {
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package grpc
|
package grpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
health "google.golang.org/grpc/health/grpc_health_v1"
|
health "google.golang.org/grpc/health/grpc_health_v1"
|
||||||
"google.golang.org/grpc/reflection"
|
"google.golang.org/grpc/reflection"
|
||||||
"net"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"gorm.io/datatypes"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type JSONMap = datatypes.JSONType[map[string]any]
|
|
||||||
|
|
||||||
type BaseModel struct {
|
|
||||||
ID uint `json:"id" gorm:"primaryKey"`
|
|
||||||
CreatedAt time.Time `json:"created_at"`
|
|
||||||
UpdatedAt time.Time `json:"updated_at"`
|
|
||||||
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
|
|
||||||
}
|
|
@ -1,12 +1,14 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/livekit/protocol/livekit"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
|
"github.com/livekit/protocol/livekit"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Call struct {
|
type Call struct {
|
||||||
BaseModel
|
hyper.BaseModel
|
||||||
|
|
||||||
EndedAt *time.Time `json:"ended_at"`
|
EndedAt *time.Time `json:"ended_at"`
|
||||||
|
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
|
)
|
||||||
|
|
||||||
type ChannelType = uint8
|
type ChannelType = uint8
|
||||||
|
|
||||||
@ -10,7 +14,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
BaseModel
|
hyper.BaseModel
|
||||||
|
|
||||||
Alias string `json:"alias"`
|
Alias string `json:"alias"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
@ -46,7 +50,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ChannelMember struct {
|
type ChannelMember struct {
|
||||||
BaseModel
|
hyper.BaseModel
|
||||||
|
|
||||||
ChannelID uint `json:"channel_id"`
|
ChannelID uint `json:"channel_id"`
|
||||||
AccountID uint `json:"account_id"`
|
AccountID uint `json:"account_id"`
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import "gorm.io/datatypes"
|
import (
|
||||||
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
|
"gorm.io/datatypes"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
EventMessageNew = "messages.new"
|
EventMessageNew = "messages.new"
|
||||||
@ -10,7 +13,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
BaseModel
|
hyper.BaseModel
|
||||||
|
|
||||||
Uuid string `json:"uuid"`
|
Uuid string `json:"uuid"`
|
||||||
Body datatypes.JSONMap `json:"body"`
|
Body datatypes.JSONMap `json:"body"`
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
|
import "git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
|
|
||||||
// Realm profiles basically fetched from Hydrogen.Passport
|
// Realm profiles basically fetched from Hydrogen.Passport
|
||||||
// But cache at here for better usage and database relations
|
// But cache at here for better usage and database relations
|
||||||
type Realm struct {
|
type Realm struct {
|
||||||
BaseModel
|
hyper.BaseModel
|
||||||
|
|
||||||
Alias string `json:"alias"`
|
Alias string `json:"alias"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
@ -2,6 +2,8 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/server/exts"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/server/exts"
|
||||||
|
|
||||||
@ -176,7 +178,7 @@ func editChannel(c *fiber.Ctx) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
tx := database.C.Where(&models.Channel{BaseModel: models.BaseModel{ID: uint(id)}})
|
tx := database.C.Where(&models.Channel{BaseModel: hyper.BaseModel{ID: uint(id)}})
|
||||||
|
|
||||||
if val, ok := c.Locals("realm").(models.Realm); ok {
|
if val, ok := c.Locals("realm").(models.Realm); ok {
|
||||||
if info, err := services.GetRealmMember(val.ExternalID, user.ID); err != nil {
|
if info, err := services.GetRealmMember(val.ExternalID, user.ID); err != nil {
|
||||||
@ -218,7 +220,7 @@ func deleteChannel(c *fiber.Ctx) error {
|
|||||||
user := c.Locals("user").(models.Account)
|
user := c.Locals("user").(models.Account)
|
||||||
id, _ := c.ParamsInt("channelId", 0)
|
id, _ := c.ParamsInt("channelId", 0)
|
||||||
|
|
||||||
tx := database.C.Where(&models.Channel{BaseModel: models.BaseModel{ID: uint(id)}})
|
tx := database.C.Where(&models.Channel{BaseModel: hyper.BaseModel{ID: uint(id)}})
|
||||||
|
|
||||||
if val, ok := c.Locals("realm").(models.Realm); ok {
|
if val, ok := c.Locals("realm").(models.Realm); ok {
|
||||||
if info, err := services.GetRealmMember(val.ExternalID, user.ID); err != nil {
|
if info, err := services.GetRealmMember(val.ExternalID, user.ID); err != nil {
|
||||||
|
@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/server/exts"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/server/exts"
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/services"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
||||||
@ -39,7 +40,7 @@ func GetCall(channel models.Channel, id uint) (models.Call, error) {
|
|||||||
var call models.Call
|
var call models.Call
|
||||||
if err := database.C.
|
if err := database.C.
|
||||||
Where(models.Call{
|
Where(models.Call{
|
||||||
BaseModel: models.BaseModel{ID: id},
|
BaseModel: hyper.BaseModel{ID: id},
|
||||||
ChannelID: channel.ID,
|
ChannelID: channel.ID,
|
||||||
}).
|
}).
|
||||||
Preload("Founder").
|
Preload("Founder").
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
@ -21,7 +22,7 @@ func GetChannelAliasAvailability(alias string) error {
|
|||||||
func GetChannel(id uint) (models.Channel, error) {
|
func GetChannel(id uint) (models.Channel, error) {
|
||||||
var channel models.Channel
|
var channel models.Channel
|
||||||
tx := database.C.Where(models.Channel{
|
tx := database.C.Where(models.Channel{
|
||||||
BaseModel: models.BaseModel{ID: id},
|
BaseModel: hyper.BaseModel{ID: id},
|
||||||
}).Preload("Account").Preload("Realm")
|
}).Preload("Account").Preload("Realm")
|
||||||
tx = PreloadDirectChannelMembers(tx)
|
tx = PreloadDirectChannelMembers(tx)
|
||||||
if err := tx.First(&channel).Error; err != nil {
|
if err := tx.First(&channel).Error; err != nil {
|
||||||
|
@ -2,6 +2,7 @@ package services
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
||||||
@ -47,7 +48,7 @@ func GetEvent(channel models.Channel, id uint) (models.Event, error) {
|
|||||||
var event models.Event
|
var event models.Event
|
||||||
if err := database.C.
|
if err := database.C.
|
||||||
Where(models.Event{
|
Where(models.Event{
|
||||||
BaseModel: models.BaseModel{ID: id},
|
BaseModel: hyper.BaseModel{ID: id},
|
||||||
ChannelID: channel.ID,
|
ChannelID: channel.ID,
|
||||||
}).
|
}).
|
||||||
Preload("Sender").
|
Preload("Sender").
|
||||||
@ -62,7 +63,7 @@ func GetEvent(channel models.Channel, id uint) (models.Event, error) {
|
|||||||
func GetEventWithSender(channel models.Channel, member models.ChannelMember, id uint) (models.Event, error) {
|
func GetEventWithSender(channel models.Channel, member models.ChannelMember, id uint) (models.Event, error) {
|
||||||
var event models.Event
|
var event models.Event
|
||||||
if err := database.C.Where(models.Event{
|
if err := database.C.Where(models.Event{
|
||||||
BaseModel: models.BaseModel{ID: id},
|
BaseModel: hyper.BaseModel{ID: id},
|
||||||
ChannelID: channel.ID,
|
ChannelID: channel.ID,
|
||||||
SenderID: member.ID,
|
SenderID: member.ID,
|
||||||
}).First(&event).Error; err != nil {
|
}).First(&event).Error; err != nil {
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
||||||
@ -11,7 +13,6 @@ import (
|
|||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetRealmWithExtID(id uint) (models.Realm, error) {
|
func GetRealmWithExtID(id uint) (models.Realm, error) {
|
||||||
|
@ -2,9 +2,10 @@ package services
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/samber/lo"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/samber/lo"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
|
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/grpc"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
|
||||||
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/grpc"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/services"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/services"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/server"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/server"
|
||||||
|
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal"
|
pkg "git.solsynth.dev/hydrogen/messaging/pkg/internal"
|
||||||
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
Loading…
Reference in New Issue
Block a user