Skip to content

Commit

Permalink
test: putContact
Browse files Browse the repository at this point in the history
  • Loading branch information
ojn03 committed Feb 5, 2024
1 parent abde0e8 commit 0ab3153
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 628 deletions.
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
13 changes: 7 additions & 6 deletions backend/src/models/contact.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ const (
type Contact struct {
Model

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

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

type PutContactRequestBody struct {
Type ContactType `gorm:"type:varchar(255)" json:"type" validate:"required,max=255"`
Content string `gorm:"type:varchar(255)" json:"content" validate:"required,url,max=255"`
ClubID uint `gorm:"foreignKey:ClubID" json:"-" validate:"min=1"`
Type ContactType `gorm:"type:varchar(255)" json:"type" validate:"required,max=255,oneof=facebook instagram twitter linkedin youtube github slack discord email customSite"`

//TODO content validator
Content string `gorm:"type:varchar(255)" json:"content" validate:"required,s3_url,max=255"`
}
6 changes: 1 addition & 5 deletions backend/src/services/club.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ func (c *ClubService) PutContact(clubID string, contactBody models.PutContactReq
if err != nil {
return nil, &errors.FailedToMapRequestToModel
}

if *idAsUUID != contact.ClubID {
return nil, &errors.FailedToUpdateContact
}

contact.ClubID = *idAsUUID
return transactions.PutContact(c.DB, *idAsUUID, *contact)
}

Expand Down
2 changes: 1 addition & 1 deletion backend/src/transactions/club.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func GetClubContacts(db *gorm.DB, id uuid.UUID) ([]models.Contact, *errors.Error

func PutContact(db *gorm.DB, clubID uuid.UUID, contact models.Contact) (*models.Contact, *errors.Error) {
err := db.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "type"}},
Columns: []clause.Column{{Name: "club_id"}, {Name: "type"}},
DoUpdates: clause.AssignmentColumns([]string{"content"}),
}).Create(&contact).Error
if err != nil {
Expand Down
Loading

0 comments on commit 0ab3153

Please sign in to comment.