Skip to content

Commit

Permalink
feat(app): add landing page #6
Browse files Browse the repository at this point in the history
* fix(app): set services placeholder

* fix(query): path column is not exist

* chore(app): gitignore generated db

* feat(app): add ui
  • Loading branch information
kobamkode authored Aug 30, 2024
1 parent 4c3dd05 commit 0d1fff9
Show file tree
Hide file tree
Showing 24 changed files with 375 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.env
assets/css/dist.css
node_modules
gen/db/db.go
gen/db/models.go
gen/db/users.sql.go
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
run: gen build-css
all: sqlc-gen style-build run

run:
go run cmd/app/main.go

gen:
sqlc-gen:
sqlc generate

up: compose-up migrate-up
Expand All @@ -18,5 +20,5 @@ migrate-up:
migrate-down:
go run cmd/migrate/main.go -run=down

build-css:
style-build:
npx tailwindcss -i ./assets/css/src.css -o ./assets/css/dist.css
6 changes: 3 additions & 3 deletions cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func init() {
}

func main() {
pool := database.NewDBPool()
defer pool.Close()
db := database.NewDBPool()
defer db.Close()

server.Run(pool)
server.Run(db)
}
6 changes: 1 addition & 5 deletions gen/queries/users.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
-- name: CreateUser :exec
insert into users (
name, path
) values (
$1, $2
);
insert into users (name) values ($1);

-- name: ListUsers :many
select * from users;
21 changes: 21 additions & 0 deletions internal/handlers/admin/auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package admin

import (
"os"

"github.com/gofiber/fiber/v2"
)

func LoginPage(c *fiber.Ctx) error {
return c.Render("login", fiber.Map{
"AppName": os.Getenv("APP_NAME"),
"Title": "Login",
}, "layouts/auth")
}

// func RegisterPage(c *fiber.Ctx) error {
// return c.Render("register", fiber.Map{
// "AppName": os.Getenv("APP_NAME"),
// "Title": "Register",
// }, "layouts/auth")
// }
14 changes: 14 additions & 0 deletions internal/handlers/admin/dashboard.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package admin

import (
"os"

"github.com/gofiber/fiber/v2"
)

func DashboardPage(c *fiber.Ctx) error {
return c.Render("dashboard", fiber.Map{
"AppName": os.Getenv("APP_NAME"),
"Title": "Hello, Dashboard!",
}, "layouts/admin")
}
9 changes: 9 additions & 0 deletions internal/handlers/api/ping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package api

import "github.com/gofiber/fiber/v2"

func Ping(c *fiber.Ctx) error {
return c.Status(fiber.StatusOK).JSON(fiber.Map{
"message": "PONG",
})
}
14 changes: 14 additions & 0 deletions internal/handlers/web/home.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package web

import (
"os"

"github.com/gofiber/fiber/v2"
)

func HomePage(c *fiber.Ctx) error {
return c.Render("home", fiber.Map{
"AppName": os.Getenv("APP_NAME"),
"Title": "Hello, World!",
}, "layouts/web")
}
8 changes: 5 additions & 3 deletions internal/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package routes
import (
"github.com/gofiber/fiber/v2"
"github.com/jackc/pgx/v5/pgxpool"
"github.com/kobamkode/terigu/internal/admin"
"github.com/kobamkode/terigu/internal/api"
"github.com/kobamkode/terigu/internal/web"
"github.com/kobamkode/terigu/internal/handlers/admin"
"github.com/kobamkode/terigu/internal/handlers/api"
"github.com/kobamkode/terigu/internal/handlers/web"
)

