From f59a4207c45af57a833f2e2b15afffdbc1e38f56 Mon Sep 17 00:00:00 2001 From: Caleb Gardner Date: Sat, 20 Jul 2024 07:01:18 -0500 Subject: [PATCH] More work on portfolio --- internal/blog/README.md | 122 ++++++++++++++++++++++--------------- internal/blog/main.go | 20 +++--- internal/blog/portfolio.go | 25 ++++++-- 3 files changed, 106 insertions(+), 61 deletions(-) diff --git a/internal/blog/README.md b/internal/blog/README.md index 8277f22..1d3182c 100644 --- a/internal/blog/README.md +++ b/internal/blog/README.md @@ -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" + } + ] + } +] +``` diff --git a/internal/blog/main.go b/internal/blog/main.go index 05966a0..3889514 100644 --- a/internal/blog/main.go +++ b/internal/blog/main.go @@ -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 } diff --git a/internal/blog/portfolio.go b/internal/blog/portfolio.go index af6b268..25d75ca 100644 --- a/internal/blog/portfolio.go +++ b/internal/blog/portfolio.go @@ -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 }