More Stuff
This commit is contained in:
@@ -6,9 +6,43 @@ A simple blog module for darkstorm-backend.
|
|||||||
|
|
||||||
### Author info
|
### Author info
|
||||||
|
|
||||||
|
#### Get author info
|
||||||
|
|
||||||
> GET /author/{authorID}
|
> GET /author/{authorID}
|
||||||
|
|
||||||
```json
|
```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
|
### 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
|
#### Latest blogs
|
||||||
|
|
||||||
> GET /blog?page=0
|
> GET /blog?page=0
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ type Author struct {
|
|||||||
PicURL string `json:"picurl" bson:"picurl"`
|
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"})
|
res := b.authCol.FindOne(context.Background(), bson.M{"_id": "caleb_gardner"})
|
||||||
if res.Err() != nil {
|
if res.Err() != nil {
|
||||||
log.Println("error getting about me:", res.Err())
|
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) {
|
func (b *BlogApp) GetAuthorInfo(w http.ResponseWriter, r *http.Request) {
|
||||||
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BlogApp) SetAuthorInfo(w http.ResponseWriter, r *http.Request) {
|
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)
|
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) {
|
func (b *BlogApp) GetLatestBlogs(page int64) ([]Blog, error) {
|
||||||
res, err := b.blogCol.Find(context.Background(), bson.M{}, options.Find().
|
res, err := b.blogCol.Find(context.Background(), bson.M{}, options.Find().
|
||||||
SetSort(bson.M{"createTime": 1}).
|
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"),
|
authCol: db.Collection("author"),
|
||||||
}
|
}
|
||||||
// setup mux
|
// 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("GET /blog/{blogID}", out.Blog)
|
||||||
|
|
||||||
|
mux.HandleFunc("POST /blog", out.CreateBlog)
|
||||||
//TODO
|
//TODO
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user