Skip to content

Commit

Permalink
more cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-brennan2005 committed Jun 18, 2024
1 parent 77fd3d1 commit 19e3253
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 97 deletions.
9 changes: 0 additions & 9 deletions backend/constants/search.go

This file was deleted.

27 changes: 0 additions & 27 deletions backend/entities/models/club.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,3 @@ type Club struct {
Event []Event `gorm:"many2many:club_events;" json:"-"`
Notification []Notification `gorm:"polymorphic:Reference;" json:"-"`
}

type ClubSearchDocument struct {
Name string `json:"name"`
Preview string `json:"preview"`
Description string `json:"description"`
NumMembers int `json:"num_members"`
Tags []string `json:"tags"`
}

func (c *Club) ToSearchDocument() interface{} {
tagIds := make([]string, len(c.Tag))
for i, tag := range c.Tag {
tagIds[i] = tag.ID.String()
}

return ClubSearchDocument{
Name: c.Name,
Preview: c.Preview,
Description: c.Description,
NumMembers: c.NumMembers,
Tags: tagIds,
}
}

func (c Club) Preload(db *gorm.DB) *gorm.DB {
return db.Preload("Tag")
}
40 changes: 0 additions & 40 deletions backend/entities/models/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

"github.com/google/uuid"
"gorm.io/gorm"
)

type EventType string
Expand Down Expand Up @@ -48,42 +47,3 @@ type Event struct {
Tag []Tag `gorm:"many2many:event_tags;" json:"-"`
Notification []Notification `gorm:"polymorphic:Reference;" json:"-"`
}

// How Events are represented in the OpenSearch index.
type EventSearchDocument struct {
Name string `json:"name"`
Preview string `json:"preview"`
Description string `json:"description"`
EventType EventType `json:"event_type"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Clubs []string `json:"clubs"`
Tags []string `json:"tags"`
}

func (c *Event) ToSearchDocument() interface{} {
tagIds := make([]string, len(c.Tag))
for i, tag := range c.Tag {
tagIds[i] = tag.ID.String()
}

clubIds := make([]string, len(c.Clubs))
for i, club := range c.Clubs {
clubIds[i] = club.ID.String()
}

return EventSearchDocument{
Name: c.Name,
Preview: c.Preview,
Description: c.Description,
EventType: c.EventType,
StartTime: c.StartTime,
EndTime: c.EndTime,
Tags: tagIds,
Clubs: clubIds,
}
}

func (c Event) Preload(db *gorm.DB) *gorm.DB {
return db.Preload("Tag").Preload("Club")
}
23 changes: 2 additions & 21 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/GenerateNU/sac/backend/background"
"github.com/GenerateNU/sac/backend/background/jobs"
"github.com/GenerateNU/sac/backend/config"
"github.com/GenerateNU/sac/backend/constants"
"github.com/GenerateNU/sac/backend/database"
"github.com/GenerateNU/sac/backend/database/store"

Expand All @@ -35,14 +34,12 @@ import (
)

func main() {
onlyMigrate, seedSearch, configPath := parseFlags()
onlyMigrate, configPath := parseFlags()
config, err := config.GetConfiguration(*configPath)
if err != nil {
utilities.Exit("Error getting configuration: %s", err.Error())
}

constants.SEARCH_URI = config.Search.URI

if checkServerRunning(config.Application.Host, config.Application.Port) == nil {
utilities.Exit("A server is already running on %s:%d.\n", config.Application.Host, config.Application.Port)
}
Expand All @@ -58,10 +55,6 @@ func main() {
return
}

if *seedSearch {
seedSearchData(db)
}

if err := database.ConnPooling(db); err != nil {
utilities.Exit("Error with connection pooling: %s", err.Error())
}
Expand All @@ -82,9 +75,8 @@ func main() {
waitForShutdown(app)
}

func parseFlags() (onlyMigrate, seedSearch *bool, configPath *string) {
func parseFlags() (onlyMigrate *bool, configPath *string) {
onlyMigrate = flag.Bool("only-migrate", false, "Specify if you want to only perform the database migration")
seedSearch = flag.Bool("seed-search", true, "Specify if you want to seed the opensearch nodes.")
configPath = flag.String("config", filepath.Join("..", "config", ".env.dev"), "Specify the path to the config file (.env)")
flag.Parse()
return
Expand All @@ -100,17 +92,6 @@ func checkServerRunning(host string, port uint16) error {
return nil
}

func seedSearchData(db *gorm.DB) {
slog.Info("to appease linter", "seedSearch", true, "db", db)
// if err := search.SeedClubs(db); err != nil {
// return
// }

// if err := search.SeedEvents(db); err != nil {
// return
// }
}

func startBackgroundJobs(ctx context.Context, db *gorm.DB) {
jobs := jobs.New(db)
background.Go(jobs.WelcomeSender(ctx))
Expand Down

0 comments on commit 19e3253

Please sign in to comment.