Skip to content

Commit

Permalink
Merge branch 'main' into minor-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley authored Mar 11, 2024
2 parents d1e38cb + 62517dd commit c2e1633
Show file tree
Hide file tree
Showing 71 changed files with 1,183 additions and 530 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/backend_codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ jobs:
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: "go"
languages: go
queries: security-and-quality
- name: Build
run: |
cd ./backend/ && go build -o backend src/main.go
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:go"
category: backend
4 changes: 2 additions & 2 deletions .github/workflows/cli_codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ jobs:
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: "go"
languages: go
queries: security-and-quality
- name: Build
run: |
cd ./cli/ && go build -o cli main.go
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:go"
category: cli
4 changes: 2 additions & 2 deletions .github/workflows/mobile_codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: "javascript-typescript"
languages: javascript-typescript
queries: security-and-quality
- name: Autobuild
uses: github/codeql-action/autobuild@v3
Expand All @@ -38,4 +38,4 @@ jobs:
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:javascript-typescript"
category: mobile
4 changes: 2 additions & 2 deletions .github/workflows/web_codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: "javascript-typescript"
languages: javascript-typescript
queries: security-and-quality
- name: Autobuild
uses: github/codeql-action/autobuild@v3
Expand All @@ -38,4 +38,4 @@ jobs:
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:javascript-typescript"
category: web
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@

<br />

<a href="https://github.com/GenerateNU/sac/actions/workflows/mobile.yml">
<img src="https://github.com/GenerateNU/sac/actions/workflows/mobile.yml/badge.svg"
alt="Mobile Workflow Status" />
</a>

<a href="https://github.com/GenerateNU/sac/actions/workflows/mobile_codeql.yml">
<img src="https://github.com/GenerateNU/sac/actions/workflows/mobile_codeql.yml/badge.svg"
alt="Mobile CodeQL Workflow Status" />
</a>

<a href="https://github.com/GenerateNU/sac/actions/workflows/mobile.yml">
<img src="https://github.com/GenerateNU/sac/actions/workflows/mobile.yml/badge.svg"
alt="Mobile Workflow Status" />
</a>

<br />

Expand All @@ -61,6 +62,6 @@

<div align="center">
<a href="https://github.com/GenerateNU/sac/graphs/contributors">
<img src="https://contrib.rocks/image?repo=GenerateNU/sac" height="50px"/>
<img src="https://contrib.rocks/image?repo=GenerateNU/sac" height="50px" alt="Contributors Image" />
</a>
</div>
8 changes: 4 additions & 4 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/GenerateNU/sac/backend
go 1.22.0

require (
github.com/garrettladley/mattress v0.3.2
github.com/garrettladley/mattress v0.4.0
github.com/go-playground/validator/v10 v10.19.0
github.com/goccy/go-json v0.10.2
github.com/gofiber/fiber/v2 v2.52.2
Expand All @@ -16,9 +16,9 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/spf13/viper v1.18.2
github.com/swaggo/swag v1.16.3
golang.org/x/crypto v0.20.0
golang.org/x/crypto v0.21.0
golang.org/x/text v0.14.0
gorm.io/driver/postgres v1.5.6
gorm.io/driver/postgres v1.5.7
gorm.io/gorm v1.25.7
)

