More API progress
This time mainly helper functions for converting an account and associated types into their API representation
This commit is contained in:
parent
873f52d64f
commit
a653477e7f
8 changed files with 201 additions and 7 deletions
|
@ -13,7 +13,7 @@ type RemoteServer struct {
|
|||
IsSelf bool // Whether this server is yours truly
|
||||
}
|
||||
|
||||
func (s *Storage) FindRemoteServer(url string) (*RemoteServer, error) {
|
||||
func (s *Storage) FindRemoteServerByDomain(url string) (*RemoteServer, error) {
|
||||
server := RemoteServer{}
|
||||
err := s.db.Where("domain = ?").First(&server).Error
|
||||
switch err {
|
||||
|
@ -40,12 +40,25 @@ func (s *Storage) FindRemoteServerByDisplayName(displayName string) (*RemoteServ
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Storage) FindRemoteServerById(id uint) (*RemoteServer, error) {
|
||||
server := RemoteServer{}
|
||||
err := s.db.First(&server, id).Error
|
||||
switch err {
|
||||
case nil:
|
||||
return &server, nil
|
||||
case gorm.ErrRecordNotFound:
|
||||
return nil, ErrEntryNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Create a new remote server
|
||||
func (s *Storage) NewRemoteServer(
|
||||
url, displayName, icon string,
|
||||
serverType RemoteServerType,
|
||||
) (*RemoteServer, error) {
|
||||
_, err := s.FindRemoteServer(url)
|
||||
_, err := s.FindRemoteServerByDomain(url)
|
||||
switch err {
|
||||
case nil:
|
||||
return nil, ErrEntryAlreadyExists
|
||||
|
|
|
@ -39,8 +39,8 @@ type Account struct {
|
|||
Description string // The description of a user account
|
||||
Tags []string `gorm:"serializer:json"` // Hashtags
|
||||
IsBot bool // Whether to mark this account as a script controlled one
|
||||
Follows []string `gorm:"serializer:json"` // List of handles this account follows
|
||||
Followers []string `gorm:"serializer:json"` // List of handles that follow this account
|
||||
Follows []string `gorm:"serializer:json"` // List of account ids this account follows
|
||||
Followers []string `gorm:"serializer:json"` // List of account ids that follow this account
|
||||
Icon string // ID of a media file used as icon
|
||||
Background string // ID of a media file used as background image
|
||||
Banner string // ID of a media file used as banner
|
||||
|
|
|
@ -20,3 +20,34 @@ type UserInfoField struct {
|
|||
}
|
||||
|
||||
// TODO: Add functions to store, load, update and delete these
|
||||
|
||||
func (s *Storage) FindUserFieldById(id uint) (*UserInfoField, error) {
|
||||
entry := UserInfoField{}
|
||||
err := s.db.First(&entry, id).Error
|
||||
switch err {
|
||||
case nil:
|
||||
return &entry, nil
|
||||
case gorm.ErrRecordNotFound:
|
||||
return nil, ErrEntryNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Storage) FindMultipleUserFieldsById(ids []uint) ([]UserInfoField, error) {
|
||||
entries := []UserInfoField{}
|
||||
err := s.db.Where(ids).Find(&entries).Error
|
||||
switch err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
return nil, ErrEntryNotFound
|
||||
case nil:
|
||||
return entries, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Storage) AddNewUserField(name, value, belongsToId string) (*UserInfoField, error) {
|
||||
// TODO: Implement me
|
||||
panic("Not implemented")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue