Skip to content

Commit

Permalink
feat: support for majors | model struct tag optimizations/cleanup | t…
Browse files Browse the repository at this point in the history
…esting sync (#547)
  • Loading branch information
garrettladley authored Apr 15, 2024
1 parent 109c5ae commit 7211d51
Show file tree
Hide file tree
Showing 22 changed files with 280 additions and 115 deletions.
1 change: 1 addition & 0 deletions backend/src/database/super.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func SuperUser(superUserSettings config.SuperUserSettings) (*models.User, *error
PasswordHash: *passwordHash,
FirstName: "SAC",
LastName: "Super",
Major0: models.ComputerScience,
College: models.KCCS,
GraduationCycle: models.May,
GraduationYear: 2025,
Expand Down
1 change: 0 additions & 1 deletion backend/src/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func (aw *AWSClient) UploadFile(folder string, fileHeader *multipart.FileHeader,
Body: bytes.NewReader(file),
})
if s3Err != nil {
fmt.Printf("Failed to upload data to %s/%s, %v\n", bucket, key, err)
return nil, &errors.FailedToUploadFile
}

Expand Down
2 changes: 1 addition & 1 deletion backend/src/models/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package models
type Category struct {
Model

Name string `gorm:"type:varchar(255);unique" json:"name" validate:"required,max=255"`
Name string `gorm:"type:varchar(255);unique;not null" json:"name" validate:"required,max=255"`
Tag []Tag `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
}

Expand Down
14 changes: 7 additions & 7 deletions backend/src/models/club.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ type Club struct {

SoftDeletedAt gorm.DeletedAt `gorm:"type:timestamptz;default:NULL" json:"-" validate:"-"`

Name string `gorm:"type:varchar(255)" json:"name" validate:"required,max=255"`
Preview string `gorm:"type:varchar(255)" json:"preview" validate:"required,max=255"`
Description string `gorm:"type:text" json:"description" validate:"required,http_url,s3_url,max=255"` // S3 URL
NumMembers int `gorm:"type:int" json:"num_members" validate:"required,min=1"`
IsRecruiting bool `gorm:"type:bool;default:false" json:"is_recruiting" validate:"required"`
RecruitmentCycle RecruitmentCycle `gorm:"type:varchar(255);default:always" json:"recruitment_cycle" validate:"required,max=255,oneof=fall spring fallSpring always"`
RecruitmentType RecruitmentType `gorm:"type:varchar(255);default:unrestricted" json:"recruitment_type" validate:"required,max=255,oneof=unrestricted tryout application"`
Name string `gorm:"type:varchar(255);not null" json:"name" validate:"required,max=255"`
Preview string `gorm:"type:varchar(255);not null" json:"preview" validate:"required,max=255"`
Description string `gorm:"type:text;not null" json:"description" validate:"required,http_url,s3_url,max=255"` // S3 URL
NumMembers int `gorm:"type:int;not null" json:"num_members" validate:"required,min=1"`
IsRecruiting bool `gorm:"type:bool;default:false;not null" json:"is_recruiting" validate:"required"`
RecruitmentCycle RecruitmentCycle `gorm:"type:varchar(255);default:always;not null" json:"recruitment_cycle" validate:"required,max=255,oneof=fall spring fallSpring always"`
RecruitmentType RecruitmentType `gorm:"type:varchar(255);default:unrestricted;not null" json:"recruitment_type" validate:"required,max=255,oneof=unrestricted tryout application"`
ApplicationLink string `gorm:"type:varchar(255);default:NULL" json:"application_link" validate:"required,max=255,http_url"`
Logo string `gorm:"type:varchar(255);default:NULL" json:"logo" validate:"omitempty,http_url,s3_url,max=255"` // S3 URL

Expand Down
14 changes: 7 additions & 7 deletions backend/src/models/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import "github.com/google/uuid"
type Comment struct {
Model

Question string `gorm:"type:varchar(255)" json:"question" validate:"required,max=255"`
Answer string `gorm:"type:varchar(255)" json:"answer" validate:",max=255"`
NumFoundHelpful uint `gorm:"type:int;default:0" json:"num_found_helpful" validate:"min=0"`
Question string `gorm:"type:varchar(255);not null" json:"question" validate:"required,max=255"`
Answer string `gorm:"type:varchar(255);not null" json:"answer" validate:",max=255"`
NumFoundHelpful uint `gorm:"type:int;default:0;not null" json:"num_found_helpful" validate:"min=0"`

AskedByID uuid.UUID `gorm:"type:uuid" json:"-" validate:"uuid4"`
AskedBy User `gorm:"foreignKey:AskedByID" json:"-" validate:"-"`
AskedByID uuid.UUID `gorm:"type:uuid;not null" json:"-" validate:"uuid4"`
AskedBy User `gorm:"foreignKey:AskedByID;not null" json:"-" validate:"-"`

ClubID uuid.UUID `gorm:"type:uuid" json:"-" validate:"uuid4"`
Club Club `gorm:"foreignKey:ClubID" json:"-" validate:"-"`
ClubID uuid.UUID `gorm:"type:uuid;not null" json:"-" validate:"uuid4"`
Club Club `gorm:"foreignKey:ClubID;not null" json:"-" validate:"-"`

AnsweredByID *uuid.UUID `gorm:"type:uuid" json:"-" validate:"uuid4"`
AnsweredBy *User `gorm:"foreignKey:AnsweredBy" json:"-" validate:"-"`
Expand Down
6 changes: 3 additions & 3 deletions backend/src/models/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ func GetContentPrefix(contactType ContactType) string {
type Contact struct {
Model

Type ContactType `gorm:"type:varchar(255);uniqueIndex:idx_contact_type" json:"type" validate:"required,max=255,oneof=facebook instagram x linkedin youtube github slack discord email customSite"`
Content string `gorm:"type:varchar(255)" json:"content" validate:"required,max=255"`
Type ContactType `gorm:"type:varchar(255);uniqueIndex:idx_contact_type;not null" json:"type" validate:"required,max=255,oneof=facebook instagram x linkedin youtube github slack discord email customSite"`
Content string `gorm:"type:varchar(255);not null" json:"content" validate:"required,max=255"`

ClubID uuid.UUID `gorm:"foreignKey:ClubID;uniqueIndex:idx_contact_type" json:"-" validate:"uuid4"`
ClubID uuid.UUID `gorm:"foreignKey:ClubID;uniqueIndex:idx_contact_type;not null" json:"-" validate:"uuid4"`
}

type PutContactRequestBody struct {
Expand Down
44 changes: 22 additions & 22 deletions backend/src/models/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ const (
type Event struct {
Model

Name string `gorm:"type:varchar(255)" json:"name" validate:"required,max=255"`
Preview string `gorm:"type:varchar(255)" json:"preview" validate:"required,max=255"`
Content string `gorm:"type:varchar(255)" json:"content" validate:"required,max=255"`
StartTime time.Time `gorm:"type:timestamptz" json:"start_time" validate:"required,ltecsfield=EndTime"`
EndTime time.Time `gorm:"type:timestamptz" json:"end_time" validate:"required,gtecsfield=StartTime"`
Location string `gorm:"type:varchar(255)" json:"location" validate:"required,max=255"`
EventType EventType `gorm:"type:varchar(255);default:open" json:"event_type" validate:"required,max=255,oneof=open membersOnly"`
IsRecurring bool `gorm:"not null;type:bool;default:false" json:"is_recurring" validate:"-"`

Host *uuid.UUID `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"uuid4"`
Name string `gorm:"type:varchar(255);not null" json:"name" validate:"required,max=255"`
Preview string `gorm:"type:varchar(255);not null" json:"preview" validate:"required,max=255"`
Content string `gorm:"type:varchar(255);not null" json:"content" validate:"required,max=255"`
StartTime time.Time `gorm:"type:timestamptz;not null" json:"start_time" validate:"required,ltecsfield=EndTime"`
EndTime time.Time `gorm:"type:timestamptz;not null" json:"end_time" validate:"required,gtecsfield=StartTime"`
Location string `gorm:"type:varchar(255);not null" json:"location" validate:"required,max=255"`
EventType EventType `gorm:"type:varchar(255);default:open;not null" json:"event_type" validate:"required,max=255,oneof=open membersOnly"`
IsRecurring bool `gorm:"type:bool;default:false;not null" json:"is_recurring" validate:"-"`

Host *uuid.UUID `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;not null;" json:"-" validate:"uuid4"`
RSVP []User `gorm:"many2many:user_event_rsvps;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
Waitlist []User `gorm:"many2many:user_event_waitlists;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
Clubs []Club `gorm:"many2many:club_events;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
Expand All @@ -43,28 +43,27 @@ type Event struct {

type Series struct {
Model
RecurringType RecurringType `gorm:"type:varchar(255);default:open" json:"recurring_type" validate:"max=255"`
MaxOccurrences int `gorm:"type:int" json:"max_occurrences" validate:"min=1"`
RecurringType RecurringType `gorm:"type:varchar(255);default:open;not null" json:"recurring_type" validate:"max=255"`
MaxOccurrences int `gorm:"type:int;not null" json:"max_occurrences" validate:"min=1"`
Events []Event `gorm:"many2many:event_series;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"events" validate:"-"`
}

// TODO: add not null to required fields on all gorm models
type EventSeries struct {
EventID uuid.UUID `gorm:"not null; type:uuid;" json:"event_id" validate:"uuid4"`
EventID uuid.UUID `gorm:"type:uuid;not null" json:"event_id" validate:"uuid4"`
Event Event `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
SeriesID uuid.UUID `gorm:"not null; type:uuid;" json:"series_id" validate:"uuid4"`
SeriesID uuid.UUID `gorm:"type:uuid;not null" json:"series_id" validate:"uuid4"`
Series Series `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
}

// Not needed for now, we will just update the events separately
type EventInstanceException struct {
Model
EventID int `gorm:"not null; type:uuid" json:"event_id" validate:"required"`
EventID int `gorm:"type:uuid;not null" json:"event_id" validate:"required"`
Event Event
IsRescheduled bool `gorm:"type:bool;default:true" json:"is_rescheduled" validate:"required"`
IsCancelled bool `gorm:"type:bool;default:false" json:"is_cancelled" validate:"required"`
StartTime time.Time `gorm:"type:timestamptz" json:"start_time" validate:"required,datetime,ltecsfield=EndTime"`
EndTime time.Time `gorm:"type:timestamptz" json:"end_time" validate:"required,datetime,gtecsfield=StartTime"`
IsRescheduled bool `gorm:"type:bool;default:true;not null" json:"is_rescheduled" validate:"required"`
IsCancelled bool `gorm:"type:bool;default:false;not null" json:"is_cancelled" validate:"required"`
StartTime time.Time `gorm:"type:timestamptz;not null" json:"start_time" validate:"required,datetime,ltecsfield=EndTime"`
EndTime time.Time `gorm:"type:timestamptz;not null" json:"end_time" validate:"required,datetime,gtecsfield=StartTime"`
}

// TODO We will likely need to update the create and update structs to account for recurring series
Expand All @@ -79,7 +78,7 @@ type CreateEventRequestBody struct {
IsRecurring *bool `json:"is_recurring" validate:"required"`

// TODO club/tag/notification logic
Host *uuid.UUID `json:"host" validate:"omitempty"`
Host *uuid.UUID `json:"host" validate:"required,uuid4"`
Clubs []Club `json:"-" validate:"omitempty"`
Tag []Tag `json:"-" validate:"omitempty"`
Notification []Notification `json:"-" validate:"omitempty"`
Expand All @@ -100,8 +99,9 @@ type UpdateEventRequestBody struct {
StartTime time.Time `json:"start_time" validate:"omitempty,ltecsfield=EndTime"`
EndTime time.Time `json:"end_time" validate:"omitempty,gtecsfield=StartTime"`
Location string `json:"location" validate:"omitempty,max=255"`
EventType EventType `gorm:"type:varchar(255);default:open" json:"event_type" validate:"omitempty,max=255,oneof=open membersOnly"`
EventType EventType `json:"event_type" validate:"omitempty,max=255,oneof=open membersOnly"`

Host *uuid.UUID `json:"host" validate:"omitempty"`
RSVP []User `json:"-" validate:"omitempty"`
Waitlist []User `json:"-" validate:"omitempty"`
Clubs []Club `json:"-" validate:"omitempty"`
Expand Down
10 changes: 5 additions & 5 deletions backend/src/models/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type File struct {
OwnerID uuid.UUID `gorm:"uniqueIndex:compositeindex;index;not null;type:uuid" json:"-" validate:"required,uuid4"`
OwnerType string `gorm:"uniqueIndex:compositeindex;index;not null;type:varchar(255)" json:"-" validate:"required,max=255"`

FileName string `gorm:"type:varchar(255)" json:"file_name" validate:"required,max=255"`
FileType string `gorm:"type:varchar(255)" json:"file_type" validate:"required,max=255"`
FileSize int `gorm:"type:int" json:"file_size" validate:"required,min=1"`
FileURL string `gorm:"type:varchar(255)" json:"file_url" validate:"required,max=255"`
ObjectKey string `gorm:"type:varchar(255)" json:"object_key" validate:"required,max=255"`
FileName string `gorm:"type:varchar(255);not null" json:"file_name" validate:"required,max=255"`
FileType string `gorm:"type:varchar(255);not null" json:"file_type" validate:"required,max=255"`
FileSize int `gorm:"type:int;not null" json:"file_size" validate:"required,min=1"`
FileURL string `gorm:"type:varchar(255);not null" json:"file_url" validate:"required,max=255"`
ObjectKey string `gorm:"type:varchar(255);not null" json:"object_key" validate:"required,max=255"`
}

type CreateFileRequestBody struct {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/models/follower.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ func (Follower) TableName() string {
}

type Follower struct {
UserID uuid.UUID `gorm:"type:uuid;not null;primaryKey" json:"user_id" validate:"required,uuid4"`
ClubID uuid.UUID `gorm:"type:uuid;not null;primaryKey" json:"club_id" validate:"required,uuid4"`
UserID uuid.UUID `gorm:"type:uuid;primaryKey;not null" json:"user_id" validate:"required,uuid4"`
ClubID uuid.UUID `gorm:"type:uuid;primaryKey;not null" json:"club_id" validate:"required,uuid4"`

Club *Club `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
User *User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
Expand Down
6 changes: 3 additions & 3 deletions backend/src/models/membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func (Membership) TableName() string {
}

type Membership struct {
UserID uuid.UUID `gorm:"type:uuid;not null;primaryKey" json:"user_id" validate:"required,uuid4"`
ClubID uuid.UUID `gorm:"type:uuid;not null;primaryKey" json:"club_id" validate:"required,uuid4"`
UserID uuid.UUID `gorm:"type:uuid;primaryKey;not null" json:"user_id" validate:"required,uuid4"`
ClubID uuid.UUID `gorm:"type:uuid;primaryKey;not null" json:"club_id" validate:"required,uuid4"`

Club *Club `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
User *User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`

MembershipType MembershipType `gorm:"type:varchar(255);not null;default:member" json:"membership_type" validate:"required,oneof=member admin"`
MembershipType MembershipType `gorm:"type:varchar(255);default:member;not null" json:"membership_type" validate:"required,oneof=member admin"`
}
14 changes: 7 additions & 7 deletions backend/src/models/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ const (
type Notification struct {
Model

SendAt time.Time `gorm:"type:timestamptz" json:"send_at" validate:"required"`
Title string `gorm:"type:varchar(255)" json:"title" validate:"required,max=255"`
Content string `gorm:"type:varchar(255)" json:"content" validate:"required,max=255"`
DeepLink string `gorm:"type:varchar(255)" json:"deep_link" validate:"required,max=255"`
Icon string `gorm:"type:varchar(255)" json:"icon" validate:"required,http_url,max=255"` // S3 URL
SendAt time.Time `gorm:"type:timestamptz;not null" json:"send_at" validate:"required"`
Title string `gorm:"type:varchar(255);not null" json:"title" validate:"required,max=255"`
Content string `gorm:"type:varchar(255);not null" json:"content" validate:"required,max=255"`
DeepLink string `gorm:"type:varchar(255);not null" json:"deep_link" validate:"required,max=255"`
Icon string `gorm:"type:varchar(255);not null" json:"icon" validate:"required,s3_url,http_url,max=255"` // S3 URL

ReferenceID uuid.UUID `gorm:"type:int" json:"-" validate:"uuid4"`
ReferenceType NotificationType `gorm:"type:varchar(255)" json:"-" validate:"max=255"`
ReferenceID uuid.UUID `gorm:"type:int;not null" json:"-" validate:"uuid4"`
ReferenceType NotificationType `gorm:"type:varchar(255);not null" json:"-" validate:"max=255"`
}
8 changes: 4 additions & 4 deletions backend/src/models/poc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
type PointOfContact struct {
Model

Name string `gorm:"type:varchar(255)" json:"name" validate:"required,max=255"`
Name string `gorm:"type:varchar(255);not null" json:"name" validate:"required,max=255"`
Email string `gorm:"uniqueIndex:compositeindex;index;not null;type:varchar(255)" json:"email" validate:"required,email,max=255"`
Position string `gorm:"type:varchar(255);" json:"position" validate:"required,max=255"`
Position string `gorm:"type:varchar(255);not null" json:"position" validate:"required,max=255"`

ClubID uuid.UUID `gorm:"uniqueIndex:compositeindex;index;not null;foreignKey:ClubID" json:"-" validate:"min=1"`
ClubID uuid.UUID `gorm:"uniqueIndex:compositeindex;index;foreignKey:ClubID;not null" json:"-" validate:"required,uuid4"`

PhotoFile File `gorm:"polymorphic:Owner;" json:"photo_file"`
PhotoFile File `gorm:"polymorphic:Owner;not null" json:"photo_file"`
}

type CreatePointOfContactBody struct {
Expand Down
6 changes: 3 additions & 3 deletions backend/src/models/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Tabler interface {
}

type Model struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4()" json:"id" example:"123e4567-e89b-12d3-a456-426614174000"`
CreatedAt time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"created_at" example:"2023-09-20T16:34:50Z"`
UpdatedAt time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"updated_at" example:"2023-09-20T16:34:50Z"`
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuid_generate_v4();not null" json:"id" example:"123e4567-e89b-12d3-a456-426614174000"`
CreatedAt time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP;not null" json:"created_at" example:"2023-09-20T16:34:50Z"`
UpdatedAt time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP;not null" json:"updated_at" example:"2023-09-20T16:34:50Z"`
}
4 changes: 2 additions & 2 deletions backend/src/models/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import "github.com/google/uuid"
type Tag struct {
Model

Name string `gorm:"type:varchar(255)" json:"name" validate:"required,max=255"`
Name string `gorm:"type:varchar(255);not null" json:"name" validate:"required,max=255"`

CategoryID uuid.UUID `json:"category_id" validate:"required,uuid4"`
CategoryID uuid.UUID `gorm:"type:uuid;not null" json:"category_id" validate:"required,uuid4"`

User []User `gorm:"many2many:user_tags;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
Club []Club `gorm:"many2many:club_tags;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
Expand Down
Loading

0 comments on commit 7211d51

Please sign in to comment.