Expand Down Expand Up @@ -75,7 +75,7 @@ require (
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/tools v0.18.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
16 changes: 8 additions & 8 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/garrettladley/mattress v0.3.2 h1:JsWsEwjXzlJXX7F/Zzmq7Xby1VAwzTJGGvf7DXPj4Jk=
github.com/garrettladley/mattress v0.3.2/go.mod h1:OWKIRc9wC3gtD3Ng/nUuNEiR1TJvRYLmn/KZYw9nl5Q=
github.com/garrettladley/mattress v0.4.0 h1:ZB3iqyc5q6bqIryNfsh2FMcbMdnV1XEryvqivouceQE=
github.com/garrettladley/mattress v0.4.0/go.mod h1:OWKIRc9wC3gtD3Ng/nUuNEiR1TJvRYLmn/KZYw9nl5Q=
github.com/go-openapi/jsonpointer v0.20.2 h1:mQc3nmndL8ZBzStEo3JYF8wzmeWffDH4VbXz58sAx6Q=
github.com/go-openapi/jsonpointer v0.20.2/go.mod h1:bHen+N0u1KEO3YlmqOjTT9Adn1RfD91Ar825/PuiRVs=
github.com/go-openapi/jsonreference v0.20.4 h1:bKlDxQxQJgwpUSgOENiMPzCTBVuc7vTdXSSgNeAhojU=
Expand Down Expand Up @@ -148,8 +148,8 @@ go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.20.0 h1:jmAMJJZXr5KiCw05dfYK9QnqaqKLYXijU23lsEdcQqg=
golang.org/x/crypto v0.20.0/go.mod h1:Xwo95rrVNIoSMx9wa1JroENMToLWn3RNVrTBpLHgZPQ=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
Expand All @@ -175,8 +175,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
Expand All @@ -201,7 +201,7 @@ gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/postgres v1.5.6 h1:ydr9xEd5YAM0vxVDY0X139dyzNz10spDiDlC7+ibLeU=
gorm.io/driver/postgres v1.5.6/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA=
gorm.io/driver/postgres v1.5.7 h1:8ptbNJTDbEmhdr62uReG5BGkdQyeasu/FZHxI0IMGnM=
gorm.io/driver/postgres v1.5.7/go.mod h1:3e019WlBaYI5o5LIdNV+LyxCMNtLOQETBXL2h4chKpA=
gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
1 change: 1 addition & 0 deletions backend/src/controllers/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func NewCategoryController(categoryService services.CategoryServiceInterface) *C
// @Failure 400 {string} errors.Error
// @Failure 401 {string} errors.Error
// @Failure 404 {string} errors.Error
// @Failure 409 {string} errors.Error
// @Failure 500 {string} errors.Error
// @Router /categories/ [post]
func (cat *CategoryController) CreateCategory(c *fiber.Ctx) error {
Expand Down
1 change: 1 addition & 0 deletions backend/src/controllers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func NewUserController(userService services.UserServiceInterface) *UserControlle
// @Failure 400 {object} errors.Error
// @Failure 401 {object} errors.Error
// @Failure 404 {object} errors.Error
// @Failure 409 {object} errors.Error
// @Failure 500 {object} errors.Error
// @Router /users/ [post]
func (u *UserController) CreateUser(c *fiber.Ctx) error {
Expand Down
3 changes: 2 additions & 1 deletion backend/src/controllers/user_follower.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controllers

import (
"github.com/GenerateNU/sac/backend/src/services"
"github.com/GenerateNU/sac/backend/src/utilities"
"github.com/gofiber/fiber/v2"
)

Expand Down Expand Up @@ -33,7 +34,7 @@ func (uf *UserFollowerController) CreateFollowing(c *fiber.Ctx) error {
if err != nil {
return err.FiberError(c)
}
return c.SendStatus(fiber.StatusCreated)
return utilities.FiberMessage(c, fiber.StatusCreated, "Successfully followed club")
}

// DeleteFollowing godoc
Expand Down
3 changes: 2 additions & 1 deletion backend/src/controllers/user_member.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controllers

import (
"github.com/GenerateNU/sac/backend/src/services"
"github.com/GenerateNU/sac/backend/src/utilities"
"github.com/gofiber/fiber/v2"
)

Expand Down Expand Up @@ -34,7 +35,7 @@ func (um *UserMemberController) CreateMembership(c *fiber.Ctx) error {
return err.FiberError(c)
}

return c.SendStatus(fiber.StatusCreated)
return utilities.FiberMessage(c, fiber.StatusCreated, "Successfully joined club")
}

// DeleteMembership godoc
Expand Down
28 changes: 21 additions & 7 deletions backend/src/database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func MigrateDB(settings config.Settings, db *gorm.DB) error {
return err
}

// Check if the database already has a super user
var superUser models.User
if err := db.Where("role = ?", models.Super).First(&superUser).Error; err != nil {
if err := createSuperUser(settings, db); err != nil {
Expand All @@ -112,26 +111,30 @@ func createSuperUser(settings config.Settings, db *gorm.DB) error {
var user models.User

if err := db.Where("nuid = ?", superUser.NUID).First(&user).Error; err != nil {
tx := db.Begin()
tx := db.Begin().Session(&gorm.Session{SkipHooks: true})

if err := tx.Error; err != nil {
return err
}

if err := tx.Create(&superUser).Error; err != nil {
superClub := SuperClub()
if err := tx.Create(&superClub).Error; err != nil {
tx.Rollback()
return err
}

SuperUserUUID = superUser.ID

superClub := SuperClub()
if err := tx.Model(&superClub).Update("num_members", gorm.Expr("num_members + 1")).Error; err != nil {
tx.Rollback()
return err
}

if err := tx.Create(&superClub).Error; err != nil {
if err := tx.Create(&superUser).Error; err != nil {
tx.Rollback()
return err
}

SuperUserUUID = superUser.ID

membership := models.Membership{
ClubID: superClub.ID,
UserID: superUser.ID,
Expand All @@ -143,7 +146,18 @@ func createSuperUser(settings config.Settings, db *gorm.DB) error {
return err
}

follower := models.Follower{
ClubID: superClub.ID,
UserID: superUser.ID,
}

if err := tx.Create(&follower).Error; err != nil {
tx.Rollback()
return err
}

return tx.Commit().Error
}

return nil
}
8 changes: 8 additions & 0 deletions backend/src/errors/club.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,12 @@ var (
StatusCode: fiber.StatusInternalServerError,
Message: "failed to get club events",
}
FailedToJoinClub = Error{
StatusCode: fiber.StatusInternalServerError,
Message: "failed to join club",
}
AlreadyMemberOfClub = Error{
StatusCode: fiber.StatusBadRequest,
Message: "already member of club",
}
)
4 changes: 4 additions & 0 deletions backend/src/errors/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ var (
StatusCode: fiber.StatusNotFound,
Message: "user not following club",
}
FailedToFollowClub = Error{
StatusCode: fiber.StatusInternalServerError,
Message: "failed to follow club",
}
)
12 changes: 1 addition & 11 deletions backend/src/models/club.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ 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"`
Name string `gorm:"type:varchar(255);unique" json:"name" validate:"required,max=255"`
Preview string `gorm:"type:varchar(255)" json:"preview" validate:"required,max=255"`
Description string `gorm:"type:varchar(255)" json:"description" validate:"required,http_url,mongo_url,max=255"` // MongoDB URL
NumMembers int `gorm:"type:int" json:"num_members" validate:"required,min=1"`
Expand Down Expand Up @@ -114,16 +114,6 @@ func (cqp *ClubQueryParams) IntoWhere() string {
return "WHERE " + strings.Join(conditions, " AND ")
}

func (c *Club) AfterCreate(tx *gorm.DB) (err error) {
tx.Model(&c).Update("num_members", c.NumMembers+1)
return
}

func (c *Club) AfterDelete(tx *gorm.DB) (err error) {
tx.Model(&c).Update("num_members", c.NumMembers-1)
return
}

func (c *Club) SearchId() string {
return c.ID.String()
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/models/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Series struct {

// TODO: add not null to required fields on all gorm models
type EventSeries struct {
EventID uuid.UUID `gorm:"not null; type:uuid; primary_key;" json:"event_id" validate:"uuid4"`
EventID uuid.UUID `gorm:"not null; type:uuid; primaryKey;" 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"`
Series Series `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
Expand Down
17 changes: 17 additions & 0 deletions backend/src/models/follower.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package models

import (
"github.com/google/uuid"
)

func (Follower) TableName() string {
return "user_club_followers"
}

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"`

Club *Club `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
User *User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
}
14 changes: 5 additions & 9 deletions backend/src/models/membership.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package models

import "github.com/google/uuid"
import (
"github.com/google/uuid"
)

type MembershipType string

Expand All @@ -9,19 +11,13 @@ const (
MembershipTypeAdmin MembershipType = "admin"
)

type Tabler interface {
TableName() string
}

func (Membership) TableName() string {
return "user_club_members"
}

type Membership struct {
Model

UserID uuid.UUID `gorm:"type:uuid;not null" json:"user_id" validate:"required,uuid4"`
ClubID uuid.UUID `gorm:"type:uuid;not null" json:"club_id" validate:"required,uuid4"`
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"`

Club *Club `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
User *User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"-" validate:"-"`
Expand Down
6 changes: 5 additions & 1 deletion backend/src/models/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import (
"github.com/google/uuid"
)

type Tabler interface {
TableName() string
}

type Model struct {
ID uuid.UUID `gorm:"type:uuid;primary_key;default:uuid_generate_v4()" json:"id" example:"123e4567-e89b-12d3-a456-426614174000"`
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"`
}
Loading

0 comments on commit c2e1633

Please sign in to comment.