♻️ Use dealer's BaseModel
This commit is contained in:
		
							
								
								
									
										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/go.mod h1:Q51JPkKnV0UoOT/IRmdBh5CyfSlp7s8BRGzgooYHqkI=
 | 
			
		||||
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
 | 
			
		||||
 
 | 
			
		||||
@@ -2,10 +2,11 @@ package gap
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/dealer/pkg/proto"
 | 
			
		||||
	"github.com/rs/zerolog/log"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"github.com/spf13/viper"
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,9 @@ package grpc
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	health "google.golang.org/grpc/health/grpc_health_v1"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	health "google.golang.org/grpc/health/grpc_health_v1"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func (v *Server) Check(ctx context.Context, request *health.HealthCheckRequest) (*health.HealthCheckResponse, error) {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,13 @@
 | 
			
		||||
package grpc
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"net"
 | 
			
		||||
 | 
			
		||||
	"git.solsynth.dev/hydrogen/dealer/pkg/proto"
 | 
			
		||||
	"github.com/spf13/viper"
 | 
			
		||||
	"google.golang.org/grpc"
 | 
			
		||||
	health "google.golang.org/grpc/health/grpc_health_v1"
 | 
			
		||||
	"google.golang.org/grpc/reflection"
 | 
			
		||||
	"net"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/livekit/protocol/livekit"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
 | 
			
		||||
	"github.com/livekit/protocol/livekit"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Call struct {
 | 
			
		||||
	BaseModel
 | 
			
		||||
	hyper.BaseModel
 | 
			
		||||
 | 
			
		||||
	EndedAt *time.Time `json:"ended_at"`
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,10 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
import "fmt"
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type ChannelType = uint8
 | 
			
		||||
 | 
			
		||||
@@ -10,7 +14,7 @@ const (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Channel struct {
 | 
			
		||||
	BaseModel
 | 
			
		||||
	hyper.BaseModel
 | 
			
		||||
 | 
			
		||||
	Alias       string          `json:"alias"`
 | 
			
		||||
	Name        string          `json:"name"`
 | 
			
		||||
@@ -46,7 +50,7 @@ const (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type ChannelMember struct {
 | 
			
		||||
	BaseModel
 | 
			
		||||
	hyper.BaseModel
 | 
			
		||||
 | 
			
		||||
	ChannelID  uint        `json:"channel_id"`
 | 
			
		||||
	AccountID  uint        `json:"account_id"`
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,9 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
import "gorm.io/datatypes"
 | 
			
		||||
import (
 | 
			
		||||
	"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
 | 
			
		||||
	"gorm.io/datatypes"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	EventMessageNew    = "messages.new"
 | 
			
		||||
@@ -10,7 +13,7 @@ const (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Event struct {
 | 
			
		||||
	BaseModel
 | 
			
		||||
	hyper.BaseModel
 | 
			
		||||
 | 
			
		||||
	Uuid      string            `json:"uuid"`
 | 
			
		||||
	Body      datatypes.JSONMap `json:"body"`
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,11 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
import "git.solsynth.dev/hydrogen/dealer/pkg/hyper"
 | 
			
		||||
 | 
			
		||||
// Realm profiles basically fetched from Hydrogen.Passport
 | 
			
		||||
// But cache at here for better usage and database relations
 | 
			
		||||
type Realm struct {
 | 
			
		||||
	BaseModel
 | 
			
		||||
	hyper.BaseModel
 | 
			
		||||
 | 
			
		||||
	Alias       string    `json:"alias"`
 | 
			
		||||
	Name        string    `json:"name"`
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,8 @@ package api
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/server/exts"
 | 
			
		||||
 | 
			
		||||
@@ -176,7 +178,7 @@ func editChannel(c *fiber.Ctx) error {
 | 
			
		||||
		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 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)
 | 
			
		||||
	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 info, err := services.GetRealmMember(val.ExternalID, user.ID); err != nil {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ package api
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/server/exts"
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ package api
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/services"
 | 
			
		||||
	"github.com/gofiber/fiber/v2"
 | 
			
		||||
)
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ package api
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/dealer/pkg/proto"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
 | 
			
		||||
	"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
 | 
			
		||||
	if err := database.C.
 | 
			
		||||
		Where(models.Call{
 | 
			
		||||
			BaseModel: models.BaseModel{ID: id},
 | 
			
		||||
			BaseModel: hyper.BaseModel{ID: id},
 | 
			
		||||
			ChannelID: channel.ID,
 | 
			
		||||
		}).
 | 
			
		||||
		Preload("Founder").
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"regexp"
 | 
			
		||||
 | 
			
		||||
	"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
 | 
			
		||||
	"github.com/samber/lo"
 | 
			
		||||
@@ -21,7 +22,7 @@ func GetChannelAliasAvailability(alias string) error {
 | 
			
		||||
func GetChannel(id uint) (models.Channel, error) {
 | 
			
		||||
	var channel models.Channel
 | 
			
		||||
	tx := database.C.Where(models.Channel{
 | 
			
		||||
		BaseModel: models.BaseModel{ID: id},
 | 
			
		||||
		BaseModel: hyper.BaseModel{ID: id},
 | 
			
		||||
	}).Preload("Account").Preload("Realm")
 | 
			
		||||
	tx = PreloadDirectChannelMembers(tx)
 | 
			
		||||
	if err := tx.First(&channel).Error; err != nil {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ package services
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
 | 
			
		||||
	"github.com/spf13/viper"
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/dealer/pkg/proto"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/database"
 | 
			
		||||
	"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
 | 
			
		||||
	if err := database.C.
 | 
			
		||||
		Where(models.Event{
 | 
			
		||||
			BaseModel: models.BaseModel{ID: id},
 | 
			
		||||
			BaseModel: hyper.BaseModel{ID: id},
 | 
			
		||||
			ChannelID: channel.ID,
 | 
			
		||||
		}).
 | 
			
		||||
		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) {
 | 
			
		||||
	var event models.Event
 | 
			
		||||
	if err := database.C.Where(models.Event{
 | 
			
		||||
		BaseModel: models.BaseModel{ID: id},
 | 
			
		||||
		BaseModel: hyper.BaseModel{ID: id},
 | 
			
		||||
		ChannelID: channel.ID,
 | 
			
		||||
		SenderID:  member.ID,
 | 
			
		||||
	}).First(&event).Error; err != nil {
 | 
			
		||||
 
 | 
			
		||||
@@ -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/messaging/pkg/internal/database"
 | 
			
		||||
@@ -11,7 +13,6 @@ import (
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
 | 
			
		||||
	"github.com/samber/lo"
 | 
			
		||||
	"gorm.io/gorm"
 | 
			
		||||
	"reflect"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func GetRealmWithExtID(id uint) (models.Realm, error) {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,9 +2,10 @@ package services
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"github.com/samber/lo"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/samber/lo"
 | 
			
		||||
 | 
			
		||||
	"git.solsynth.dev/hydrogen/dealer/pkg/proto"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/models"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,18 +1,19 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/gap"
 | 
			
		||||
	"git.solsynth.dev/hydrogen/messaging/pkg/internal/grpc"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/signal"
 | 
			
		||||
	"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"
 | 
			
		||||
	"github.com/robfig/cron/v3"
 | 
			
		||||
 | 
			
		||||
	"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"
 | 
			
		||||
	"github.com/rs/zerolog"
 | 
			
		||||
	"github.com/rs/zerolog/log"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user