Skip to content

Commit

Permalink
Implemented missing template to ask timezone in results, and general …
Browse files Browse the repository at this point in the history
…fixes
  • Loading branch information
eapl-gemugami committed Dec 1, 2022
1 parent ecf76ae commit 2744e8a
Show file tree
Hide file tree
Showing 17 changed files with 376 additions and 235 deletions.
File renamed without changes.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ https://github.com/cosmtrek/air
go fmt ./...
```

## Important links
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-go-web-application-using-nginx-on-ubuntu-18-04
https://lets-go.alexedwards.net/sample/02.07-html-templating-and-inheritance.html
28 changes: 14 additions & 14 deletions models/event_user.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package models

import (
"gorm.io/gorm"
)

type EventUser struct {
gorm.Model

EventID int
Event Event

Name string `gorm:"unique"`
}
package models

import (
"gorm.io/gorm"
)

type EventUser struct {
gorm.Model

EventID int
Event Event

Name string `gorm:"unique"`
}
6 changes: 3 additions & 3 deletions models/event_vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package models

type EventVote struct {
EventID int
Event Event
Event Event

EventUserID int
EventUser EventUser
EventUser EventUser

TimeOption int
TimeOption int
TimeAvailability int
}
62 changes: 3 additions & 59 deletions route.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ func init() {
r.Get("/e/{public_code}/{timezone}", views.EventGetDataRange)
r.Post("/e/{public_code}/{timezone}", views.EventPostDataRange)

// r = Results (of voting)
//r.Get("/r/{public_code}", views.EventGetResultsAskTimezone)
// r = Results (of survey)
r.Get("/r/{public_code}", views.EventGetResultsAskTimezone)
r.Post("/r/{public_code}", views.EventPostResultsAskTimezone)
r.Get("/r/{public_code}/{timezone}", views.EventGetResults)

// a = Admin shortcut
Expand All @@ -43,60 +44,3 @@ func init() {

Serve = r
}

/*
r.Get("/api/widgets", apiGetWidgets)
r.Post("/api/widgets", apiCreateWidget)
r.Post("/api/widgets/{slug}", apiUpdateWidget)
r.Post("/api/widgets/{slug}/parts", apiCreateWidgetPart)
r.Post("/api/widgets/{slug}/parts/{id:[0-9]+}/update", apiUpdateWidgetPart)
r.Post("/api/widgets/{slug}/parts/{id:[0-9]+}/delete", apiDeleteWidgetPart)
r.Get("/{slug}", widgetGet)
r.Get("/{slug}/admin", widgetAdmin)
r.Post("/{slug}/image", widgetImage)
func apiGetWidgets(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "apiGetWidgets\n")
}
func apiCreateWidget(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "apiCreateWidget\n")
}
func apiUpdateWidget(w http.ResponseWriter, r *http.Request) {
slug := chi.URLParam(r, "slug")
fmt.Fprintf(w, "apiUpdateWidget %s\n", slug)
}
func apiCreateWidgetPart(w http.ResponseWriter, r *http.Request) {
slug := chi.URLParam(r, "slug")
fmt.Fprintf(w, "apiCreateWidgetPart %s\n", slug)
}
func apiUpdateWidgetPart(w http.ResponseWriter, r *http.Request) {
slug := chi.URLParam(r, "slug")
id, _ := strconv.Atoi(chi.URLParam(r, "id"))
fmt.Fprintf(w, "apiUpdateWidgetPart %s %d\n", slug, id)
}
func apiDeleteWidgetPart(w http.ResponseWriter, r *http.Request) {
slug := chi.URLParam(r, "slug")
id, _ := strconv.Atoi(chi.URLParam(r, "id"))
fmt.Fprintf(w, "apiDeleteWidgetPart %s %d\n", slug, id)
}
func widgetGet(w http.ResponseWriter, r *http.Request) {
slug := chi.URLParam(r, "slug")
fmt.Fprintf(w, "widget %s\n", slug)
}
func widgetAdmin(w http.ResponseWriter, r *http.Request) {
slug := chi.URLParam(r, "slug")
fmt.Fprintf(w, "widgetAdmin %s\n", slug)
}
func widgetImage(w http.ResponseWriter, r *http.Request) {
slug := chi.URLParam(r, "slug")
fmt.Fprintf(w, "widgetImage %s\n", slug)
}
*/
4 changes: 2 additions & 2 deletions views/event_admin.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package views

import (
"errors"
"fmt"
"html/template"
"log"
"errors"
"net/http"
"html/template"

"github.com/go-chi/chi"
"gorm.io/gorm"
Expand Down
7 changes: 4 additions & 3 deletions views/event_ask_timezone.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package views

import (
"errors"
"fmt"
"html/template"
"log"
"net/http"
Expand All @@ -26,14 +27,14 @@ func EventGetAskTimezone(w http.ResponseWriter, r *http.Request) {
err = conn.First(&event, "public_code = ?", public_code).Error

if errors.Is(err, gorm.ErrRecordNotFound) {
//fmt.Fprintf(w, "Event not found")
panic("Event not found")
fmt.Fprintf(w, "Event not found")
//panic("Event not found")
return
}

tmpl_files := []string{
"templates/base.tmpl.html",
"templates/ask_timezone.tmpl.html",
"templates/event_ask_timezone.tmpl.html",
}

ts, err := template.ParseFS(content, tmpl_files...)
Expand Down
35 changes: 17 additions & 18 deletions views/event_date_range.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package views

import (
"errors"
"fmt"
"html/template"
"log"
"time"
"errors"
"strings"
"net/http"
"net/url"
"strconv"
"net/http"
"html/template"
"strings"
"time"

"github.com/go-chi/chi"
"gorm.io/gorm"
Expand All @@ -26,8 +26,8 @@ type TemplateData struct {
}

type SuccessData struct {
Event models.Event
EventUser models.EventUser
Event models.Event
EventUser models.EventUser
}

// TimeIn returns the time in UTC if the name is "" or "UTC".
Expand Down Expand Up @@ -122,14 +122,13 @@ func EventPostDataRange(w http.ResponseWriter, r *http.Request) {

conn.FirstOrCreate(&eventUser, models.EventUser{
EventID: int(event.ID),
Name: strings.TrimSpace(r.FormValue("username")),
Name: strings.TrimSpace(r.FormValue("username")),
})
//fmt.Printf("%v\n\n", &eventUser)

conn.Delete(&models.EventVote{},
"event_user_id == ?",
strconv.FormatUint(uint64(eventUser.ID), 10,
))
strconv.FormatUint(uint64(eventUser.ID), 10))

var votes []models.EventVote

Expand All @@ -142,9 +141,9 @@ func EventPostDataRange(w http.ResponseWriter, r *http.Request) {
if currentAvailability != 0 {
votes = append(votes, models.EventVote{
//EventID: int(event.ID),
Event: event,
EventUser: eventUser,
TimeOption: optionIdx,
Event: event,
EventUser: eventUser,
TimeOption: optionIdx,
TimeAvailability: currentAvailability,
})
}
Expand All @@ -164,14 +163,14 @@ func EventPostDataRange(w http.ResponseWriter, r *http.Request) {
//fmt.Fprintf(w, "r.PostFrom = %v\n", r.PostForm)

/*
for key, value := range r.PostForm {
fmt.Fprintf(w, "%v - %v\n", key, value)
}
for key, value := range r.PostForm {
fmt.Fprintf(w, "%v - %v\n", key, value)
}
*/

successData := SuccessData{
Event: event,
EventUser: eventUser,
Event: event,
EventUser: eventUser,
}

tmpl_files := []string{
Expand Down
Loading

0 comments on commit 2744e8a

Please sign in to comment.