From fa9330a95919963c12b782ae6b2129a86c590ac2 Mon Sep 17 00:00:00 2001 From: Caleb Gardner Date: Mon, 17 Jun 2024 18:01:37 -0500 Subject: [PATCH] More Stuff --- internal/blog/README.md | 75 +++++++++++++++++++++++++++++++++++++++++ internal/blog/author.go | 4 +-- internal/blog/blog.go | 8 +++++ internal/blog/main.go | 5 ++- 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/internal/blog/README.md b/internal/blog/README.md index 9343b9e..28e1825 100644 --- a/internal/blog/README.md +++ b/internal/blog/README.md @@ -6,9 +6,43 @@ A simple blog module for darkstorm-backend. ### Author info +#### Get author info + > GET /author/{authorID} ```json +{ + id: "authorID", + about: "about", + picurl: "picture URL" +} +``` + +#### Update author info + +> POST /author/{authorID} + +Must have a auth token for a user with the `"blog": "admin"` permission. + +```json +{ + about: "about", + picurl: "picture url" +} +``` + +#### Add Author info + +> POST /author + +Must have a auth token for a user with the `"blog": "admin"` permission. + +```json +{ + id: "authorID", + about: "about", + picurl: "picture URL" +} ``` ### Blog @@ -31,6 +65,47 @@ Return: } ``` +#### Create blog + +Request: + +> POST /blog + +Must have a auth token for a user with the `"blog": "admin"` permission. + +```json +{ + author: "authorID", + favicon: "favicon url", + title: "blog title", + blog: "blog", // blog will have been converted to HTML +} +``` + +Return: + +```json +{ + id: "blogID" +} +``` + +#### Update blog + +Request: + +> POST /blog/{blogID} + +Must have a auth token for a user with the `"blog": "admin"` permission. + +```json +{ + favicon: "new icon", + title: "new title", + blog: "new blog content" +} +``` + #### Latest blogs > GET /blog?page=0 diff --git a/internal/blog/author.go b/internal/blog/author.go index a6f87ba..9aae509 100644 --- a/internal/blog/author.go +++ b/internal/blog/author.go @@ -16,7 +16,7 @@ type Author struct { PicURL string `json:"picurl" bson:"picurl"` } -func (b *BlogApp) AboutCaleb() (*Author, error) { +func (b *BlogApp) AboutMe() (*Author, error) { res := b.authCol.FindOne(context.Background(), bson.M{"_id": "caleb_gardner"}) if res.Err() != nil { log.Println("error getting about me:", res.Err()) @@ -35,7 +35,7 @@ func (b *BlogApp) AboutCaleb() (*Author, error) { } func (b *BlogApp) GetAuthorInfo(w http.ResponseWriter, r *http.Request) { - + //TODO } func (b *BlogApp) SetAuthorInfo(w http.ResponseWriter, r *http.Request) { diff --git a/internal/blog/blog.go b/internal/blog/blog.go index bc25db5..e4369cd 100644 --- a/internal/blog/blog.go +++ b/internal/blog/blog.go @@ -77,6 +77,14 @@ func (b *BlogApp) Blog(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(blog) } +func (b *BlogApp) CreateBlog(w http.ResponseWriter, r *http.Request) { + //TODO +} + +func (b *BlogApp) UpdateBlog(w http.ResponseWriter, r *http.Request) { + //TODO +} + func (b *BlogApp) GetLatestBlogs(page int64) ([]Blog, error) { res, err := b.blogCol.Find(context.Background(), bson.M{}, options.Find(). SetSort(bson.M{"createTime": 1}). diff --git a/internal/blog/main.go b/internal/blog/main.go index 1a02a27..68b5494 100644 --- a/internal/blog/main.go +++ b/internal/blog/main.go @@ -20,8 +20,11 @@ func NewBlogApp(b *backend.Backend, db *mongo.Database, mux *http.ServeMux) *Blo authCol: db.Collection("author"), } // setup mux - mux.HandleFunc("GET /blog/", out.LatestBlogs) + mux.HandleFunc("GET /blog", out.LatestBlogs) + mux.HandleFunc("GET /blog/list", out.BlogList) mux.HandleFunc("GET /blog/{blogID}", out.Blog) + + mux.HandleFunc("POST /blog", out.CreateBlog) //TODO return out }