diff --git a/assets/style.css b/assets/style.css index b0ee548..19c5121 100644 --- a/assets/style.css +++ b/assets/style.css @@ -3,12 +3,14 @@ body { margin: 0 auto; padding: 1em; font-family: Verdana; + background-color: azure; + color: midnightblue; } -section { - padding: 1em; - background-color: lightblue; -} +/*section {*/ +/* padding: 1em;*/ +/* background-color: lightblue;*/ +/*}*/ .flash { background-color: lightgreen; @@ -50,13 +52,13 @@ dd { margin-bottom: 1em; } -nav { - margin-bottom: 1em; -} +/*nav {*/ +/* margin-bottom: 1em;*/ +/*}*/ -h1, h2 { - margin-top: 0; -} +/*h1, h2 {*/ +/* !*margin-top: 0;*!*/ +/*}*/ .tools { list-style-position: inside; @@ -65,11 +67,12 @@ h1, h2 { @media (min-width: 650px) { .cols { - grid-template-columns: repeat(2, 1fr); - grid-gap: 1em; + grid-template-columns: 1fr 2fr; + grid-gap: 2em; } } +.radio { display: inline-block } .field { margin-bottom: 1rem; max-width: 500px; } .field > label { margin-bottom: .25rem; } .field > * { display: block; width: 100%; box-sizing: border-box; } \ No newline at end of file diff --git a/model/status.go b/model/status.go index 1929413..cd03a54 100644 --- a/model/status.go +++ b/model/status.go @@ -10,6 +10,7 @@ type Status struct { Id int64 User string Content string + Face string CreatedAt time.Time } diff --git a/storage/migration.go b/storage/migration.go index b3ac4a2..83842fb 100644 --- a/storage/migration.go +++ b/storage/migration.go @@ -7,7 +7,7 @@ import ( "strconv" ) -const schemaVersion = 7 +const schemaVersion = 8 func Migrate(db *sql.DB) { var currentVersion int diff --git a/storage/sql.go b/storage/sql.go index 2cd228a..93866b7 100644 --- a/storage/sql.go +++ b/storage/sql.go @@ -40,4 +40,6 @@ alter column about TYPE TEXT;`, add column picture varchar(500) not null DEFAULT '';`, "schema_version_7": `alter table users add column email varchar(500) not null DEFAULT '';`, + "schema_version_8": `alter table statuses + add column face varchar(1) not null DEFAULT '🙂';`, } diff --git a/storage/sql/schema_version_8.sql b/storage/sql/schema_version_8.sql new file mode 100644 index 0000000..d8245a0 --- /dev/null +++ b/storage/sql/schema_version_8.sql @@ -0,0 +1,2 @@ +alter table statuses + add column face varchar(1) not null DEFAULT '🙂'; \ No newline at end of file diff --git a/storage/status.go b/storage/status.go index b4f46ef..0858053 100644 --- a/storage/status.go +++ b/storage/status.go @@ -15,7 +15,7 @@ type statusQueryBuilder struct { } func (p statusQueryBuilder) build() string { - query := []string{`SELECT id, author, content, created_at from statuses`} + query := []string{`SELECT id, author, content, created_at, face from statuses`} if p.where != "" { query = append(query, `WHERE`, p.where) } @@ -31,7 +31,7 @@ func (p statusQueryBuilder) build() string { func (s *Storage) populateStatus(rows *sql.Rows) (model.Status, error) { var status model.Status - err := rows.Scan(&status.Id, &status.User, &status.Content, &status.CreatedAt) + err := rows.Scan(&status.Id, &status.User, &status.Content, &status.CreatedAt, &status.Face) if err != nil { return status, err } @@ -45,8 +45,8 @@ func (s *Storage) CreateStatus(status model.Status) error { if err != nil { return err } - if err := tx.QueryRowContext(ctx, `INSERT INTO statuses (author, content) VALUES ($1, $2) RETURNING id`, - status.User, status.Content).Scan(&statusId); err != nil { + if err := tx.QueryRowContext(ctx, `INSERT INTO statuses (author, content, face) VALUES ($1, $2, $3) RETURNING id`, + status.User, status.Content, status.Face).Scan(&statusId); err != nil { tx.Rollback() return err } @@ -121,7 +121,8 @@ func (s *Storage) LatestStatuses() ([]model.Status, error) { statuses.id, users.name, statuses.content, - statuses.created_at + statuses.created_at, + statuses.face from users inner join statuses @@ -143,11 +144,11 @@ func (s *Storage) LatestStatuses() ([]model.Status, error) { } func (s *Storage) UpdateStatus(status model.Status) error { - stmt, err := s.db.Prepare(`UPDATE statuses SET content = $1 WHERE id = $2 and author = $3;`) + stmt, err := s.db.Prepare(`UPDATE statuses SET content = $1, face = $2 WHERE id = $3 and author = $4;`) if err != nil { return err } - _, err = stmt.Exec(status.Content, status.Id, status.User) + _, err = stmt.Exec(status.Content, status.Face, status.Id, status.User) return err } @@ -186,7 +187,13 @@ func (s *Storage) DeleteStatus(id int64, author string) error { tx.Rollback() return err } + } else { + if _, err := tx.ExecContext(ctx, `UPDATE users set status_id=$1 where name=$2`, latestId, author); err != nil { + tx.Rollback() + return err + } } + err = tx.Commit() return err } diff --git a/web/handler/common.go b/web/handler/common.go index f42fec1..30be482 100644 --- a/web/handler/common.go +++ b/web/handler/common.go @@ -42,7 +42,7 @@ var TplCommonMap = map[string]string{ {{ define "head" }}{{ end }} `, "status": `{{ define "status" }} -
{{ .Content }}
{{ end }}`, } diff --git a/web/handler/form/status.go b/web/handler/form/status.go index 888574b..627f7dd 100644 --- a/web/handler/form/status.go +++ b/web/handler/form/status.go @@ -8,6 +8,7 @@ import ( type StatusForm struct { Id int64 Content string + Face string Error string } @@ -17,5 +18,6 @@ func NewStatusForm(r *http.Request) *StatusForm { return &StatusForm{ Id: id, Content: r.FormValue("content"), + Face: r.FormValue("face"), } } diff --git a/web/handler/html.go b/web/handler/html.go index 5a649b9..7f9cebf 100644 --- a/web/handler/html.go +++ b/web/handler/html.go @@ -63,6 +63,19 @@ var TplMap = map[string]string{