From e9bbeb62dc0f0f7d13ae2bf18f15d049ee48f01d Mon Sep 17 00:00:00 2001 From: gom-by Date: Tue, 14 Jan 2025 14:13:55 +0100 Subject: [PATCH] Schemas in backend schemas.go --- backend/go.mod | 1 + backend/go.sum | 2 + backend/schemas.go | 75 ++++++++++++++++++++++ frontend/components/nav-bar.tsx | 9 +-- frontend/deno.lock | 108 ++++++++++++++++++++++++++++++-- 5 files changed, 183 insertions(+), 12 deletions(-) create mode 100644 backend/schemas.go diff --git a/backend/go.mod b/backend/go.mod index dfc90c4..857f398 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -3,6 +3,7 @@ module fr.latosa-escrima go 1.23.4 require ( + github.com/google/uuid v1.6.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/joho/godotenv v1.5.1 // indirect github.com/puzpuzpuz/xsync/v3 v3.4.0 // indirect diff --git a/backend/go.sum b/backend/go.sum index eeda9ee..bfd2319 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -1,3 +1,5 @@ +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= diff --git a/backend/schemas.go b/backend/schemas.go new file mode 100644 index 0000000..6c61ba2 --- /dev/null +++ b/backend/schemas.go @@ -0,0 +1,75 @@ +package main + +import ( + "time" + "github.com/uptrace/bun" + "github.com/google/uuid" +) + +type Role string + +const ( + AdminRole Role = "admin" + UserRole Role = "user" +) + +type User struct { + bun.BaseModel `bun:"table:users"` + + ID uuid.UUID `bun:"type:uuid,pk,default:gen_random_uuid()"` + FirstName string `bun:"firstname,notnull"` + LastName string `bun:"lastname,notnull"` + Email string `bun:"email,unique,notnull"` + Phone string `bun:"phone,notnull"` + Role Role `bun:"role,notnull,default:'user'"` + CreatedAt time.Time `bun:"created_at,default:current_timestamp"` + UpdatedAt time.Time `bun:"updated_at,default:current_timestamp"` +} + +type Event struct { + bun.BaseModel `bun:"table:events"` + + EventID uuid.UUID `bun:"type:uuid,pk"` + CreationDate time.Time `bun:"creation_date,notnull,default:current_timestamp"` + ScheduleStart time.Time `bun:"schedule_start,notnull"` + ScheduleEnd time.Time `bun:"schedule_end,notnull"` + Status string `bun:"status,notnull"` +} + +type EventsToUsers struct { + bun.BaseModel `bun:"table:events_to_users"` + + EventID uuid.UUID `bun:"type:uuid,notnull"` + UserID uuid.UUID `bun:"type:uuid,notnull"` + + Event *Event `bun:"rel:belongs_to,join:event_id=event_id"` + User *User `bun:"rel:belongs_to,join:user_id=user_id"` + + PrimaryKey struct { + EventID uuid.UUID `bun:"pk"` + UserID uuid.UUID `bun:"pk"` + } +} + +type Blog struct { + bun.BaseModel `bun:"table:blogs"` + + UUID uuid.UUID `bun:"type:uuid,pk"` + Slug string `bun:"slug,unique,notnull"` + Content string `bun:"content,notnull"` + Label string `bun:"label"` + AuthorID uuid.UUID `bun:"author,notnull"` + Published time.Time `bun:"published,default:current_timestamp"` + Summary string `bun:"summary"` + Image string `bun:"image"` + Href string `bun:"href"` + + Author *User `bun:"rel:belongs_to,join:author=author_id"` +} + +type WebsiteSettings struct { + bun.BaseModel `bun:"table:website_settings"` + + ID uuid.UUID `bun:"type:uuid,pk,default:gen_random_uuid()"` + AutoAcceptDemand bool `bun:"auto_accept_demand,default:false"` +} diff --git a/frontend/components/nav-bar.tsx b/frontend/components/nav-bar.tsx index 64e85c8..99a0400 100644 --- a/frontend/components/nav-bar.tsx +++ b/frontend/components/nav-bar.tsx @@ -69,7 +69,7 @@ const subMenuItemsTwo = [ const Navbar = () => { return (
-
+