project page get from db
This commit is contained in:
parent
9514f0bff1
commit
6c9c7cc33e
@ -6,22 +6,22 @@ import (
|
||||
. "github.com/maragudk/gomponents/html"
|
||||
b "github.com/willoma/bulma-gomponents"
|
||||
e "github.com/willoma/gomplements"
|
||||
"portfolio/web/types"
|
||||
"portfolio/database/ent"
|
||||
)
|
||||
|
||||
func ProjectList(projects []types.Project) g.Node {
|
||||
return Div(Class("py-2 px-2"), g.Group(g.Map(projects, func(p types.Project) g.Node {
|
||||
func ProjectList(projects []*ent.Project) g.Node {
|
||||
return Div(Class("py-2 px-2"), g.Group(g.Map(projects, func(p *ent.Project) g.Node {
|
||||
return Project(p)
|
||||
})),
|
||||
)
|
||||
}
|
||||
|
||||
func Project(project types.Project) g.Node {
|
||||
func Project(project *ent.Project) g.Node {
|
||||
return b.Card(
|
||||
b.Media(
|
||||
b.MediaLeft(
|
||||
b.ImageImg(
|
||||
project.ImageUrl,
|
||||
project.ImageURL,
|
||||
e.Alt("project image"),
|
||||
b.ImgSq64,
|
||||
),
|
||||
@ -29,8 +29,8 @@ func Project(project types.Project) g.Node {
|
||||
b.Title(4, project.Name),
|
||||
b.Subtitle(
|
||||
6,
|
||||
A(Class("flex"), Href(project.Url), mdi.Github(), g.Text("Checkout repo")),
|
||||
A(Class("flex"), Href(project.DocUrl), mdi.Document(), g.Text("Docs"))),
|
||||
A(Class("flex"), Href(project.URL), mdi.Github(), g.Text("Checkout repo")),
|
||||
A(Class("flex"), Href(project.DocURL), mdi.Document(), g.Text("Docs"))),
|
||||
),
|
||||
b.Content(
|
||||
g.Raw(project.Description),
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
g "github.com/maragudk/gomponents"
|
||||
. "github.com/maragudk/gomponents/html"
|
||||
"net/http"
|
||||
"portfolio/database/query"
|
||||
"portfolio/web/components"
|
||||
"portfolio/web/services"
|
||||
)
|
||||
|
||||
func ProjectPageHandler(w http.ResponseWriter, r *http.Request) {
|
||||
@ -19,8 +20,13 @@ func ProjectPageHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func createProjectBody(w http.ResponseWriter, r *http.Request) g.Node {
|
||||
|
||||
projects, err := query.GetProjects(context.Background())
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return Body(
|
||||
components.ProjectList(services.ReadProjectsJson()),
|
||||
components.ProjectList(projects),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
@ -1,28 +0,0 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"portfolio/web/types"
|
||||
)
|
||||
|
||||
func ReadProjectsJson() []types.Project {
|
||||
// Open our jsonFile
|
||||
jsonFile, err := os.Open("web/assets/json/projects.json")
|
||||
// if we os.Open returns an error then handle it
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
defer jsonFile.Close()
|
||||
|
||||
byteValue, _ := io.ReadAll(jsonFile)
|
||||
|
||||
var projects types.Projects
|
||||
|
||||
json.Unmarshal(byteValue, &projects)
|
||||
|
||||
return projects.Projects
|
||||
}
|
||||
@ -1,13 +0,0 @@
|
||||
package types
|
||||
|
||||
type Projects struct {
|
||||
Projects []Project `json:"projects"`
|
||||
}
|
||||
|
||||
type Project struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Url string `json:"url"`
|
||||
ImageUrl string `json:"image_url"`
|
||||
DocUrl string `json:"doc_url"`
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user