From a4b3f8ce0664b1daf3c928556fe5fcfdf1d879a9 Mon Sep 17 00:00:00 2001
From: DilankaHer
Date: Mon, 17 Nov 2025 03:13:46 +0700
Subject: [PATCH] use json files to store data/ get css to work
---
css/index.css | 47 +++++++++++++++++--------
data/experience.json | 13 +++++++
internal/api/project_handler.go | 13 +++----
internal/store/experience_store.go | 16 ++++-----
internal/store/experience_store_json.go | 41 +++++++++++++++++++++
views/footer.html | 10 +++---
views/header.html | 4 +--
views/partials/experience-partial.html | 38 ++++++++++----------
views/partials/projects-partial.html | 4 +--
9 files changed, 131 insertions(+), 55 deletions(-)
create mode 100644 data/experience.json
create mode 100644 internal/store/experience_store_json.go
diff --git a/css/index.css b/css/index.css
index a7444e5..5719bda 100644
--- a/css/index.css
+++ b/css/index.css
@@ -1,26 +1,45 @@
.htmx-indicator {
- opacity:0;
- transition: opacity 500ms ease-in;
+ opacity: 0;
+ transition: opacity 500ms ease-in;
}
-.htmx-request .htmx-indicator{
- opacity:1
+.htmx-request .htmx-indicator {
+ opacity: 1;
}
-.htmx-request.htmx-indicator{
- opacity:1
+.htmx-request.htmx-indicator {
+ opacity: 1;
}
.contact.htmx-swapping {
- opacity:0;
- transition: opacity 500ms ease-in;
+ opacity: 0;
+ transition: opacity 500ms ease-in;
}
.nav-link {
- padding-bottom: 2px;
- border-bottom: 2px solid transparent;
- transition: all 0.2s;
+ padding-bottom: 2px;
+ border-bottom: 2px solid transparent;
+ transition: all 0.2s;
}
.nav-link.active {
- color: #2563eb; /* Tailwind blue-600 */
- border-bottom-color: #2563eb;
- font-weight: 600;
+ color: #2563eb;
+ border-bottom-color: #2563eb;
+ font-weight: 600;
+}
+
+.table-th {
+ text-align: center;
+ font-size: large;
+ font-weight: bold;
+ color: #4b5563;
+ padding: 0.7rem 0.7rem 1rem 1rem;
+ border: 1px solid #4b5563;
+ border-radius: 6px;
+}
+
+.table-td {
+ text-align: center;
+ font-size: medium;
+ font-weight: 300;
+ color: #4b5563;
+ border: 1px solid #4b5563;
+ border-radius: 6px;
}
diff --git a/data/experience.json b/data/experience.json
new file mode 100644
index 0000000..299f241
--- /dev/null
+++ b/data/experience.json
@@ -0,0 +1,13 @@
+[
+ {
+ "company": "AIS",
+ "position": "Frontend web developer",
+ "employeeType": "Vendor",
+ "tasks": [
+ "add new features to a web applicaton for AIS employees to process SIMs",
+ "develop functionality to recover sim process data during system failures"
+ ],
+ "tools": "Angular JS, MongoDB",
+ "years": 1
+ }
+]
diff --git a/internal/api/project_handler.go b/internal/api/project_handler.go
index 32f79f5..0807943 100644
--- a/internal/api/project_handler.go
+++ b/internal/api/project_handler.go
@@ -8,8 +8,8 @@ import (
)
type ApiHandler struct {
- Templates *template.Template
- ProjectStore *store.SQLiteProjectStore
+ Templates *template.Template
+ ProjectStore *store.SQLiteProjectStore
ExperienceStore *store.SQLiteExperienceStore
}
@@ -19,14 +19,14 @@ func (h *ApiHandler) Render(w http.ResponseWriter, tmpl string, data interface{}
return
}
}
-
+
func NewApiHandler(db *sql.DB) *ApiHandler {
tmpl := template.Must(template.New("").ParseGlob("views/*.html"))
template.Must(tmpl.ParseGlob("views/partials/*.html"))
return &ApiHandler{
- Templates: tmpl,
- ProjectStore: store.NewSQLiteProjectStore(db),
+ Templates: tmpl,
+ ProjectStore: store.NewSQLiteProjectStore(db),
ExperienceStore: store.NewSQLiteExperienceStore(db),
}
}
@@ -56,7 +56,8 @@ func (h *ApiHandler) ProjectsPage(w http.ResponseWriter, r *http.Request) {
func (h *ApiHandler) ExperiencePage(w http.ResponseWriter, r *http.Request) {
var hxRequest = r.Header.Get("HX-Request")
- experiences, err := h.ExperienceStore.GetAllExperiences()
+ // experiences, err := h.ExperienceStore.GetAllExperiences()
+ experiences, err := store.GetAllExperiencesJSON()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
diff --git a/internal/store/experience_store.go b/internal/store/experience_store.go
index d5d7280..dd50430 100644
--- a/internal/store/experience_store.go
+++ b/internal/store/experience_store.go
@@ -6,13 +6,13 @@ import (
)
type Experience struct {
- ID int `json:"id"`
- Company string `json:"company"`
- EmployeeType string `json:"employee_type"`
- Position string `json:"position"`
- Tasks []string `json:"tasks"`
- Tools string `json:"tools"`
- Years int `json:"years"`
+ ID int `json:"id"`
+ Company string `json:"company"`
+ EmployeeType string `json:"employee_type"`
+ Position string `json:"position"`
+ Tasks []string `json:"tasks"`
+ Tools string `json:"tools"`
+ Years int `json:"years"`
}
type SQLiteExperienceStore struct {
@@ -43,4 +43,4 @@ func (s *SQLiteExperienceStore) GetAllExperiences() ([]Experience, error) {
experience = append(experience, e)
}
return experience, nil
-}
\ No newline at end of file
+}
diff --git a/internal/store/experience_store_json.go b/internal/store/experience_store_json.go
new file mode 100644
index 0000000..f587ead
--- /dev/null
+++ b/internal/store/experience_store_json.go
@@ -0,0 +1,41 @@
+package store
+
+import (
+ "encoding/json"
+ "fmt"
+ "io"
+ "os"
+)
+
+type ExperienceJSON struct {
+ ID int `json:"id"`
+ Company string `json:"company"`
+ EmployeeType string `json:"employeeType"`
+ Position string `json:"position"`
+ Tasks []string `json:"tasks"`
+ Tools string `json:"tools"`
+ Years int `json:"years"`
+}
+
+func GetAllExperiencesJSON() ([]ExperienceJSON, error) {
+ jsonFile, err := os.Open("data/experience.json")
+ if err != nil {
+ fmt.Println("File not found; Error: ", err.Error())
+ }
+
+ defer jsonFile.Close()
+
+ byteValue, err := io.ReadAll(jsonFile)
+ if err != nil {
+ fmt.Println("Unable to read json file; Error: ", err.Error())
+ }
+
+ var experience []ExperienceJSON
+
+ err = json.Unmarshal(byteValue, &experience)
+ if err != nil {
+ fmt.Println("Unable to unmarshal; Error: ", err.Error())
+ }
+
+ return experience, nil
+}
diff --git a/views/footer.html b/views/footer.html
index 8b30d8c..260b6b0 100644
--- a/views/footer.html
+++ b/views/footer.html
@@ -6,23 +6,25 @@
Feel free to reach out via email or connect on my socials.
- © 2025 Your Name
+ © 2025 Dilanka Herath
{{ end }}
diff --git a/views/header.html b/views/header.html
index f6f332f..7fdd242 100644
--- a/views/header.html
+++ b/views/header.html
@@ -1,14 +1,14 @@
{{ block "header" .}}