Serverside stuff. Mostly shuffling things around

This commit is contained in:
Melody Becker 2024-10-26 11:42:51 +02:00
parent 90667d96c7
commit be70109c43
20 changed files with 513 additions and 71 deletions

View file

@ -1,30 +1,21 @@
package storage
import (
"time"
"gorm.io/gorm"
)
type RemoteServer struct {
ID string `gorm:"primarykey"` // ID is also server url
CreatedAt time.Time // When this entry was created
UpdatedAt time.Time // When this entry was last updated
// When this entry was deleted (for soft deletions)
// Soft delete means that this entry still exists in the db, but gorm won't include it anymore unless specifically told to
// If not null, this entry is marked as deleted
DeletedAt gorm.DeletedAt `gorm:"index"`
gorm.Model
ServerType RemoteServerType // What software the server is running. Useful for formatting
Domain string // `gorm:"primaryKey"` // Domain the server exists under. Additional primary key
Name string // What the server wants to be known as (usually same as url)
Icon string // ID of a media file
IsSelf bool // Whether this server is yours truly
}
func (s *Storage) FindRemoteServer(url string) (*RemoteServer, error) {
server := RemoteServer{
ID: url,
}
err := s.db.First(&server).Error
server := RemoteServer{}
err := s.db.Where("domain = ?").First(&server).Error
switch err {
case nil:
return &server, nil
@ -63,7 +54,7 @@ func (s *Storage) NewRemoteServer(
return nil, err
}
server := RemoteServer{
ID: url,
Domain: url,
Name: displayName,
Icon: icon,
ServerType: serverType,