Able to get the creator details of channel

This commit is contained in:
LittleSheep 2024-04-25 21:00:45 +08:00
parent fd611d7f67
commit b4f24f0ae0
9 changed files with 60 additions and 12 deletions

9
.idea/Messaging.iml generated Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

19
.idea/dataSources.xml generated Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="hy_messaging@localhost" uuid="bdafe5e4-b64b-48b5-91b9-d004691610a6">
<driver-ref>postgresql</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
<jdbc-url>jdbc:postgresql://localhost:5432/hy_messaging</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
<data-source source="LOCAL" name="messaging@im.solsynth.dev" uuid="4470fffd-ce14-4a9e-947a-5addec3a9ae5">
<driver-ref>postgresql</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
<jdbc-url>jdbc:postgresql://im.solsynth.dev:5432/messaging</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Messaging.iml" filepath="$PROJECT_DIR$/.idea/Messaging.iml" />
</modules>
</component>
</project>

6
.idea/sqldialects.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="PROJECT" dialect="PostgreSQL" />
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -10,10 +10,8 @@ import (
func getChannel(c *fiber.Ctx) error { func getChannel(c *fiber.Ctx) error {
alias := c.Params("channel") alias := c.Params("channel")
var channel models.Channel channel, err := services.GetChannelWithAlias(alias)
if err := database.C.Where(&models.Channel{ if err != nil {
Alias: alias,
}).First(&channel).Error; err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error()) return fiber.NewError(fiber.StatusNotFound, err.Error())
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/samber/lo" "github.com/samber/lo"
) )
func unifiedGateway(c *websocket.Conn) { func messageGateway(c *websocket.Conn) {
user := c.Locals("principal").(models.Account) user := c.Locals("principal").(models.Account)
// Push connection // Push connection

View File

@ -1,13 +1,14 @@
package server package server
import ( import (
"git.solsynth.dev/hydrogen/messaging/pkg"
"github.com/gofiber/contrib/websocket"
"github.com/gofiber/fiber/v2/middleware/favicon"
"net/http" "net/http"
"strings" "strings"
"time" "time"
"git.solsynth.dev/hydrogen/messaging/pkg"
"github.com/gofiber/contrib/websocket"
"github.com/gofiber/fiber/v2/middleware/favicon"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cache" "github.com/gofiber/fiber/v2/middleware/cache"
"github.com/gofiber/fiber/v2/middleware/cors" "github.com/gofiber/fiber/v2/middleware/cors"
@ -103,7 +104,7 @@ func NewServer() {
channels.Post("/:channel/calls/ongoing/token", authMiddleware, exchangeCallToken) channels.Post("/:channel/calls/ongoing/token", authMiddleware, exchangeCallToken)
} }
api.Get("/unified", authMiddleware, websocket.New(unifiedGateway)) api.Get("/ws", authMiddleware, websocket.New(messageGateway))
} }
A.Use(favicon.New(favicon.Config{ A.Use(favicon.New(favicon.Config{

View File

@ -2,6 +2,7 @@ package services
import ( import (
"fmt" "fmt"
"git.solsynth.dev/hydrogen/messaging/pkg/database" "git.solsynth.dev/hydrogen/messaging/pkg/database"
"git.solsynth.dev/hydrogen/messaging/pkg/models" "git.solsynth.dev/hydrogen/messaging/pkg/models"
"github.com/samber/lo" "github.com/samber/lo"
@ -11,7 +12,7 @@ func GetChannel(id uint) (models.Channel, error) {
var channel models.Channel var channel models.Channel
if err := database.C.Where(models.Channel{ if err := database.C.Where(models.Channel{
BaseModel: models.BaseModel{ID: id}, BaseModel: models.BaseModel{ID: id},
}).First(&channel).Error; err != nil { }).Preload("Account").First(&channel).Error; err != nil {
return channel, err return channel, err
} }
@ -22,7 +23,7 @@ func GetChannelWithAlias(alias string) (models.Channel, error) {
var channel models.Channel var channel models.Channel
if err := database.C.Where(models.Channel{ if err := database.C.Where(models.Channel{
Alias: alias, Alias: alias,
}).First(&channel).Error; err != nil { }).Preload("Account").First(&channel).Error; err != nil {
return channel, err return channel, err
} }
@ -67,7 +68,7 @@ func GetAvailableChannel(id uint, user models.Account) (models.Channel, models.C
func ListChannel() ([]models.Channel, error) { func ListChannel() ([]models.Channel, error) {
var channels []models.Channel var channels []models.Channel
if err := database.C.Find(&channels).Error; err != nil { if err := database.C.Preload("Account").Find(&channels).Error; err != nil {
return channels, err return channels, err
} }