socialnetworknews-api

git clone git://archive.git.mtrnord.blog/SocialNetworkNews/socialnetworknews-api.git
Log | Files | Refs | LICENSE

commit 912c9f995e547d1c4ad04473545d97cd1825a6e9
parent ae21d0a345a51255997d80322e683a11aac01be0
Author: MTRNord <mtrnord1@gmail.com>
Date:   Mon, 19 Feb 2018 08:30:26 +0100

Add ability to add a paper avatar

Diffstat:
Mapi/openapi.yaml | 2++
Mapi/webserver.go | 13+++++++++++++
2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/api/openapi.yaml b/api/openapi.yaml @@ -59,6 +59,8 @@ paths: properties: name: type: string + paper_image: + type: string description: type: string author: diff --git a/api/webserver.go b/api/webserver.go @@ -38,6 +38,7 @@ type Paper struct { Name string `json:"name,omitempty"` UUID string `json:"uuid,omitempty"` Description string `json:"description,omitempty"` + PaperImage string `json:"paper_image"` Author `json:",omitempty"` } @@ -100,6 +101,7 @@ func addPapers(data []Paper) ([]byte, error) { newName := p.Name newDesc := p.Description newAuthor := p.Author.UUID + newPIMG := p.PaperImage DBErr := papersDB.Update(func(txn *badger.Txn) error { nameErr := txn.Set([]byte(fmt.Sprintf("papers|paper|%s|name", newUUID)), []byte(newName)) @@ -112,6 +114,11 @@ func addPapers(data []Paper) ([]byte, error) { return descErr } + pIMGErr := txn.Set([]byte(fmt.Sprintf("papers|paper|%s|image", newUUID)), []byte(newPIMG)) + if pIMGErr != nil { + return pIMGErr + } + return txn.Set([]byte(fmt.Sprintf("papers|paper|%s|author", newUUID)), []byte(newAuthor)) }) if DBErr != nil { @@ -167,6 +174,12 @@ func getPapers() ([]byte, error) { return errors.WithMessage(QueryErr, fmt.Sprintf("%s%s|name", prefix, stringKeyEnd)) } + paperIMGResult, QueryErr := db.Get(txn, []byte(fmt.Sprintf("%s%s|image", prefix, stringKeyEnd))) + if QueryErr != nil { + return errors.WithMessage(QueryErr, fmt.Sprintf("%s%s|image", prefix, stringKeyEnd)) + } + + paper.PaperImage = fmt.Sprintf("%s", paperIMGResult) paper.Name = fmt.Sprintf("%s", nameResult) papers = append(papers, paper)