More Stuff
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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}).
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user