yeet
This commit is contained in:
commit
0159e5e49f
7 changed files with 295 additions and 0 deletions
6
.aider.chat.history.md
Normal file
6
.aider.chat.history.md
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
# aider chat started at 2026-02-19 21:35:37
|
||||||
|
|
||||||
|
> Update git name with: git config user.name "Your Name"
|
||||||
|
> Update git email with: git config user.email "you@example.com"
|
||||||
|
> You can skip this check with --no-gitignore
|
||||||
BIN
birthdays.db
Normal file
BIN
birthdays.db
Normal file
Binary file not shown.
BIN
db/birthdays.db
Normal file
BIN
db/birthdays.db
Normal file
Binary file not shown.
5
go.mod
Normal file
5
go.mod
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
module main.go
|
||||||
|
|
||||||
|
go 1.25.7
|
||||||
|
|
||||||
|
require github.com/mattn/go-sqlite3 v1.14.34
|
||||||
2
go.sum
Normal file
2
go.sum
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.34 h1:3NtcvcUnFBPsuRcno8pUtupspG/GM+9nZ88zgJcp6Zk=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.34/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
143
main.go
Normal file
143
main.go
Normal file
|
|
@ -0,0 +1,143 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Birthday struct {
|
||||||
|
ID int `db:"id"`
|
||||||
|
Name string `db:"name"`
|
||||||
|
Birthday time.Time `db:"birthday"`
|
||||||
|
GiftPurchased bool `db:"gift_purchased"`
|
||||||
|
DaysUntil int `db:"days_until"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var db *sql.DB
|
||||||
|
|
||||||
|
func initDB() {
|
||||||
|
var err error
|
||||||
|
db, err = sql.Open("sqlite3", "./birthdays.db")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create table if it doesn't exist
|
||||||
|
createTableSQL := `
|
||||||
|
CREATE TABLE IF NOT EXISTS birthdays (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
birthday DATE NOT NULL,
|
||||||
|
gift_purchased BOOLEAN DEFAULT FALSE
|
||||||
|
);`
|
||||||
|
|
||||||
|
_, err = db.Exec(createTableSQL)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getBirthdays() ([]Birthday, error) {
|
||||||
|
rows, err := db.Query("SELECT id, name, birthday, gift_purchased FROM birthdays ORDER BY birthday")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
|
||||||
|
var birthdays []Birthday
|
||||||
|
for rows.Next() {
|
||||||
|
var b Birthday
|
||||||
|
err := rows.Scan(&b.ID, &b.Name, &b.Birthday, &b.GiftPurchased)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
birthdays = append(birthdays, b)
|
||||||
|
}
|
||||||
|
|
||||||
|
return birthdays, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func addBirthday(name string, birthday time.Time, giftPurchased bool) error {
|
||||||
|
_, err := db.Exec("INSERT INTO birthdays (name, birthday, gift_purchased) VALUES (?, ?, ?)", name, birthday, giftPurchased)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func homeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method == "POST" {
|
||||||
|
name := r.FormValue("name")
|
||||||
|
birthdayStr := r.FormValue("birthday")
|
||||||
|
giftPurchased := r.FormValue("giftPurchased") == "on"
|
||||||
|
|
||||||
|
// Parse the birthday date
|
||||||
|
birthday, err := time.Parse("2006-01-02", birthdayStr)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error parsing birthday: %v", err)
|
||||||
|
http.Error(w, "Invalid birthday date", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = addBirthday(name, birthday, giftPurchased)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error adding birthday: %v", err)
|
||||||
|
http.Error(w, "Error adding birthday", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redirect to avoid resubmission
|
||||||
|
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
birthdays, err := getBirthdays()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error getting birthdays: %v", err)
|
||||||
|
http.Error(w, "Error getting birthdays", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate days until each birthday
|
||||||
|
for i, b := range birthdays {
|
||||||
|
nextBirthday := time.Date(time.Now().Year(), b.Birthday.Month(), b.Birthday.Day(), 0, 0, 0, 0, time.Now().Location())
|
||||||
|
if nextBirthday.Before(time.Now()) {
|
||||||
|
nextBirthday = nextBirthday.AddDate(1, 0, 0)
|
||||||
|
}
|
||||||
|
daysUntil := int(nextBirthday.Sub(time.Now()).Hours() / 24)
|
||||||
|
birthdays[i].DaysUntil = daysUntil
|
||||||
|
}
|
||||||
|
|
||||||
|
data := struct {
|
||||||
|
UpcomingBirthdays []Birthday
|
||||||
|
}{
|
||||||
|
UpcomingBirthdays: birthdays,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse template from template directory
|
||||||
|
tmpl, err := template.ParseFiles("template/index.html")
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error parsing template: %v", err)
|
||||||
|
http.Error(w, "Template error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tmpl.Execute(w, data)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error executing template: %v", err)
|
||||||
|
http.Error(w, "Template execution error", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
initDB()
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
http.HandleFunc("/", homeHandler)
|
||||||
|
|
||||||
|
log.Println("Server starting on http://localhost:8080")
|
||||||
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
|
}
|
||||||
139
template/index.html
Normal file
139
template/index.html
Normal file
|
|
@ -0,0 +1,139 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Birthday Reminder</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
|
||||||
|
min-height: 100vh;
|
||||||
|
padding: 20px;
|
||||||
|
}
|
||||||
|
.card {
|
||||||
|
border-radius: 15px;
|
||||||
|
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
|
||||||
|
border: none;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
.card-header {
|
||||||
|
background: linear-gradient(to right, #4b6cb7, #182848);
|
||||||
|
color: white;
|
||||||
|
border-radius: 15px 15px 0 0 !important;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.birthday-card {
|
||||||
|
transition: transform 0.3s;
|
||||||
|
}
|
||||||
|
.birthday-card:hover {
|
||||||
|
transform: translateY(-5px);
|
||||||
|
}
|
||||||
|
.gift-icon {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
color: #ffc107;
|
||||||
|
}
|
||||||
|
.no-gift {
|
||||||
|
color: #6c757d;
|
||||||
|
}
|
||||||
|
.gifted {
|
||||||
|
color: #28a745;
|
||||||
|
}
|
||||||
|
.upcoming {
|
||||||
|
background-color: rgba(40, 167, 69, 0.1);
|
||||||
|
}
|
||||||
|
.today {
|
||||||
|
background-color: rgba(220, 53, 69, 0.1);
|
||||||
|
}
|
||||||
|
.form-control:focus {
|
||||||
|
border-color: #4b6cb7;
|
||||||
|
box-shadow: 0 0 0 0.2rem rgba(75, 108, 180, 0.25);
|
||||||
|
}
|
||||||
|
.modal-content {
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-8">
|
||||||
|
<div class="card mb-4">
|
||||||
|
<div class="card-header">
|
||||||
|
<i class="fas fa-birthday-cake me-2"></i>Upcoming Birthdays
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h5>Today</h5>
|
||||||
|
<ul class="list-group list-group-flush">
|
||||||
|
{{range .UpcomingBirthdays}}
|
||||||
|
{{if eq .DaysUntil 0}}
|
||||||
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||||
|
<span>{{.Name}}</span>
|
||||||
|
<span class="badge bg-danger rounded-pill">TODAY!</span>
|
||||||
|
</li>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h5>Coming Up</h5>
|
||||||
|
<ul class="list-group list-group-flush">
|
||||||
|
{{range .UpcomingBirthdays}}
|
||||||
|
{{if ne .DaysUntil 0}}
|
||||||
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||||
|
<span>{{.Name}}</span>
|
||||||
|
<span class="badge bg-primary rounded-pill">{{.DaysUntil}} days</span>
|
||||||
|
</li>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-4">
|
||||||
|
<div class="card mb-4">
|
||||||
|
<div class="card-header">
|
||||||
|
<i class="fas fa-plus-circle me-2"></i>Add New Birthday
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<form id="addBirthdayForm" method="post" action="/">
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="name" class="form-label">Name</label>
|
||||||
|
<input type="text" class="form-control" id="name" name="name" placeholder="Enter name" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="birthday" class="form-label">Birthday</label>
|
||||||
|
<input type="date" class="form-control" id="birthday" name="birthday" required>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3 form-check">
|
||||||
|
<input type="checkbox" class="form-check-input" id="giftPurchased" name="giftPurchased">
|
||||||
|
<label class="form-check-label" for="giftPurchased">Gift Purchased</label>
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-primary w-100">
|
||||||
|
<i class="fas fa-save me-2"></i>Add Birthday
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="footer">
|
||||||
|
<p>Birthday Reminder App © 2023</p>
|
||||||
|
</div>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
<script>
|
||||||
|
// Set today's date as minimum for date picker
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const today = new Date().toISOString().split('T')[0];
|
||||||
|
document.getElementById('birthday').min = today;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue