diff options
-rw-r--r-- | client/.editorconfig (renamed from .editorconfig) | 0 | ||||
-rw-r--r-- | client/.eslintrc.cjs (renamed from .eslintrc.cjs) | 0 | ||||
-rw-r--r-- | client/.gitignore (renamed from .gitignore) | 0 | ||||
-rw-r--r-- | client/.prettierrc (renamed from .prettierrc) | 0 | ||||
-rw-r--r-- | client/README.md (renamed from README.md) | 0 | ||||
-rw-r--r-- | client/index.html (renamed from index.html) | 0 | ||||
-rw-r--r-- | client/package-lock.json (renamed from package-lock.json) | 0 | ||||
-rw-r--r-- | client/package.json (renamed from package.json) | 0 | ||||
-rw-r--r-- | client/public/avatar.png (renamed from public/avatar.png) | bin | 7941 -> 7941 bytes | |||
-rw-r--r-- | client/public/mockServiceWorker.js (renamed from public/mockServiceWorker.js) | 0 | ||||
-rw-r--r-- | client/src/App.tsx (renamed from src/App.tsx) | 0 | ||||
-rw-r--r-- | client/src/ThemeContextProvider.tsx (renamed from src/ThemeContextProvider.tsx) | 0 | ||||
-rw-r--r-- | client/src/apiSlice.ts (renamed from src/apiSlice.ts) | 0 | ||||
-rw-r--r-- | client/src/components/Admin.tsx (renamed from src/components/Admin.tsx) | 0 | ||||
-rw-r--r-- | client/src/components/Desktop.tsx (renamed from src/components/Desktop.tsx) | 0 | ||||
-rw-r--r-- | client/src/components/Home.tsx (renamed from src/components/Home.tsx) | 0 | ||||
-rw-r--r-- | client/src/components/Mobile.tsx (renamed from src/components/Mobile.tsx) | 0 | ||||
-rw-r--r-- | client/src/components/NavBar.tsx (renamed from src/components/NavBar.tsx) | 0 | ||||
-rw-r--r-- | client/src/components/Registry.tsx (renamed from src/components/Registry.tsx) | 0 | ||||
-rw-r--r-- | client/src/components/Rsvp.tsx (renamed from src/components/Rsvp.tsx) | 0 | ||||
-rw-r--r-- | client/src/components/RsvpForm.tsx (renamed from src/components/RsvpForm.tsx) | 0 | ||||
-rw-r--r-- | client/src/components/Schedule.tsx (renamed from src/components/Schedule.tsx) | 2 | ||||
-rw-r--r-- | client/src/components/active.css (renamed from src/components/active.css) | 0 | ||||
-rw-r--r-- | client/src/features/auth/GuestLogin.tsx (renamed from src/features/auth/GuestLogin.tsx) | 0 | ||||
-rw-r--r-- | client/src/features/auth/authSlice.ts (renamed from src/features/auth/authSlice.ts) | 0 | ||||
-rw-r--r-- | client/src/main.css (renamed from src/main.css) | 0 | ||||
-rw-r--r-- | client/src/main.tsx (renamed from src/main.tsx) | 0 | ||||
-rw-r--r-- | client/src/mocks/browser.ts (renamed from src/mocks/browser.ts) | 0 | ||||
-rw-r--r-- | client/src/mocks/handlers.ts (renamed from src/mocks/handlers.ts) | 2 | ||||
-rw-r--r-- | client/src/pages.ts (renamed from src/pages.ts) | 0 | ||||
-rw-r--r-- | client/src/store.ts (renamed from src/store.ts) | 0 | ||||
-rw-r--r-- | client/src/vite-env.d.ts (renamed from src/vite-env.d.ts) | 0 | ||||
-rw-r--r-- | client/tsconfig.json (renamed from tsconfig.json) | 0 | ||||
-rw-r--r-- | client/vite.config.ts (renamed from vite.config.ts) | 0 | ||||
-rw-r--r-- | server/.bashrc | 1 | ||||
-rw-r--r-- | server/cmd/main.go | 109 | ||||
-rw-r--r-- | server/go.mod | 3 | ||||
-rw-r--r-- | server/guests/models.go | 17 | ||||
-rw-r--r-- | server/guests/store.go | 26 | ||||
-rw-r--r-- | server/post.json | 15 |
40 files changed, 172 insertions, 3 deletions
diff --git a/.editorconfig b/client/.editorconfig index 41c2aaf..41c2aaf 100644 --- a/.editorconfig +++ b/client/.editorconfig diff --git a/.eslintrc.cjs b/client/.eslintrc.cjs index d6c9537..d6c9537 100644 --- a/.eslintrc.cjs +++ b/client/.eslintrc.cjs diff --git a/.gitignore b/client/.gitignore index 0750d47..0750d47 100644 --- a/.gitignore +++ b/client/.gitignore diff --git a/.prettierrc b/client/.prettierrc index e537c8a..e537c8a 100644 --- a/.prettierrc +++ b/client/.prettierrc diff --git a/README.md b/client/README.md index 0d6babe..0d6babe 100644 --- a/README.md +++ b/client/README.md diff --git a/index.html b/client/index.html index 567658b..567658b 100644 --- a/index.html +++ b/client/index.html diff --git a/package-lock.json b/client/package-lock.json index 9487398..9487398 100644 --- a/package-lock.json +++ b/client/package-lock.json diff --git a/package.json b/client/package.json index fac7b6b..fac7b6b 100644 --- a/package.json +++ b/client/package.json diff --git a/public/avatar.png b/client/public/avatar.png Binary files differindex 58fada6..58fada6 100644 --- a/public/avatar.png +++ b/client/public/avatar.png diff --git a/public/mockServiceWorker.js b/client/public/mockServiceWorker.js index 919d3e1..919d3e1 100644 --- a/public/mockServiceWorker.js +++ b/client/public/mockServiceWorker.js diff --git a/src/App.tsx b/client/src/App.tsx index 27fc180..27fc180 100644 --- a/src/App.tsx +++ b/client/src/App.tsx diff --git a/src/ThemeContextProvider.tsx b/client/src/ThemeContextProvider.tsx index 6ae1430..6ae1430 100644 --- a/src/ThemeContextProvider.tsx +++ b/client/src/ThemeContextProvider.tsx diff --git a/src/apiSlice.ts b/client/src/apiSlice.ts index 5d987f9..5d987f9 100644 --- a/src/apiSlice.ts +++ b/client/src/apiSlice.ts diff --git a/src/components/Admin.tsx b/client/src/components/Admin.tsx index 1c941a5..1c941a5 100644 --- a/src/components/Admin.tsx +++ b/client/src/components/Admin.tsx diff --git a/src/components/Desktop.tsx b/client/src/components/Desktop.tsx index 13de4ee..13de4ee 100644 --- a/src/components/Desktop.tsx +++ b/client/src/components/Desktop.tsx diff --git a/src/components/Home.tsx b/client/src/components/Home.tsx index 839667a..839667a 100644 --- a/src/components/Home.tsx +++ b/client/src/components/Home.tsx diff --git a/src/components/Mobile.tsx b/client/src/components/Mobile.tsx index 2e7b15c..2e7b15c 100644 --- a/src/components/Mobile.tsx +++ b/client/src/components/Mobile.tsx diff --git a/src/components/NavBar.tsx b/client/src/components/NavBar.tsx index 52e8e6c..52e8e6c 100644 --- a/src/components/NavBar.tsx +++ b/client/src/components/NavBar.tsx diff --git a/src/components/Registry.tsx b/client/src/components/Registry.tsx index 60a73f9..60a73f9 100644 --- a/src/components/Registry.tsx +++ b/client/src/components/Registry.tsx diff --git a/src/components/Rsvp.tsx b/client/src/components/Rsvp.tsx index dad7213..dad7213 100644 --- a/src/components/Rsvp.tsx +++ b/client/src/components/Rsvp.tsx diff --git a/src/components/RsvpForm.tsx b/client/src/components/RsvpForm.tsx index 71db0d8..71db0d8 100644 --- a/src/components/RsvpForm.tsx +++ b/client/src/components/RsvpForm.tsx diff --git a/src/components/Schedule.tsx b/client/src/components/Schedule.tsx index 3ebe446..808499c 100644 --- a/src/components/Schedule.tsx +++ b/client/src/components/Schedule.tsx @@ -15,7 +15,7 @@ function Schedule() { elevation={3} sx={{ mt: 8, - height: '50%', + height: '100%', width: '100%', display: 'flex', flexDirection: 'column', diff --git a/src/components/active.css b/client/src/components/active.css index e8b5f60..e8b5f60 100644 --- a/src/components/active.css +++ b/client/src/components/active.css diff --git a/src/features/auth/GuestLogin.tsx b/client/src/features/auth/GuestLogin.tsx index 4da7e45..4da7e45 100644 --- a/src/features/auth/GuestLogin.tsx +++ b/client/src/features/auth/GuestLogin.tsx diff --git a/src/features/auth/authSlice.ts b/client/src/features/auth/authSlice.ts index bff2bdd..bff2bdd 100644 --- a/src/features/auth/authSlice.ts +++ b/client/src/features/auth/authSlice.ts diff --git a/src/main.css b/client/src/main.css index 5cb7cd6..5cb7cd6 100644 --- a/src/main.css +++ b/client/src/main.css diff --git a/src/main.tsx b/client/src/main.tsx index 8ada188..8ada188 100644 --- a/src/main.tsx +++ b/client/src/main.tsx diff --git a/src/mocks/browser.ts b/client/src/mocks/browser.ts index 0a56427..0a56427 100644 --- a/src/mocks/browser.ts +++ b/client/src/mocks/browser.ts diff --git a/src/mocks/handlers.ts b/client/src/mocks/handlers.ts index e3569df..217a7d5 100644 --- a/src/mocks/handlers.ts +++ b/client/src/mocks/handlers.ts @@ -11,7 +11,6 @@ export const handlers = [ firstName: 'Michael', lastName: 'Hunteman', attendance: 'false', - meal: '', email: '', message: '', }, @@ -24,7 +23,6 @@ export const handlers = [ firstName: 'Michael', lastName: 'Hunteman', attendance: 'true', - meal: 'beef', email: '', message: '', }); diff --git a/src/pages.ts b/client/src/pages.ts index bad57f6..bad57f6 100644 --- a/src/pages.ts +++ b/client/src/pages.ts diff --git a/src/store.ts b/client/src/store.ts index 264639e..264639e 100644 --- a/src/store.ts +++ b/client/src/store.ts diff --git a/src/vite-env.d.ts b/client/src/vite-env.d.ts index 11f02fe..11f02fe 100644 --- a/src/vite-env.d.ts +++ b/client/src/vite-env.d.ts diff --git a/tsconfig.json b/client/tsconfig.json index 960b5a6..960b5a6 100644 --- a/tsconfig.json +++ b/client/tsconfig.json diff --git a/vite.config.ts b/client/vite.config.ts index 5a33944..5a33944 100644 --- a/vite.config.ts +++ b/client/vite.config.ts diff --git a/server/.bashrc b/server/.bashrc new file mode 100644 index 0000000..802d935 --- /dev/null +++ b/server/.bashrc @@ -0,0 +1 @@ +PATH=$PATH:/c/Go/bin diff --git a/server/cmd/main.go b/server/cmd/main.go new file mode 100644 index 0000000..ed4f748 --- /dev/null +++ b/server/cmd/main.go @@ -0,0 +1,109 @@ +package main + +import ( + "encoding/json" + "log" + "net/http" + "regexp" + "strconv" + + "git.huntm.net/wedding/server/guests" +) + +type guestHandler struct { + store guestStore +} + +type guestStore interface { + Get() (map[int]guests.Guest, error) + Add(id int, guest guests.Guest) error + Update(id int, guest guests.Guest) error +} + +var ( + guestRe = regexp.MustCompile(`^/guests/*$`) + guestIdRe = regexp.MustCompile(`^/guests/([0-9]+)$`) +) + +func newGuestHandler(s guestStore) *guestHandler { + return &guestHandler{ + store: s, + } +} + +func (h *guestHandler) getGuests(w http.ResponseWriter, _ *http.Request) { + guests, err := h.store.Get() + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + } + + jsonBytes, err := json.Marshal(guests) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + } + + w.WriteHeader(http.StatusOK) + w.Write(jsonBytes) +} + +func (h *guestHandler) createGuest(w http.ResponseWriter, r *http.Request) { + var guest guests.Guest + err := json.NewDecoder(r.Body).Decode(&guest) + defer r.Body.Close() + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + err = h.store.Add(guest.Id, guest) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + + w.WriteHeader(http.StatusOK) +} + +func (h *guestHandler) updateGuest(w http.ResponseWriter, r *http.Request) { + matches := guestIdRe.FindStringSubmatch(r.URL.Path) + if len(matches) < 2 { + http.Error(w, "No id found", http.StatusBadRequest) + } + + var guest guests.Guest + err := json.NewDecoder(r.Body).Decode(&guest) + defer r.Body.Close() + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + } + + id, err := strconv.Atoi(matches[1]) + if err != nil { + http.Error(w, "Cannot convert string to integer", http.StatusBadRequest) + } + + err = h.store.Update(id, guest) + if err != nil { + http.Error(w, "Guest not found", http.StatusBadRequest) + } +} + +func (h *guestHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + switch { + case r.Method == http.MethodGet && guestRe.MatchString(r.URL.Path): + h.getGuests(w, r) + case r.Method == http.MethodPost && guestRe.MatchString(r.URL.Path): + h.createGuest(w, r) + case r.Method == http.MethodPut && guestIdRe.MatchString(r.URL.Path): + h.updateGuest(w, r) + } +} + +func main() { + store := guests.NewMemStore() + guestHandler := newGuestHandler(store) + + mux := http.NewServeMux() + mux.Handle("/guests/", guestHandler) + log.Fatal(http.ListenAndServe(":8080", mux)) +} diff --git a/server/go.mod b/server/go.mod new file mode 100644 index 0000000..737eac4 --- /dev/null +++ b/server/go.mod @@ -0,0 +1,3 @@ +module git.huntm.net/wedding/server + +go 1.22.2 diff --git a/server/guests/models.go b/server/guests/models.go new file mode 100644 index 0000000..c68a4c3 --- /dev/null +++ b/server/guests/models.go @@ -0,0 +1,17 @@ +package guests + +type Guest struct { + Id int `json:"id"` + FirstName string `json:"firstName"` + LastName string `json:"lastName"` + Attendance string `json:"attendance"` + Email string `json:"email"` + Message string `json:"message"` + PartySize int `json:"partySize"` + PartyList []PartyGuest `json:"partyList"` +} + +type PartyGuest struct { + FirstName string `json:"firstName"` + LastName string `json:"lastName"` +} diff --git a/server/guests/store.go b/server/guests/store.go new file mode 100644 index 0000000..f1d8558 --- /dev/null +++ b/server/guests/store.go @@ -0,0 +1,26 @@ +package guests + +type MemStore struct { + guestMap map[int]Guest +} + +func NewMemStore() *MemStore { + guestMap := make(map[int]Guest) + return &MemStore{ + guestMap, + } +} + +func (m MemStore) Get() (map[int]Guest, error) { + return m.guestMap, nil +} + +func (m MemStore) Add(id int, guest Guest) error { + m.guestMap[id] = guest + return nil +} + +func (m MemStore) Update(id int, guest Guest) error { + m.guestMap[id] = guest + return nil +} diff --git a/server/post.json b/server/post.json new file mode 100644 index 0000000..f550b1b --- /dev/null +++ b/server/post.json @@ -0,0 +1,15 @@ +{ + "id": 1, + "firstName": "Michael", + "lastName": "Hunteman", + "attendance": "true", + "email": "mhunteman@cox.net", + "message": "Hi", + "partySize": 1, + "partyList": [ + { + "firstName": "Madison", + "lastName": "Rossitto" + } + ] +} |