type handler struct {
Expand All @@ -30,4 +30,6 @@ func (h *handler) API() {
func (h *handler) Admin() {
r := h.app.Group("/admin")
r.Get("/", admin.DashboardPage)
r.Get("/login", admin.LoginPage)
// r.Get("/register", admin.RegisterPage)
}
5 changes: 3 additions & 2 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ import (
"github.com/kobamkode/terigu/internal/routes"
)

func Run(pool *pgxpool.Pool) {
func Run(db *pgxpool.Pool) {
engine := html.New("./views", ".html")

app := fiber.New(fiber.Config{
Views: engine,
})
app.Static("/assets", "./assets")
app.Static("/admin/assets", "./assets")
app.Use(requestid.New())
app.Use(logger.New(logger.Config{
Format: "${time} ${locals:requestid} ${latency} ${status} - ${method} ${path}\n",
}))

run := routes.NewHandler(app, pool)
run := routes.NewHandler(app, db)
run.Web()
run.API()
run.Admin()
Expand Down
2 changes: 1 addition & 1 deletion internal/web/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ func HomePage(c *fiber.Ctx) error {
return c.Render("home", fiber.Map{
"AppName": os.Getenv("APP_NAME"),
"Title": "Hello, World!",
}, "layouts/main")
}, "layouts/web")
}
67 changes: 67 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"devDependencies": {
"@tailwindcss/forms": "^0.5.7",
"daisyui": "^4.12.10",
"tailwindcss": "^3.4.10"
}
}
5 changes: 4 additions & 1 deletion tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ module.exports = {
theme: {
extend: {},
},
plugins: [],
plugins: [
require('@tailwindcss/forms'),
require('daisyui'),
],
}

4 changes: 3 additions & 1 deletion views/home.html
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<h1 class="text-3xl font-bold underline">{{.Title}}</h1>
<div class="my-4">
{{template "partials/hero"}}
</div>
19 changes: 19 additions & 0 deletions views/layouts/admin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>

<head>
<title>{{.AppName}}</title>
<link href="assets/css/dist.css" rel="stylesheet">
<script src="assets/js/htmx.min.js"></script>
</head>

<body>
<div class="flex">
<div class="flex-none">
{{template "partials/drawer"}}
</div>
<div class="flex-1 bg-slate-200 p-4">{{embed}}</div>
</div>
</body>

</html>
2 changes: 1 addition & 1 deletion views/layouts/main.html → views/layouts/auth.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>

<body>
<div class="">
<div class="flex min-h-screen justify-center items-center bg-slate-200">
{{embed}}
</div>
</body>
Expand Down
18 changes: 18 additions & 0 deletions views/layouts/web.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>

<head>
<title>{{.AppName}}</title>
<link href="assets/css/dist.css" rel="stylesheet">
<script src="assets/js/htmx.min.js"></script>
</head>

<body class="bg-slate-200">
{{template "partials/navbar" .}}
<div class="container mx-auto min-h-screen">
{{embed}}
</div>
{{template "partials/footer"}}
</body>

</html>
37 changes: 37 additions & 0 deletions views/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div class="card bg-base-100 w-96 shadow-xl">
<div class="card-body items-center text-center">
<h2 class="card-title">{{.Title}}</h2>

<form hx-post="/admin/login" hx-target="#form-login" hx-swap="outerHTML">
<div class="form-control my-4">
<label class="input input-bordered flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor"
class="h-4 w-4 opacity-70">
<path
d="M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6ZM12.735 14c.618 0 1.093-.561.872-1.139a6.002 6.002 0 0 0-11.215 0c-.22.578.254 1.139.872 1.139h9.47Z" />
</svg>
<input type="text" name="username" class="grow border-none focus:outline-none"
placeholder="Username" />
</label>

</div>
<div class="form-control my-4">
<label class="input input-bordered flex items-center gap-2">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor"
class="h-4 w-4 opacity-70">
<path fill-rule="evenodd"
d="M14 6a4 4 0 0 1-4.899 3.899l-1.955 1.955a.5.5 0 0 1-.353.146H5v1.5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1-.5-.5v-2.293a.5.5 0 0 1 .146-.353l3.955-3.955A4 4 0 1 1 14 6Zm-4-2a.75.75 0 0 0 0 1.5.5.5 0 0 1 .5.5.75.75 0 0 0 1.5 0 2 2 0 0 0-2-2Z"
clip-rule="evenodd" />
</svg>
<input type="password" name="password"
class="grow border-none focus:outline-none" value="password" />
</label>

</div>

<div class="form-control my-4">
<button class="btn btn-block" type="submit">Login</button>
</div>
</form>
</div>
</div>
14 changes: 14 additions & 0 deletions views/partials/drawer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="drawer lg:drawer-open bg-slate-200">
<input id="my-drawer" type="checkbox" class="drawer-toggle" />
<div class="drawer-content">
<label for="my-drawer" class="btn btn-primary drawer-button lg:hidden">Open drawer</label>
</div>
<div class="drawer-side">
<label for="my-drawer" aria-label="close sidebar" class="drawer-overlay"></label>
<ul class="menu bg-base-200 text-base-content min-h-full w-40 p-4">
<!-- Sidebar content here -->
<li><a>Sidebar Item 1</a></li>
<li><a>Sidebar Item 2</a></li>
</ul>
</div>
</div>
Loading

0 comments on commit 0d1fff9

Please sign in to comment.