MCPcopy
hub / github.com/writefreely/writefreely / CreateOwnedPost

Method CreateOwnedPost

database.go:641–673  ·  view source on GitHub ↗
(post *SubmittedPost, accessToken, collAlias, hostName string)

Source from the content-addressed store, hash-verified

639}
640
641func (db *datastore) CreateOwnedPost(post *SubmittedPost, accessToken, collAlias, hostName string) (*PublicPost, error) {
642 var userID, collID int64 = -1, -1
643 var coll *Collection
644 var err error
645 if accessToken != "" {
646 userID = db.GetUserID(accessToken)
647 if userID == -1 {
648 return nil, ErrBadAccessToken
649 }
650 if collAlias != "" {
651 coll, err = db.GetCollection(collAlias)
652 if err != nil {
653 return nil, err
654 }
655 coll.hostName = hostName
656 if coll.OwnerID != userID {
657 return nil, ErrForbiddenCollection
658 }
659 collID = coll.ID
660 }
661 }
662
663 rp := &PublicPost{}
664 rp.Post, err = db.CreatePost(userID, collID, post)
665 if err != nil {
666 return rp, err
667 }
668 if coll != nil {
669 coll.ForPublic()
670 rp.Collection = &CollectionObj{Collection: *coll}
671 }
672 return rp, nil
673}
674
675func (db *datastore) CreatePost(userID, collID int64, post *SubmittedPost) (*Post, error) {
676 idLen := postIDLen

Callers

nothing calls this directly

Calls 4

GetUserIDMethod · 0.95
GetCollectionMethod · 0.95
CreatePostMethod · 0.95
ForPublicMethod · 0.95

Tested by

no test coverage detected