Added resume site

This commit is contained in:
Caleb Gardner
2023-04-25 11:05:35 -05:00
parent a0f63aaee8
commit 6453be599d
+65
View File
@@ -38,6 +38,8 @@ func (d *DarkstormTech) Extension(req *stupid.Request) bool {
} }
if req.Path[1] == "files" { if req.Path[1] == "files" {
return d.handleFiles(req) return d.handleFiles(req)
} else if req.Path[1] == "resume" {
return d.handleResume(req)
} }
res := d.DB.Collection("pages").FindOne(context.TODO(), bson.M{"_id": strings.Join(req.Path[1:], "/")}, options.FindOne().SetProjection(bson.M{"_id": 0, "content": 1})) res := d.DB.Collection("pages").FindOne(context.TODO(), bson.M{"_id": strings.Join(req.Path[1:], "/")}, options.FindOne().SetProjection(bson.M{"_id": 0, "content": 1}))
if res.Err() == mongo.ErrNoDocuments { if res.Err() == mongo.ErrNoDocuments {
@@ -93,3 +95,66 @@ func (d *DarkstormTech) handleFiles(req *stupid.Request) bool {
} }
return true return true
} }
type project struct {
ID string `bson:"_id"`
Repository string
Description string
Language []struct {
Language string
Dates string
}
}
func selectedString(selected bool) string {
if !selected {
return ""
}
return " selected"
}
func (d *DarkstormTech) handleResume(req *stupid.Request) bool {
filter := bson.M{}
lang := ""
if l, ok := req.Query["lang"]; ok && len(l) == 1 && l[0] != "" {
lang = l[0]
filter = bson.M{"language.language": l[0]}
}
projects := make([]project, 0)
res, err := d.DB.Collection("projects").Find(context.TODO(), filter)
if err != nil {
log.Println("Error while getting projects:", err)
req.Resp.WriteHeader(http.StatusInternalServerError)
return true
}
err = res.All(context.TODO(), &projects)
if err != nil {
log.Println("Error while decoding projects:", err)
req.Resp.WriteHeader(http.StatusInternalServerError)
return true
}
out := "<p>Language Filter: <select name='langSelect' id='langSelect'>"
out += "<option value=''" + selectedString(lang == "") + ">All</option>"
out += "<option value='Go'" + selectedString(lang == "Go") + ">Go</option>"
out += "<option value='Dart'" + selectedString(lang == "Dart") + ">Dart (Flutter)</option>"
out += "<option value='Java'" + selectedString(lang == "Java") + ">Java</option>"
out += "</select></p>"
for _, p := range projects {
out += "<h2 style='margin-bottom:10px'>" + p.ID + "</h2>"
out += "<p><a href='" + p.Repository + "'>" + p.Repository + "</a></p>"
for _, l := range p.Language {
lang := l.Language
if lang == "Dart" {
lang = "Dart (Flutter)"
}
out += "<p><b>" + lang + "</b>: " + l.Dates + "</p>"
}
out += "<p>" + p.Description + "</p>"
}
_, err = req.Resp.Write([]byte(out))
if err != nil {
log.Println("Error while writing output:", err)
req.Resp.WriteHeader(http.StatusInternalServerError)
}
return true
}