// Copyright (c) 2024 mStar // // Licensed under the EUPL, Version 1.2 // // You may not use this work except in compliance with the Licence. // You should have received a copy of the Licence along with this work. If not, see: // . // See the Licence for the specific language governing permissions and limitations under the Licence. // package storage import ( "errors" "github.com/MatejLach/astreams" "gorm.io/gorm" ) type Person struct { gorm.Model // Includes primary key (uid) as well as various time info // Public data Uid string ApID string Name string Instance string // url Local bool PublicKey string Url string ManuallyApprovesFollowers bool // Private data, set if local == true Mail *string // mail PwHash *string Inbox string // url Outbox string // url PrivateKey *string // private key } func (pdb *Person) IntoAPPerson() (*astreams.Person, error) { var actor astreams.Actor actor.PublicKey = &astreams.PublicKey{ ID: pdb.ApID, Owner: pdb.Url, PublicKeyPem: pdb.PublicKey, } actor.Inbox = &astreams.StringWithOrderedCollection{ URL: pdb.Inbox, } actor.Outbox = &astreams.StringWithOrderedCollection{ URL: pdb.Outbox, } actor.ManuallyApprovesFollowers = pdb.ManuallyApprovesFollowers actor.PreferredUsername = pdb.Name return nil, errors.New("unimplemented") } // Gets a person from the db by name func (s *Storage) GetPersonByName(name string) (*Person, error) { var nrFound int64 s.Db.Table("people").Where("name = ?", name).Count(&nrFound) if nrFound <= 0 { return nil, ErrNotFound } var p Person s.Db.Table("people").Where("name = ?", name).First(&p) return &p, nil }