Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: events overhaul #745

Merged
merged 31 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cbe98d4
finally commiting initial progress on events refactor
garrettladley May 7, 2024
a620684
rename from protos.Event -> protos.Occurence to avoid confusion
garrettladley May 7, 2024
f815453
logical reorg
garrettladley May 7, 2024
f2454fb
Merge branch 'main' into 669-fix-events
garrettladley May 7, 2024
1e3b8ca
go mod shi
garrettladley May 7, 2024
14cdee7
Merge branch 'main' into 669-fix-events
garrettladley May 7, 2024
89c9406
max termination date config | naming clarity | series as nested route…
garrettladley May 9, 2024
874315d
merge complete
garrettladley May 10, 2024
baa4766
pause
garrettladley May 10, 2024
eae033d
Merge branch 'main' into 669-fix-events
garrettladley May 10, 2024
a8935fe
Merge branch '669-fix-events' of https://github.com/GenerateNU/sac in…
garrettladley May 10, 2024
1e1b530
routes built out | TODO: test
garrettladley May 10, 2024
ab6d6b2
format and lint
garrettladley May 10, 2024
61ad863
fix typo
garrettladley May 10, 2024
e1f365c
Merge branch 'main' into 669-fix-events
garrettladley May 10, 2024
1ed66f3
more ergonomic proto | increased go lint timeout
garrettladley May 11, 2024
0c880f6
Merge branch 'main' into 669-fix-events
garrettladley May 11, 2024
de89c5e
reorg
garrettladley May 11, 2024
35256ec
calendar config fix | schema sheet
garrettladley May 11, 2024
a8be8d4
sync down with up
garrettladley May 11, 2024
556f294
Merge branch 'main' into 669-fix-events
garrettladley May 11, 2024
71858c1
middleware updates
garrettladley May 11, 2024
5c19ca9
fix no effect
garrettladley May 11, 2024
81e6a4d
format & lint
garrettladley May 11, 2024
51b41f3
Merge branch 'main' into 669-fix-events
garrettladley May 12, 2024
1035b7d
post make decorator clean up
garrettladley May 12, 2024
afd82ed
lint and format
garrettladley May 12, 2024
c90ebe0
the utilities.MapJsonTags fiasco...
garrettladley May 13, 2024
92a90a2
Merge branch 'main' into 669-fix-events
garrettladley May 17, 2024
06b76dc
clean up post merge
garrettladley May 17, 2024
2030c8d
i'm satisfied with events
garrettladley May 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions backend/config/calendar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package config

import (
"time"
)

type CalendarSettings struct {
MaxTerminationDate time.Time
garrettladley marked this conversation as resolved.
Show resolved Hide resolved
}

type intermediateCalendarSettings struct {
MaxTerminationDate string `yaml:"maxterminationdate"`
}

func (int *intermediateCalendarSettings) into() (*CalendarSettings, error) {
t, err := time.Parse("01-02-2006", int.MaxTerminationDate)
if err != nil {
return nil, err
}

return &CalendarSettings{
MaxTerminationDate: t,
}, nil
}
24 changes: 16 additions & 8 deletions backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ import (
)

type Settings struct {
Application ApplicationSettings
Database DatabaseSettings
SuperUser SuperUserSettings
Auth AuthSettings
AWS AWSSettings
PineconeSettings PineconeSettings
OpenAISettings OpenAISettings
ResendSettings ResendSettings
Application ApplicationSettings
Database DatabaseSettings
SuperUser SuperUserSettings
Auth AuthSettings
AWS AWSSettings
Pinecone PineconeSettings
OpenAI OpenAISettings
Resend ResendSettings
Calendar CalendarSettings
}

type intermediateSettings struct {
Application ApplicationSettings `yaml:"application"`
Database intermediateDatabaseSettings `yaml:"database"`
SuperUser intermediateSuperUserSettings `yaml:"superuser"`
Auth intermediateAuthSettings `yaml:"authsecret"`
Calendar intermediateCalendarSettings `yaml:"calendar"`
}

func (int *intermediateSettings) into() (*Settings, error) {
Expand All @@ -41,11 +43,17 @@ func (int *intermediateSettings) into() (*Settings, error) {
return nil, err
}

calendarSettings, err := int.Calendar.into()
if err != nil {
return nil, err
}

return &Settings{
Application: int.Application,
Database: *databaseSettings,
SuperUser: *superUserSettings,
Auth: *authSettings,
Calendar: *calendarSettings,
}, nil
}

