More work on portfolio

This commit is contained in:
Caleb Gardner
2024-07-20 07:01:18 -05:00
parent 4eb69bb343
commit f59a4207c4
3 changed files with 106 additions and 61 deletions
+73 -49
View File
@@ -12,10 +12,10 @@ A simple blog module for darkstorm-backend.
```json
{
id: "authorID",
name: "author name",
about: "about",
picurl: "picture URL"
id: "authorID",
name: "author name",
about: "about",
picurl: "picture URL"
}
```
@@ -27,9 +27,9 @@ Must have a auth token for a user with the `"blog": "admin"` permission.
```json
{
name: "author name",
about: "about",
picurl: "picture url"
name: "author name",
about: "about",
picurl: "picture url"
}
```
@@ -41,9 +41,9 @@ Must have a auth token for a user with the `"blog": "admin"` permission.
```json
{
name: "author name",
about: "about",
picurl: "picture URL"
name: "author name",
about: "about",
picurl: "picture URL"
}
```
@@ -57,13 +57,13 @@ Return:
```json
{
id: "blogID",
createTime: 0, // creation time in Unix format
updateTime: 0, // last update time in Unix format
author: "authorID",
favicon: "favicon url",
title: "blog title",
blog: "blog", // blog will have been converted to HTML
id: "blogID",
createTime: 0, // creation time in Unix format
updateTime: 0, // last update time in Unix format
author: "authorID",
favicon: "favicon url",
title: "blog title",
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
{
favicon: "favicon url",
title: "blog title",
blog: "blog", // blog will have been converted to HTML
favicon: "favicon url",
title: "blog title",
blog: "blog", // blog will have been converted to HTML
}
```
@@ -87,7 +87,7 @@ Return:
```json
{
id: "blogID"
id: "blogID"
}
```
@@ -101,9 +101,9 @@ Must have a auth token for a user with the `"blog": "admin"` permission.
```json
{
favicon: "new icon",
title: "new title",
blog: "new blog content"
favicon: "new icon",
title: "new title",
blog: "new blog content"
}
```
@@ -117,19 +117,19 @@ Return:
```json
{
num: 1, // Number of returned results, returns up to 5 results
blogs: [
{
id: "blogID",
createTime: 0, // creation time in Unix format
updateTime: 0, // last update time in Unix format
author: "authorID",
favicon: "favicon url",
title: "blog title",
blog: "blog", // blog will have been converted to HTML
}
...
]
num: 1, // Number of returned results, returns up to 5 results
blogs: [
{
id: "blogID",
createTime: 0, // creation time in Unix format
updateTime: 0, // last update time in Unix format
author: "authorID",
favicon: "favicon url",
title: "blog title",
blog: "blog", // blog will have been converted to HTML
}
...
]
}
```
@@ -143,17 +143,41 @@ Return:
```json
{
num: 1, // Number of returned results, returns up to 50 results
blogList: [
{
id: "blogID",
createTime: 0, // Unix format
},
{
id: "blogID",
createTime: 0, // Unix format
},
...
]
num: 1, // Number of returned results, returns up to 50 results
blogList: [
{
id: "blogID",
createTime: 0, // Unix format
},
{
id: "blogID",
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
View File
@@ -9,18 +9,20 @@ import (
)
type BlogApp struct {
back *backend.Backend
blogCol *mongo.Collection
authCol *mongo.Collection
conv *bbConvert.HTMLConverter
back *backend.Backend
blogCol *mongo.Collection
authCol *mongo.Collection
portfolioCol *mongo.Collection
conv *bbConvert.HTMLConverter
}
func NewBlogApp(b *backend.Backend, db *mongo.Database, mux *http.ServeMux) *BlogApp {
out := &BlogApp{
back: b,
blogCol: db.Collection("blog"),
authCol: db.Collection("author"),
conv: &bbConvert.HTMLConverter{},
back: b,
blogCol: db.Collection("blog"),
authCol: db.Collection("author"),
portfolioCol: db.Collection("portfolio"),
conv: &bbConvert.HTMLConverter{},
}
out.conv.ImplementDefaults()
// 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("POST /author", out.addAuthorInfo)
mux.HandleFunc("POST /author/{authorID}", out.updateAuthorInfo)
mux.HandleFunc("GET /portfolio", out.reqPortfolio)
return out
}
+21 -4
View File
@@ -1,12 +1,15 @@
package blog
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"`
Repository string `bson:"respository"`
Repository string `bson:"repository"`
Description string `bson:"description"`
Languages []struct {
Language string `bson:"language"`
@@ -14,6 +17,20 @@ type project struct {
} `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
}