Skip to content

Commit

Permalink
🧹 chore: make search url configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley committed May 28, 2024
1 parent 13b4e60 commit ec38a55
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
6 changes: 4 additions & 2 deletions backend/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Integrations struct {
OutlookOauth OAuthSettings
AWS AWSSettings
Resend ResendSettings
Search SearchSettings
}

type intermediateSettings struct {
Expand All @@ -27,11 +28,12 @@ type intermediateSettings struct {
RedisLimiter intermediateRedisSettings `envPrefix:"SAC_REDIS_LIMITER_"`
SuperUser intermediateSuperUserSettings `envPrefix:"SAC_SUDO_"`
Auth intermediateAuthSettings `envPrefix:"SAC_AUTH_"`
AWS intermediateAWSSettings `envPrefix:"SAC_AWS_"`
Resend intermediateResendSettings `envPrefix:"SAC_RESEND_"`
Calendar intermediateCalendarSettings `envPrefix:"SAC_CALENDAR_"`
GoogleSettings GoogleOAuthSettings `envPrefix:"SAC_GOOGLE_OAUTH"`
OutlookSettings OutlookOAuthSettings `envPrefix:"SAC_OUTLOOK_OAUTH"`
AWS intermediateAWSSettings `envPrefix:"SAC_AWS_"`
Resend intermediateResendSettings `envPrefix:"SAC_RESEND_"`
Search SearchSettings `env:"SAC_SEARCH"`
}

func (i *intermediateSettings) into() (*Settings, error) {
Expand Down
9 changes: 5 additions & 4 deletions backend/constants/search.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package constants

const (
SEARCH_URL = "http://127.0.0.1:9200"
CLUBS_INDEX = "clubs"
EVENTS_INDEX = "events"
SEARCH_QUERY_DEFAULT_MAX_MEMBERS = 16384
CLUBS_INDEX string = "clubs"
EVENTS_INDEX string = "events"
SEARCH_QUERY_DEFAULT_MAX_MEMBERS int = 16384
)

var SEARCH_URI string
3 changes: 3 additions & 0 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path/filepath"

"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"
_ "github.com/GenerateNU/sac/backend/docs"
Expand All @@ -32,6 +33,8 @@ func main() {
utilities.Exit("Error getting configuration: %s", err.Error())
}

constants.SEARCH_URI = config.Search.URI

err = checkServerRunning(config.Application.Host, config.Application.Port)
if err == nil {
utilities.Exit("A server is already running on %s:%d.\n", config.Application.Host, config.Application.Port)
Expand Down
6 changes: 3 additions & 3 deletions backend/search/base/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func doSearchGetRequest[T, V any](url string, requestBody T) (*V, error) {
return nil, err
}

resp, err := utilities.Request(http.MethodGet, fmt.Sprintf("%s%s", constants.SEARCH_URL, url), payload, utilities.JSON())
resp, err := utilities.Request(http.MethodGet, fmt.Sprintf("%s%s", constants.SEARCH_URI, url), payload, utilities.JSON())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -80,7 +80,7 @@ func Upsert[T types.Searchable](db *gorm.DB, index string, uuid string, model ty
return err
}

resp, err := utilities.Request(http.MethodPost, fmt.Sprintf("%s/%s/_update/%s", constants.SEARCH_URL, index, uuid), payload, utilities.JSON())
resp, err := utilities.Request(http.MethodPost, fmt.Sprintf("%s/%s/_update/%s", constants.SEARCH_URI, index, uuid), payload, utilities.JSON())
if err != nil {
return err
}
Expand All @@ -90,7 +90,7 @@ func Upsert[T types.Searchable](db *gorm.DB, index string, uuid string, model ty
}

func Delete(db *gorm.DB, index string, uuid string) error {
resp, err := utilities.Request(http.MethodDelete, fmt.Sprintf("%s/%s/_doc/%s", constants.SEARCH_URL, index, uuid), nil, utilities.JSON())
resp, err := utilities.Request(http.MethodDelete, fmt.Sprintf("%s/%s/_doc/%s", constants.SEARCH_URI, index, uuid), nil, utilities.JSON())
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions backend/search/seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func SeedClubs(db *gorm.DB) error {
stdout := os.Stdout

stdout.WriteString("Deleting existing club index...\n")
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/clubs", constants.SEARCH_URL), nil)
req, err := http.NewRequest("DELETE", fmt.Sprintf("%s/clubs", constants.SEARCH_URI), nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -58,7 +58,7 @@ func SeedClubs(db *gorm.DB) error {
requestBodyBuilder.WriteString(fmt.Sprintf("%s\n%s\n", indexJson, clubJson))
}

resp, err := utilities.Request(http.MethodPost, fmt.Sprintf("%s/_bulk", constants.SEARCH_URL), []byte(requestBodyBuilder.String()), utilities.JSON())
resp, err := utilities.Request(http.MethodPost, fmt.Sprintf("%s/_bulk", constants.SEARCH_URI), []byte(requestBodyBuilder.String()), utilities.JSON())
if err != nil {
stdout.WriteString(fmt.Sprintf("Error making _bulk request for club seeding: %s\n", err.Error()))
}
Expand All @@ -78,7 +78,7 @@ func SeedEvents(db *gorm.DB) error {
stdout := os.Stdout

stdout.WriteString("Deleting existing event index...\n")
resp, err := utilities.Request(http.MethodDelete, fmt.Sprintf("%s/events", constants.SEARCH_URL), nil, utilities.JSON())
resp, err := utilities.Request(http.MethodDelete, fmt.Sprintf("%s/events", constants.SEARCH_URI), nil, utilities.JSON())
if err != nil {
return err
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func SeedEvents(db *gorm.DB) error {
requestBodyBuilder.WriteString(fmt.Sprintf("%s\n%s\n", indexJson, eventJson))
}

resp, err = utilities.Request(http.MethodPost, fmt.Sprintf("%s/_bulk", constants.SEARCH_URL), []byte(requestBodyBuilder.String()), utilities.JSON())
resp, err = utilities.Request(http.MethodPost, fmt.Sprintf("%s/_bulk", constants.SEARCH_URI), []byte(requestBodyBuilder.String()), utilities.JSON())
if err != nil {
stdout.WriteString(fmt.Sprintf("Error making _bulk request for event seeding: %s\n", err.Error()))
}
Expand Down
1 change: 1 addition & 0 deletions config/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ GOOGLE_API_KEY=GOOGLE_API_KEY
OUTLOOK_OAUTH_CLIENT_ID=test
OUTLOOK_OAUTH_CLIENT_SECRET=test

SAC_SEARCH_URI=""http://127.0.0.1:9200"

0 comments on commit ec38a55

Please sign in to comment.