Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ AUTO_MIGRATE=true
# Mandatory

DATABASE_URL=db.sqlite
JWT_SECRET=secrettt
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ toolchain go1.24.1

require (
github.com/a-h/templ v0.3.857
github.com/gofiber/fiber/v2 v2.49.0
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/gofiber/fiber/v2 v2.52.6
github.com/golang-migrate/migrate/v4 v4.16.2
github.com/google/uuid v1.3.1
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
github.com/spf13/cobra v1.7.0
golang.org/x/crypto v0.32.0
Expand All @@ -24,17 +23,17 @@ require (
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.48.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/mod v0.20.0 // indirect
Expand Down
22 changes: 10 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/gofiber/fiber/v2 v2.49.0 h1:xBVG2c66GDcWfww56xHvMn52Q0XX7UrSvjj6MD8/5EE=
github.com/gofiber/fiber/v2 v2.49.0/go.mod h1:oxpt7wQaEYgdDmq7nMxCGhilYicBLFnZ+jQSJcQDlSE=
github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE=
github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/gofiber/fiber/v2 v2.52.6 h1:Rfp+ILPiYSvvVuIPvxrBns+HJp8qGLDnLJawAu27XVI=
github.com/gofiber/fiber/v2 v2.52.6/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
github.com/golang-migrate/migrate/v4 v4.16.2 h1:8coYbMKUyInrFk1lfGfRovTLAW7PhWp8qQDT2iKfuoA=
github.com/golang-migrate/migrate/v4 v4.16.2/go.mod h1:pfcJX4nPHaVdc5nmdCikFBWtm+UBpiZjRNNsyBbp0/o=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand All @@ -30,17 +28,17 @@ github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/lib/pq v1.10.2 h1:AqzbZs4ZoCBp+GtejcpCpcxM3zlSMx29dXbUSeVtJb8=
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
Expand All @@ -59,8 +57,8 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.48.0 h1:oJWvHb9BIZToTQS3MuQ2R3bJZiNSa2KiNdeI8A+79Tc=
github.com/valyala/fasthttp v1.48.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA=
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
Expand Down
77 changes: 4 additions & 73 deletions internal/components/design.templ
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ templ ErrorPage() {
}
}

templ authenticatedPage(title string, breadcrumb, description string) {
templ headedPage(title string, breadcrumb, description string) {
@rawPage(title) {
<div class="px-4 sm:px-8 max-w-5xl m-auto">
<div class="flex flex-col">
<div class="flex flex-row justify-between items-center">
<a href="/" class="text-2xl">{breadcrumb}</a>
<a href="/auth/logout" class="bg-slate-800 border border-slate-600 rounded px-2">Logout</a>
<a href="/" class="bg-slate-800 border border-slate-600 rounded px-2">???</a>
</div>
if description != "" {
<p class="mt-2 text-xs mb-4 text-gray-500">{description}</p>
Expand All @@ -74,79 +74,10 @@ templ authenticatedPage(title string, breadcrumb, description string) {
}
}

templ PostLogoutPage() {
@rawPage("Logout") {
<div class="px-4 sm:px-8 max-w-5xl m-auto">
<div class="flex flex-col">
<div class="flex flex-row justify-between items-center">
<a href="/" class="text-2xl">Home</a>
<div>
<a href="/auth/login" class="bg-slate-800 border border-slate-600 rounded px-2">Login</a>
<a href="/auth/register" class="bg-slate-800 border border-slate-600 rounded px-2">Register</a>
</div>
</div>
<p class="mt-2 text-xs mb-4 text-gray-500">You need to login to proceed</p>
</div>
</div>
}
}

templ LoginPage() {
@rawPage("Login") {
<div class="px-4 h-screen sm:px-8 max-w-5xl m-auto">
<div class="h-full flex flex-col">
<div class="flex flex-row justify-between items-center">
<a href="/" class="text-2xl">Login</a>
<div>
<a href="/auth/register" class="bg-slate-800 border border-slate-600 rounded px-2">Register</a>
</div>
</div>
<form hx-post="/auth/login" class="mx-auto h-full flex flex-col justify-center">
<div class="relative z-0 w-full mb-5 group">
<input name="username" id="username" class="block py-2.5 px-0 w-full text-sm text-gray-900 bg-transparent border-0 border-b-2 border-gray-300 appearance-none dark:text-white dark:border-gray-600 dark:focus:border-blue-500 focus:outline-none focus:ring-0 focus:border-blue-600 peer" placeholder=" " required />
<label for="username" class="peer-focus:font-medium absolute text-sm text-gray-500 dark:text-gray-400 duration-300 transform -translate-y-6 scale-75 top-3 -z-10 origin-[0] peer-focus:start-0 rtl:peer-focus:translate-x-1/4 rtl:peer-focus:left-auto peer-focus:text-blue-600 peer-focus:dark:text-blue-500 peer-placeholder-shown:scale-100 peer-placeholder-shown:translate-y-0 peer-focus:scale-75 peer-focus:-translate-y-6">Username</label>
</div>
<div class="relative z-0 w-full mb-5 group">
<input type="password" name="password" id="password" class="block py-2.5 px-0 w-full text-sm text-gray-900 bg-transparent border-0 border-b-2 border-gray-300 appearance-none dark:text-white dark:border-gray-600 dark:focus:border-blue-500 focus:outline-none focus:ring-0 focus:border-blue-600 peer" placeholder=" " required />
<label for="password" class="peer-focus:font-medium absolute text-sm text-gray-500 dark:text-gray-400 duration-300 transform -translate-y-6 scale-75 top-3 -z-10 origin-[0] peer-focus:start-0 rtl:peer-focus:translate-x-1/4 peer-focus:text-blue-600 peer-focus:dark:text-blue-500 peer-placeholder-shown:scale-100 peer-placeholder-shown:translate-y-0 peer-focus:scale-75 peer-focus:-translate-y-6">Password</label>
</div>
<button type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Submit</button>
</form>
</div>
</div>
}
}

templ RegisterPage() {
@rawPage("Register") {
<div class="px-4 h-screen sm:px-8 max-w-5xl m-auto">
<div class="h-full flex flex-col">
<div class="flex flex-row justify-between items-center">
<a href="/" class="text-2xl">Register</a>
<div>
<a href="/auth/login" class="bg-slate-800 border border-slate-600 rounded px-2">Login</a>
</div>
</div>
<form hx-post="/auth/register" class="mx-auto h-full flex flex-col justify-center">
<div class="relative z-0 w-full mb-5 group">
<input name="username" id="username" class="block py-2.5 px-0 w-full text-sm text-gray-900 bg-transparent border-0 border-b-2 border-gray-300 appearance-none dark:text-white dark:border-gray-600 dark:focus:border-blue-500 focus:outline-none focus:ring-0 focus:border-blue-600 peer" placeholder=" " required />
<label for="username" class="peer-focus:font-medium absolute text-sm text-gray-500 dark:text-gray-400 duration-300 transform -translate-y-6 scale-75 top-3 -z-10 origin-[0] peer-focus:start-0 rtl:peer-focus:translate-x-1/4 rtl:peer-focus:left-auto peer-focus:text-blue-600 peer-focus:dark:text-blue-500 peer-placeholder-shown:scale-100 peer-placeholder-shown:translate-y-0 peer-focus:scale-75 peer-focus:-translate-y-6">Username</label>
</div>
<div class="relative z-0 w-full mb-5 group">
<input type="password" name="password" id="password" class="block py-2.5 px-0 w-full text-sm text-gray-900 bg-transparent border-0 border-b-2 border-gray-300 appearance-none dark:text-white dark:border-gray-600 dark:focus:border-blue-500 focus:outline-none focus:ring-0 focus:border-blue-600 peer" placeholder=" " required />
<label for="password" class="peer-focus:font-medium absolute text-sm text-gray-500 dark:text-gray-400 duration-300 transform -translate-y-6 scale-75 top-3 -z-10 origin-[0] peer-focus:start-0 rtl:peer-focus:translate-x-1/4 peer-focus:text-blue-600 peer-focus:dark:text-blue-500 peer-placeholder-shown:scale-100 peer-placeholder-shown:translate-y-0 peer-focus:scale-75 peer-focus:-translate-y-6">Password</label>
</div>
<button type="submit" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Submit</button>
</form>
</div>
</div>
}
}

// Tasks Views

templ TaskListPage(tasks []models.Task) {
@authenticatedPage("Tasks List", "Tasks", "Open Tasks To Do") {
@headedPage("Tasks List", "Tasks", "Open Tasks To Do") {
<div>
<ul id="wrapper" class="border border-slate-600 rounded overflow-hidden shadow-md">
if len(tasks) > 0 {
Expand All @@ -169,7 +100,7 @@ templ TaskListPage(tasks []models.Task) {
}

templ TaskEditPage(task models.Task) {
@authenticatedPage("Task Editor", fmt.Sprintf("Tasks > %s", task.Title), "Edit this task") {
@headedPage("Task Editor", fmt.Sprintf("Tasks > %s", task.Title), "Edit this task") {
<div>
<div class="flex flex-col">
<label for="title" class="text-xs mb-1">Title</label>
Expand Down
6 changes: 0 additions & 6 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type ServerConfigs struct {
ServerAddress string

DataBaseURL string
JwtSecret string
}

func GetServerConfigs() ServerConfigs {
Expand All @@ -24,11 +23,6 @@ func GetServerConfigs() ServerConfigs {
panic("Missing DATABASE_URL")
}

config.JwtSecret = os.Getenv("JWT_SECRET")
if config.JwtSecret == "" {
panic("Missing JWT_SECRET")
}

// optional - with defaults

envAutoMigrate := os.Getenv("AUTO_MIGRATE")
Expand Down
5 changes: 0 additions & 5 deletions internal/controllers/controllers.go

This file was deleted.

21 changes: 8 additions & 13 deletions internal/controllers/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,20 @@ func NewTaskController(dbRepo database.Database) *TaskController {
}
}

func (tc *TaskController) CreateTask(ownerId string) (models.Task, error) {
func (tc *TaskController) CreateTask() (models.Task, error) {
task := models.Task{
Id: models.GenerateId(),
Title: "New Task",
Description: "New Task Description",
OwnerId: ownerId,
}
return task, tc.DbRepo.CreateTask(task)
}

func (tc *TaskController) ListTasks(ownerId string) ([]models.Task, error) {
return tc.DbRepo.ListTasksByOwner(ownerId)
func (tc *TaskController) ListTasks() ([]models.Task, error) {
return tc.DbRepo.ListTasks()
}

func (tc *TaskController) RetrieveTask(ownerId, taskId string) (models.Task, error) {
func (tc *TaskController) RetrieveTask(taskId string) (models.Task, error) {
task, err := tc.DbRepo.RetrieveTaskById(taskId)
if err != nil {
if err == sql.ErrNoRows {
Expand All @@ -42,15 +41,11 @@ func (tc *TaskController) RetrieveTask(ownerId, taskId string) (models.Task, err
return models.EmptyTask, err
}

if task.OwnerId != ownerId {
return models.EmptyTask, fiber.ErrNotFound
}

return task, nil
}

func (tc *TaskController) DeleteTask(ownerId, taskId string) error {
_, err := tc.RetrieveTask(ownerId, taskId)
func (tc *TaskController) DeleteTask(taskId string) error {
_, err := tc.RetrieveTask(taskId)
if err != nil {
return err
}
Expand All @@ -63,8 +58,8 @@ type TaskChange struct {
Description string `json:"description"`
}

func (tc *TaskController) UpdateTask(ownerId, taskId string, changes TaskChange) error {
task, err := tc.RetrieveTask(ownerId, taskId)
func (tc *TaskController) UpdateTask(taskId string, changes TaskChange) error {
task, err := tc.RetrieveTask(taskId)
if err != nil {
return err
}
Expand Down
89 changes: 0 additions & 89 deletions internal/controllers/users.go

This file was deleted.

1 change: 0 additions & 1 deletion internal/embeded/migrations/01_initial.down.sql

This file was deleted.

8 changes: 0 additions & 8 deletions internal/embeded/migrations/01_initial.up.sql

This file was deleted.

8 changes: 8 additions & 0 deletions internal/embeded/migrations/01_tasks.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- SQLITE

CREATE TABLE tasks (
id UUID PRIMARY KEY,
title TEXT NOT NULL,
description TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);
Loading