Skip to content
Merged
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ YELLOW := \033[1;33m
# -------------------------------------------------------------------------------------------------------------------- #
# -------------------------------------------------------------------------------------------------------------------- #

ROOT_NETWORK := gocanto
ROOT_NETWORK := oullin_net
DATABASE := postgres
SOURCE := go_bindata
ROOT_PATH := $(shell pwd)
Expand Down
10 changes: 5 additions & 5 deletions boost/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (r *Router) PipelineFor(apiHandler http.ApiHandler) baseHttp.HandlerFunc {
}

func (r *Router) Profile() {
abstract := handler.MakeProfileHandler()
abstract := handler.MakeProfileHandler("./storage/fixture/profile.json")

resolver := r.PipelineFor(
abstract.Handle,
Expand All @@ -39,7 +39,7 @@ func (r *Router) Profile() {
}

func (r *Router) Experience() {
abstract := handler.MakeExperienceHandler()
abstract := handler.MakeExperienceHandler("./storage/fixture/experience.json")

resolver := r.PipelineFor(
abstract.Handle,
Expand All @@ -49,7 +49,7 @@ func (r *Router) Experience() {
}

func (r *Router) Projects() {
abstract := handler.MakeProjectsHandler()
abstract := handler.MakeProjectsHandler("./storage/fixture/projects.json")

resolver := r.PipelineFor(
abstract.Handle,
Expand All @@ -59,7 +59,7 @@ func (r *Router) Projects() {
}

func (r *Router) Social() {
abstract := handler.MakeSocialHandler()
abstract := handler.MakeSocialHandler("./storage/fixture/social.json")

resolver := r.PipelineFor(
abstract.Handle,
Expand All @@ -69,7 +69,7 @@ func (r *Router) Social() {
}

func (r *Router) Talks() {
abstract := handler.MakeTalks()
abstract := handler.MakeTalksHandler("./storage/fixture/talks.json")

resolver := r.PipelineFor(
abstract.Handle,
Expand Down
27 changes: 19 additions & 8 deletions handler/experience.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
package handler

import (
"github.com/oullin/handler/payload"
"github.com/oullin/pkg"
"github.com/oullin/pkg/http"
"log/slog"
baseHttp "net/http"
"os"
)

type ExperienceHandler struct {
content string
filePath string
}

func MakeExperienceHandler() ExperienceHandler {
func MakeExperienceHandler(filePath string) ExperienceHandler {
return ExperienceHandler{
content: "./storage/fixture/experience.json",
filePath: filePath,
}
}

func (h ExperienceHandler) Handle(w baseHttp.ResponseWriter, r *baseHttp.Request) *http.ApiError {
fixture, err := os.ReadFile(h.content)
data, err := pkg.ParseJsonFile[payload.ExperienceResponse](h.filePath)

if err != nil {
slog.Error("Error reading projects file", "error", err)
slog.Error("Error reading experience file", "error", err)

return http.InternalError("could not read experience data")
}

if err := writeJSON(fixture, w); err != nil {
return http.InternalError(err.Error())
resp := http.MakeResponseFrom(data.Version, w, r)

if resp.HasCache() {
resp.RespondWithNotModified()

return nil
}

if err := resp.RespondOk(data); err != nil {
slog.Error("Error marshaling JSON for experience response", "error", err)

return nil
}

return nil // A nil return indicates success.
Expand Down
20 changes: 20 additions & 0 deletions handler/payload/experience.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package payload

type ExperienceResponse struct {
Version string `json:"version"`
Data []ExperienceData `json:"data"`
}

type ExperienceData struct {
UUID string `json:"uuid"`
Company string `json:"company"`
EmploymentType string `json:"employment_type"`
LocationType string `json:"location_type"`
Position string `json:"position"`
StartDate string `json:"start_date"`
EndDate string `json:"end_date"`
Summary string `json:"summary"`
Country string `json:"country"`
City string `json:"city"`
Skills string `json:"skills"`
}
14 changes: 14 additions & 0 deletions handler/payload/profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package payload

type ProfileResponse struct {
Version string `json:"version"`
Data ProfileData `json:"data"`
}

type ProfileData struct {
Nickname string `json:"nickname"`
Handle string `json:"handle"`
Name string `json:"name"`
Email string `json:"email"`
Profession string `json:"profession"`
}
16 changes: 16 additions & 0 deletions handler/payload/projects.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package payload

type ProjectsResponse struct {
Version string `json:"version"`
Data []ProjectsData `json:"data"`
}

type ProjectsData struct {
UUID string `json:"uuid"`
Language string `json:"language"`
Title string `json:"title"`
Excerpt string `json:"excerpt"`
URL string `json:"url"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
14 changes: 14 additions & 0 deletions handler/payload/social.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package payload

type SocialResponse struct {
Version string `json:"version"`
Data []SocialData `json:"data"`
}

type SocialData struct {
UUID string `json:"uuid"`
Handle string `json:"handle"`
URL string `json:"url"`
Description string `json:"description"`
Name string `json:"name"`
}
17 changes: 17 additions & 0 deletions handler/payload/talks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package payload

type TalksResponse struct {
Version string `json:"version"`
Data []TalksData `json:"data"`
}

type TalksData struct {
UUID string `json:"uuid"`
Title string `json:"title"`
Subject string `json:"subject"`
Location string `json:"location"`
URL string `json:"url"`
Photo string `json:"photo"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
27 changes: 19 additions & 8 deletions handler/profile.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
package handler

import (
"github.com/oullin/handler/payload"
"github.com/oullin/pkg"
"github.com/oullin/pkg/http"
"log/slog"
baseHttp "net/http"
"os"
)

type ProfileHandler struct {
content string
filePath string
}

func MakeProfileHandler() ProfileHandler {
func MakeProfileHandler(filePath string) ProfileHandler {
return ProfileHandler{
content: "./storage/fixture/profile.json",
filePath: filePath,
}
}

func (h ProfileHandler) Handle(w baseHttp.ResponseWriter, r *baseHttp.Request) *http.ApiError {
fixture, err := os.ReadFile(h.content)
data, err := pkg.ParseJsonFile[payload.ProfileResponse](h.filePath)

if err != nil {
slog.Error("Error reading projects file", "error", err)
slog.Error("Error reading profile file", "error", err)

return http.InternalError("could not read profile data")
}

if err := writeJSON(fixture, w); err != nil {
return http.InternalError(err.Error())
resp := http.MakeResponseFrom(data.Version, w, r)

if resp.HasCache() {
resp.RespondWithNotModified()

return nil
}

if err := resp.RespondOk(data); err != nil {
slog.Error("Error marshaling JSON for profile response", "error", err)

return nil
}

return nil // A nil return indicates success.
Expand Down
25 changes: 18 additions & 7 deletions handler/projects.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
package handler

import (
"github.com/oullin/handler/payload"
"github.com/oullin/pkg"
"github.com/oullin/pkg/http"
"log/slog"
baseHttp "net/http"
"os"
)

type ProjectsHandler struct {
content string
filePath string
}

func MakeProjectsHandler() ProjectsHandler {
func MakeProjectsHandler(filePath string) ProjectsHandler {
return ProjectsHandler{
content: "./storage/fixture/projects.json",
filePath: filePath,
}
}

func (h ProjectsHandler) Handle(w baseHttp.ResponseWriter, r *baseHttp.Request) *http.ApiError {
fixture, err := os.ReadFile(h.content)
data, err := pkg.ParseJsonFile[payload.ProjectsResponse](h.filePath)

if err != nil {
slog.Error("Error reading projects file", "error", err)

return http.InternalError("could not read projects data")
}

if err := writeJSON(fixture, w); err != nil {
return http.InternalError(err.Error())
resp := http.MakeResponseFrom(data.Version, w, r)

if resp.HasCache() {
resp.RespondWithNotModified()

return nil
}

if err := resp.RespondOk(data); err != nil {
slog.Error("Error marshaling JSON for projects response", "error", err)

return nil
}

return nil // A nil return indicates success.
Expand Down
17 changes: 0 additions & 17 deletions handler/response.go

This file was deleted.

27 changes: 19 additions & 8 deletions handler/social.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,44 @@
package handler

import (
"github.com/oullin/handler/payload"
"github.com/oullin/pkg"
"github.com/oullin/pkg/http"
"log/slog"
baseHttp "net/http"
"os"
)

type SocialHandler struct {
content string
filePath string
}

func MakeSocialHandler() SocialHandler {
func MakeSocialHandler(filePath string) SocialHandler {
return SocialHandler{
content: "./storage/fixture/social.json",
filePath: filePath,
}
}

func (h SocialHandler) Handle(w baseHttp.ResponseWriter, r *baseHttp.Request) *http.ApiError {
fixture, err := os.ReadFile(h.content)
data, err := pkg.ParseJsonFile[payload.SocialResponse](h.filePath)

if err != nil {
slog.Error("Error reading projects file", "error", err)
slog.Error("Error reading social file", "error", err)

return http.InternalError("could not read social data")
}

if err := writeJSON(fixture, w); err != nil {
return http.InternalError(err.Error())
resp := http.MakeResponseFrom(data.Version, w, r)

if resp.HasCache() {
resp.RespondWithNotModified()

return nil
}

if err := resp.RespondOk(data); err != nil {
slog.Error("Error marshaling JSON for social response", "error", err)

return nil
}

return nil // A nil return indicates success.
Expand Down
Loading
Loading