Expand Down
6 changes: 3 additions & 3 deletions backend/config/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func readLocal(v *viper.Viper, path string, useDevDotEnv bool) (*Settings, error
return nil, fmt.Errorf("failed to read Pinecone settings: %w", err)
}

settings.PineconeSettings = *pineconeSettings
settings.Pinecone = *pineconeSettings

openAISettings, err := readOpenAISettings()
if err != nil {
return nil, fmt.Errorf("failed to read OpenAI settings: %w", err)
}

settings.OpenAISettings = *openAISettings
settings.OpenAI = *openAISettings

awsSettings, err := readAWSSettings()
if err != nil {
Expand All @@ -63,7 +63,7 @@ func readLocal(v *viper.Viper, path string, useDevDotEnv bool) (*Settings, error
return nil, fmt.Errorf("failed to read Resend settings: %w", err)
}

settings.ResendSettings = *resendSettings
settings.Resend = *resendSettings

return settings, nil
}
10 changes: 6 additions & 4 deletions backend/config/production.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
type ProductionSettings struct {
Database ProductionDatabaseSettings `yaml:"database"`
Application ProductionApplicationSettings `yaml:"application"`
Calendar CalendarSettings `yaml:"calendar"`
}

type ProductionDatabaseSettings struct {
Expand Down Expand Up @@ -118,9 +119,10 @@ func readProd(v *viper.Viper) (*Settings, error) {
AccessKey: authAccessKey,
RefreshKey: authRefreshKey,
},
PineconeSettings: *pineconeSettings,
OpenAISettings: *openAISettings,
AWS: *awsSettings,
ResendSettings: *resendSettings,
Pinecone: *pineconeSettings,
OpenAI: *openAISettings,
AWS: *awsSettings,
Resend: *resendSettings,
Calendar: prodSettings.Calendar,
}, nil
}
11 changes: 6 additions & 5 deletions backend/entities/clubs/base/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import (
"github.com/GenerateNU/sac/backend/entities/clubs/member"
"github.com/GenerateNU/sac/backend/entities/clubs/poc"
"github.com/GenerateNU/sac/backend/entities/clubs/tag"
"github.com/GenerateNU/sac/backend/middleware"

"github.com/GenerateNU/sac/backend/types"
"github.com/gofiber/fiber/v2"
)

