blogs and event api : Get and Post methods

This commit is contained in:
gom-by
2025-01-16 14:45:18 +01:00
parent 9a6e4a7565
commit 0c5a411ed1
5 changed files with 174 additions and 91 deletions

View File

@@ -33,6 +33,13 @@ const (
UserRole Role = "user"
)
type Status string
const (
Active Status = "Active"
Inactive Status = "Inactive"
)
type User struct {
bun.BaseModel `bun:"table:users"`
@@ -52,17 +59,17 @@ type User struct {
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"`
EventID uuid.UUID `bun:"type:uuid,pk,default:gen_random_uuid()" json:"eventID"`
CreationDate time.Time `bun:"creation_date,notnull,default:current_timestamp" json:"creationDate"`
ScheduleStart time.Time `bun:"schedule_start,notnull" json:"scheduleStart"`
ScheduleEnd time.Time `bun:"schedule_end,notnull" json:"scheduleEnd"`
Status Status `bun:"status,notnull,default:Inactive" json:"status"`
}
type EventToUser struct {
bun.BaseModel `bun:"table:events_to_users"`
EventID uuid.UUID `bun:"type:uuid,pk"`
EventID uuid.UUID `bun:"type:uuid,pk"`
UserID uuid.UUID `bun:"type:uuid,pk"`
Event *Event `bun:"rel:belongs-to,join:event_id=event_id"`
@@ -72,24 +79,24 @@ type EventToUser struct {
type Blog struct {
bun.BaseModel `bun:"table:blogs"`
BlogID 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_id,notnull"`
Published time.Time `bun:"published,default:current_timestamp"`
Summary string `bun:"summary"`
Image string `bun:"image"`
Href string `bun:"href"`
BlogID uuid.UUID `bun:"type:uuid,pk,default:gen_random_uuid()" json:"blogID"`
Slug string `bun:"slug,unique,notnull" json:"slug"`
Content string `bun:"content,notnull" json:"content"`
Label string `bun:"label" json:"label"`
AuthorID uuid.UUID `bun:"author_id,type:uuid,notnull" json:"authorID"`
Published time.Time `bun:"published,default:current_timestamp" json:"published"`
Summary string `bun:"summary" json:"summary"`
Image string `bun:"image" json:"image"`
Href string `bun:"href" json:"href"`
Author *User `bun:"rel:belongs-to,join:author_id=user_id"`
Author User `bun:"rel:belongs-to,join:author_id=user_id" json:"author"`
}
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"`
ID uuid.UUID `bun:"type:uuid,pk,default:gen_random_uuid()" json:"id"`
AutoAcceptDemand bool `bun:"auto_accept_demand,default:false" json:"autoAcceptDemand"`
}
func InitDatabase(dsn DSN) (*bun.DB, error) {