Changed ExtendedApp to use ServeMux directly

More work on portfolio stuff
Added technologies to portfolio projects
This commit is contained in:
Caleb Gardner
2024-07-27 02:38:31 -05:00
parent f59a4207c4
commit cb53b7b831
7 changed files with 48 additions and 27 deletions
+5 -1
View File
@@ -169,9 +169,13 @@ Return:
```json
[
{
title: "title",
title: "Darkstorm Server",
repository: "https://github.com/CalebQ42/darkstorm-server",
description: "The backend that runs runs my website and APIs",
technologies: [ // May be empty
"MongoDB",
"RESTful API"
],
language: [
{
language: "go",
+15 -13
View File
@@ -16,7 +16,7 @@ type BlogApp struct {
conv *bbConvert.HTMLConverter
}
func NewBlogApp(b *backend.Backend, db *mongo.Database, mux *http.ServeMux) *BlogApp {
func NewBlogApp(b *backend.Backend, db *mongo.Database) *BlogApp {
out := &BlogApp{
back: b,
blogCol: db.Collection("blog"),
@@ -25,18 +25,6 @@ func NewBlogApp(b *backend.Backend, db *mongo.Database, mux *http.ServeMux) *Blo
conv: &bbConvert.HTMLConverter{},
}
out.conv.ImplementDefaults()
// setup mux
mux.HandleFunc("GET /blog", out.reqLatestBlogs)
mux.HandleFunc("GET /blog/list", out.reqBlogList)
mux.HandleFunc("GET /blog/{blogID}", out.reqBlog)
mux.HandleFunc("POST /blog", out.createBlog)
mux.HandleFunc("POST /blog/{blogID}", out.updateBlog)
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
}
@@ -51,3 +39,17 @@ func (b *BlogApp) CountTable() backend.CountTable {
func (b *BlogApp) CrashTable() backend.CrashTable {
return nil
}
func (b *BlogApp) Extension(mux *http.ServeMux) {
mux.HandleFunc("GET /blog", b.reqLatestBlogs)
mux.HandleFunc("GET /blog/list", b.reqBlogList)
mux.HandleFunc("GET /blog/{blogID}", b.reqBlog)
mux.HandleFunc("POST /blog", b.createBlog)
mux.HandleFunc("POST /blog/{blogID}", b.updateBlog)
mux.HandleFunc("GET /author/{authorID}", b.reqAuthorInfo)
mux.HandleFunc("POST /author", b.addAuthorInfo)
mux.HandleFunc("POST /author/{authorID}", b.updateAuthorInfo)
mux.HandleFunc("GET /portfolio", b.reqPortfolio)
}
+16 -8
View File
@@ -2,19 +2,22 @@ package blog
import (
"context"
"encoding/json"
"net/http"
"github.com/CalebQ42/darkstorm-server/internal/backend"
"go.mongodb.org/mongo-driver/bson"
)
type PortfolioProject struct {
Title string `bson:"_id"`
Repository string `bson:"repository"`
Description string `bson:"description"`
Languages []struct {
Language string `bson:"language"`
Dates string `bson:"dates"`
} `bson:"language"`
Title string `json:"_id" bson:"_id"`
Repository string `json:"repository" bson:"repository"`
Description string `json:"description" bson:"description"`
Technologies []string `json:"technologies" bson:"technologies"`
Languages []struct {
Language string `json:"language" bson:"language"`
Dates string `json:"dates" bson:"dates"`
} `json:"language" bson:"language"`
}
func (b *BlogApp) Projects(languageFilter string) ([]PortfolioProject, error) {
@@ -32,5 +35,10 @@ func (b *BlogApp) Projects(languageFilter string) ([]PortfolioProject, error) {
}
func (b *BlogApp) reqPortfolio(w http.ResponseWriter, r *http.Request) {
//TODO
folio, err := b.Projects(r.URL.Query().Get("lang"))
if err != nil {
backend.ReturnError(w, http.StatusInternalServerError, "internal", "Server Error")
return
}
json.NewEncoder(w).Encode(folio)
}