func ClubRoutes(clubParams types.RouteParams) {
clubIDRouter := ClubRouter(clubParams)

// update the router in params
clubParams.Router = clubIDRouter
clubParams.Router = ClubRouter(clubParams)

tag.ClubTag(clubParams)
follower.ClubFollower(clubParams)
Expand All @@ -40,7 +38,10 @@ func ClubRouter(clubParams types.RouteParams) fiber.Router {
clubID := clubs.Group("/:clubID")

clubID.Get("/", clubController.GetClub)
clubID.Patch("/", clubParams.AuthMiddleware.ClubAuthorizeById, clubController.UpdateClub)
clubID.Patch(
"/",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
clubController.UpdateClub)
clubID.Delete("/", clubParams.AuthMiddleware.Authorize(p.DeleteAll), clubController.DeleteClub)

return clubID
Expand Down
7 changes: 6 additions & 1 deletion backend/entities/clubs/contact/routes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package contact

import (
"github.com/GenerateNU/sac/backend/middleware"
"github.com/GenerateNU/sac/backend/types"
)

Expand All @@ -11,5 +12,9 @@ func ClubContact(clubParams types.RouteParams) {

// api/v1/clubs/:clubID/contacts/*
clubContacts.Get("/", clubContactController.GetClubContacts)
clubContacts.Put("/", clubParams.AuthMiddleware.ClubAuthorizeById, clubContactController.PutContact)
clubContacts.Put(
"/",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
clubContactController.PutContact,
)
}
13 changes: 11 additions & 2 deletions backend/entities/clubs/member/routes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package member

import (
"github.com/GenerateNU/sac/backend/middleware"
"github.com/GenerateNU/sac/backend/types"
)

Expand All @@ -11,6 +12,14 @@ func ClubMember(clubParams types.RouteParams) {

// api/v1/clubs/:clubID/members/*
clubMembers.Get("/", clubMemberController.GetClubMembers)
clubMembers.Post("/:userID", clubParams.AuthMiddleware.ClubAuthorizeById, clubMemberController.CreateClubMember)
clubMembers.Delete("/:userID", clubParams.AuthMiddleware.ClubAuthorizeById, clubMemberController.DeleteClubMember)
clubMembers.Post(
"/:userID",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
clubMemberController.CreateClubMember,
)
clubMembers.Delete(
"/:userID",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
clubMemberController.DeleteClubMember,
)
}
25 changes: 21 additions & 4 deletions backend/entities/clubs/poc/routes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package poc

import (
"github.com/GenerateNU/sac/backend/middleware"
"github.com/GenerateNU/sac/backend/types"
)

Expand All @@ -12,8 +13,24 @@ func ClubPointOfContact(clubParams types.RouteParams) {
// api/v1/clubs/:clubID/pocs/*
clubPointOfContacts.Get("/", clubPointOfContactController.GetClubPointOfContacts)
clubPointOfContacts.Get("/:pocID", clubPointOfContactController.GetClubPointOfContact)
clubPointOfContacts.Post("/", clubParams.AuthMiddleware.ClubAuthorizeById, clubPointOfContactController.CreateClubPointOfContact)
clubPointOfContacts.Patch("/:pocID", clubParams.AuthMiddleware.ClubAuthorizeById, clubPointOfContactController.UpdateClubPointOfContact)
clubPointOfContacts.Patch("/:pocID/photo", clubParams.AuthMiddleware.ClubAuthorizeById, clubPointOfContactController.UpdateClubPointOfContactPhoto)
clubPointOfContacts.Delete("/:pocID", clubParams.AuthMiddleware.ClubAuthorizeById, clubPointOfContactController.DeleteClubPointOfContact)
clubPointOfContacts.Post(
"/",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
clubPointOfContactController.CreateClubPointOfContact,
)
clubPointOfContacts.Patch(
"/:pocID",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
clubPointOfContactController.UpdateClubPointOfContact,
)
clubPointOfContacts.Patch(
"/:pocID/photo",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
clubPointOfContactController.UpdateClubPointOfContactPhoto,
)
clubPointOfContacts.Delete(
"/:pocID",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
clubPointOfContactController.DeleteClubPointOfContact,
)
}
13 changes: 11 additions & 2 deletions backend/entities/clubs/tag/routes.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tag

import (
"github.com/GenerateNU/sac/backend/middleware"
"github.com/GenerateNU/sac/backend/types"
)

Expand All @@ -11,6 +12,14 @@ func ClubTag(clubParams types.RouteParams) {

// api/v1/clubs/:clubID/tags/*
clubTags.Get("/", clubTagController.GetClubTags)
clubTags.Post("/", clubParams.AuthMiddleware.ClubAuthorizeById, clubTagController.CreateClubTags)
clubTags.Delete("/:tagID", clubParams.AuthMiddleware.ClubAuthorizeById, clubTagController.DeleteClubTag)
clubTags.Post(
"/",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
clubTagController.CreateClubTags,
)
clubTags.Delete(
"/:tagID",
middleware.AttachExtractor(clubParams.AuthMiddleware.ClubAuthorizeById, middleware.ExtractFromParams("clubID")),
clubTagController.DeleteClubTag,
)
}
8 changes: 4 additions & 4 deletions backend/entities/clubs/tag/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
)

func CreateClubTags(db *gorm.DB, id uuid.UUID, tags []models.Tag) ([]models.Tag, error) {
user, err := clubs.GetClub(db, id, transactions.PreloadTag())
club, err := clubs.GetClub(db, id, transactions.PreloadTag())
if err != nil {
return nil, err
}

if err := db.Model(&user).Association("Tag").Append(tags); err != nil {
if err := db.Model(&club).Association("Tag").Append(tags); err != nil {
return nil, err
}

Expand All @@ -26,7 +26,7 @@ func CreateClubTags(db *gorm.DB, id uuid.UUID, tags []models.Tag) ([]models.Tag,
func GetClubTags(db *gorm.DB, id uuid.UUID) ([]models.Tag, error) {
var tags []models.Tag

club, err := clubs.GetClub(db, id)
club, err := clubs.GetClub(db, id, transactions.PreloadTag())
if err != nil {
return nil, err
}
Expand All @@ -38,7 +38,7 @@ func GetClubTags(db *gorm.DB, id uuid.UUID) ([]models.Tag, error) {
}

func DeleteClubTag(db *gorm.DB, id uuid.UUID, tagID uuid.UUID) error {
club, err := clubs.GetClub(db, id)
club, err := clubs.GetClub(db, id, transactions.PreloadTag())
if err != nil {
return err
}
Expand Down
Loading
Loading