More work on portfolio
This commit is contained in:
+73
-49
@@ -12,10 +12,10 @@ A simple blog module for darkstorm-backend.
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
id: "authorID",
|
id: "authorID",
|
||||||
name: "author name",
|
name: "author name",
|
||||||
about: "about",
|
about: "about",
|
||||||
picurl: "picture URL"
|
picurl: "picture URL"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -27,9 +27,9 @@ Must have a auth token for a user with the `"blog": "admin"` permission.
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
name: "author name",
|
name: "author name",
|
||||||
about: "about",
|
about: "about",
|
||||||
picurl: "picture url"
|
picurl: "picture url"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -41,9 +41,9 @@ Must have a auth token for a user with the `"blog": "admin"` permission.
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
name: "author name",
|
name: "author name",
|
||||||
about: "about",
|
about: "about",
|
||||||
picurl: "picture URL"
|
picurl: "picture URL"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -57,13 +57,13 @@ Return:
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
id: "blogID",
|
id: "blogID",
|
||||||
createTime: 0, // creation time in Unix format
|
createTime: 0, // creation time in Unix format
|
||||||
updateTime: 0, // last update time in Unix format
|
updateTime: 0, // last update time in Unix format
|
||||||
author: "authorID",
|
author: "authorID",
|
||||||
favicon: "favicon url",
|
favicon: "favicon url",
|
||||||
title: "blog title",
|
title: "blog title",
|
||||||
blog: "blog", // blog will have been converted to HTML
|
blog: "blog", // blog will have been converted to HTML
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -77,9 +77,9 @@ Must have a auth token for a user with the `"blog": "admin"` permission.
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
favicon: "favicon url",
|
favicon: "favicon url",
|
||||||
title: "blog title",
|
title: "blog title",
|
||||||
blog: "blog", // blog will have been converted to HTML
|
blog: "blog", // blog will have been converted to HTML
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ Return:
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
id: "blogID"
|
id: "blogID"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -101,9 +101,9 @@ Must have a auth token for a user with the `"blog": "admin"` permission.
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
favicon: "new icon",
|
favicon: "new icon",
|
||||||
title: "new title",
|
title: "new title",
|
||||||
blog: "new blog content"
|
blog: "new blog content"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -117,19 +117,19 @@ Return:
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
num: 1, // Number of returned results, returns up to 5 results
|
num: 1, // Number of returned results, returns up to 5 results
|
||||||
blogs: [
|
blogs: [
|
||||||
{
|
{
|
||||||
id: "blogID",
|
id: "blogID",
|
||||||
createTime: 0, // creation time in Unix format
|
createTime: 0, // creation time in Unix format
|
||||||
updateTime: 0, // last update time in Unix format
|
updateTime: 0, // last update time in Unix format
|
||||||
author: "authorID",
|
author: "authorID",
|
||||||
favicon: "favicon url",
|
favicon: "favicon url",
|
||||||
title: "blog title",
|
title: "blog title",
|
||||||
blog: "blog", // blog will have been converted to HTML
|
blog: "blog", // blog will have been converted to HTML
|
||||||
}
|
}
|
||||||
...
|
...
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -143,17 +143,41 @@ Return:
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
num: 1, // Number of returned results, returns up to 50 results
|
num: 1, // Number of returned results, returns up to 50 results
|
||||||
blogList: [
|
blogList: [
|
||||||
{
|
{
|
||||||
id: "blogID",
|
id: "blogID",
|
||||||
createTime: 0, // Unix format
|
createTime: 0, // Unix format
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: "blogID",
|
id: "blogID",
|
||||||
createTime: 0, // Unix format
|
createTime: 0, // Unix format
|
||||||
},
|
},
|
||||||
...
|
...
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Portfolio
|
||||||
|
|
||||||
|
#### Get Projects
|
||||||
|
|
||||||
|
> GET: /portfolio?lang=go
|
||||||
|
|
||||||
|
Return:
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
title: "title",
|
||||||
|
repository: "https://github.com/CalebQ42/darkstorm-server",
|
||||||
|
description: "The backend that runs runs my website and APIs",
|
||||||
|
language: [
|
||||||
|
{
|
||||||
|
language: "go",
|
||||||
|
dates: "September 2021"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|||||||
+12
-8
@@ -9,18 +9,20 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type BlogApp struct {
|
type BlogApp struct {
|
||||||
back *backend.Backend
|
back *backend.Backend
|
||||||
blogCol *mongo.Collection
|
blogCol *mongo.Collection
|
||||||
authCol *mongo.Collection
|
authCol *mongo.Collection
|
||||||
conv *bbConvert.HTMLConverter
|
portfolioCol *mongo.Collection
|
||||||
|
conv *bbConvert.HTMLConverter
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBlogApp(b *backend.Backend, db *mongo.Database, mux *http.ServeMux) *BlogApp {
|
func NewBlogApp(b *backend.Backend, db *mongo.Database, mux *http.ServeMux) *BlogApp {
|
||||||
out := &BlogApp{
|
out := &BlogApp{
|
||||||
back: b,
|
back: b,
|
||||||
blogCol: db.Collection("blog"),
|
blogCol: db.Collection("blog"),
|
||||||
authCol: db.Collection("author"),
|
authCol: db.Collection("author"),
|
||||||
conv: &bbConvert.HTMLConverter{},
|
portfolioCol: db.Collection("portfolio"),
|
||||||
|
conv: &bbConvert.HTMLConverter{},
|
||||||
}
|
}
|
||||||
out.conv.ImplementDefaults()
|
out.conv.ImplementDefaults()
|
||||||
// setup mux
|
// setup mux
|
||||||
@@ -33,6 +35,8 @@ func NewBlogApp(b *backend.Backend, db *mongo.Database, mux *http.ServeMux) *Blo
|
|||||||
mux.HandleFunc("GET /author/{authorID}", out.reqAuthorInfo)
|
mux.HandleFunc("GET /author/{authorID}", out.reqAuthorInfo)
|
||||||
mux.HandleFunc("POST /author", out.addAuthorInfo)
|
mux.HandleFunc("POST /author", out.addAuthorInfo)
|
||||||
mux.HandleFunc("POST /author/{authorID}", out.updateAuthorInfo)
|
mux.HandleFunc("POST /author/{authorID}", out.updateAuthorInfo)
|
||||||
|
|
||||||
|
mux.HandleFunc("GET /portfolio", out.reqPortfolio)
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
package blog
|
package blog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
)
|
)
|
||||||
|
|
||||||
type project struct {
|
type PortfolioProject struct {
|
||||||
Title string `bson:"_id"`
|
Title string `bson:"_id"`
|
||||||
Repository string `bson:"respository"`
|
Repository string `bson:"repository"`
|
||||||
Description string `bson:"description"`
|
Description string `bson:"description"`
|
||||||
Languages []struct {
|
Languages []struct {
|
||||||
Language string `bson:"language"`
|
Language string `bson:"language"`
|
||||||
@@ -14,6 +17,20 @@ type project struct {
|
|||||||
} `bson:"language"`
|
} `bson:"language"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func portfolio(client *mongo.Client) {
|
func (b *BlogApp) Projects(languageFilter string) ([]PortfolioProject, error) {
|
||||||
|
filter := bson.M{}
|
||||||
|
if languageFilter != "" {
|
||||||
|
filter["language.language"] = languageFilter
|
||||||
|
}
|
||||||
|
res, err := b.portfolioCol.Find(context.Background(), filter)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var out []PortfolioProject
|
||||||
|
err = res.All(context.Background(), &out)
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BlogApp) reqPortfolio(w http.ResponseWriter, r *http.Request) {
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user