Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Generate NEU committed Jun 17, 2024
1 parent 772681d commit 9f82213
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 28 deletions.
7 changes: 4 additions & 3 deletions backend/config/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package config
import "fmt"

type ApplicationSettings struct {
Port uint16 `env:"PORT"`
Host string `env:"HOST"`
BaseUrl string `env:"BASE_URL"`
Port uint16 `env:"PORT"`
Host string `env:"HOST"`
BaseUrl string `env:"BASE_URL"`
PublicUrl string `env:"PUBLIC_URL"`
}

func (s *ApplicationSettings) ApplicationURL() string {
Expand Down
16 changes: 8 additions & 8 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/GenerateNU/sac/backend/integrations/email"
"github.com/GenerateNU/sac/backend/integrations/file"
"github.com/GenerateNU/sac/backend/integrations/oauth/soth/sothic"
"github.com/GenerateNU/sac/backend/search"
"github.com/GenerateNU/sac/backend/server"
"github.com/GenerateNU/sac/backend/telemetry"
"github.com/GenerateNU/sac/backend/utilities"
Expand Down Expand Up @@ -97,14 +98,13 @@ func checkServerRunning(host string, port uint16) error {
}

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
// }
if err := search.SeedClubs(db); err != nil {
return
}

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

func startBackgroundJobs(ctx context.Context, db *gorm.DB) {
Expand Down
4 changes: 2 additions & 2 deletions backend/redis_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

# set up redis configuration directory
mkdir -p /usr/local/etc/redis
Expand All @@ -12,7 +12,7 @@ if [ -n ${REDIS_USERNAME} ] && [ -n ${REDIS_PASSWORD} ]; then
fi

# disable default user
if [ $(echo ${REDIS_DISABLE_DEFAULT_USER}) == "true" ]; then
if [ "$REDIS_DISABLE_DEFAULT_USER" == "true" ]; then
echo "user default off nopass nocommands" >> /usr/local/etc/redis/custom_aclfile.acl
fi

Expand Down
6 changes: 6 additions & 0 deletions backend/search/base/controller.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package base

import (
"log"
"net/http"
"os"

search_types "github.com/GenerateNU/sac/backend/search/types"
"github.com/GenerateNU/sac/backend/utilities"
Expand Down Expand Up @@ -30,14 +32,18 @@ func NewSearchController(searchService SearchServiceInterface) *SearchController
// @Failure 500 {object} error
// @Router /search/clubs [get]
func (s *SearchController) SearchClubs(c *fiber.Ctx) error {
log.SetOutput(os.Stdout)

var searchQuery search_types.ClubSearchRequest

log.Println("RAHHHHHH")
if err := c.BodyParser(&searchQuery); err != nil {
return utilities.InvalidJSON()
}

result, err := s.searchService.SearchClubs(searchQuery)
if err != nil {
log.Println("RAHHHHHH XD")
return err
}

Expand Down
12 changes: 10 additions & 2 deletions backend/search/base/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package base
import (
"fmt"
"io"
"log"
"log/slog"
"net/http"

Expand All @@ -18,16 +19,21 @@ import (
func doSearchGetRequest[T, V any](url string, requestBody T) (*V, error) {
payload, err := json.Marshal(requestBody)
if err != nil {
log.Println("json marshal failed")
return nil, err
}

resp, err := utilities.Request(http.MethodGet, fmt.Sprintf("%s%s", constants.SEARCH_URI, url), payload, utilities.JSON())
if err != nil {
log.Println("response failed")
return nil, err
}
defer resp.Body.Close()

responseBody, err := io.ReadAll(resp.Body)
log.Println("response body VVV")
log.Println(string(responseBody))

if err != nil {
return nil, err
}
Expand All @@ -44,7 +50,8 @@ func doSearchGetRequest[T, V any](url string, requestBody T) (*V, error) {
func Search[T types.Searchable](db *gorm.DB, query types.SearchRequest) (*types.SearchResult[T], error) {
result, err := doSearchGetRequest[types.SearchEndpointRequest, types.SearchEndpointResponse](fmt.Sprintf("/%s/_search", query.Index()), query.ToSearchEndpointRequest())
if err != nil {
return nil, nil
log.Println("dosearchgetrequest failed")
return nil, err
}

ids := make([]string, len(result.Hits.Hits))
Expand All @@ -55,7 +62,8 @@ func Search[T types.Searchable](db *gorm.DB, query types.SearchRequest) (*types.
var results []T

if err = query.Preload(db).Where("id IN ?", ids).Find(&results).Error; err != nil {
return nil, nil
log.Println("query preload failed")
return nil, err
}

return &types.SearchResult[T]{
Expand Down
6 changes: 4 additions & 2 deletions backend/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ func Init(db *gorm.DB, stores *store.Stores, integrations integrations.Integrati

applicationURL := settings.Application.ApplicationURL()

msftProvider := msft.New(settings.Microsft.Key, settings.Microsft.Secret, fmt.Sprintf("%s/api/v1/auth/microsoftonline/callback", applicationURL), settings.Microsft.Tenant)
googProvider := goog.New(settings.Google.Key, settings.Google.Secret, fmt.Sprintf("%s/api/v1/auth/google/callback", applicationURL))
publicURL := settings.Application.PublicUrl

msftProvider := msft.New(settings.Microsft.Key, settings.Microsft.Secret, fmt.Sprintf("%s/api/v1/auth/microsoftonline/callback", publicURL), settings.Microsft.Tenant)
googProvider := goog.New(settings.Google.Key, settings.Google.Secret, fmt.Sprintf("%s/api/v1/auth/google/callback", publicURL))

authMiddleware := authMiddleware.New(
db,
Expand Down
1 change: 1 addition & 0 deletions config/.env.template
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
SAC_APPLICATION_PORT="8080"
SAC_APPLICATION_HOST="127.0.0.1"
SAC_APPLICATION_BASE_URL="http://127.0.0.1"
SAC_APPLICATION_PUBLIC_URL="http://127.0.0.1"

SAC_DB_USERNAME="postgres"
SAC_DB_PASSWORD="password"
Expand Down
2 changes: 1 addition & 1 deletion deployment/Caddyfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sac.tech0tron.net {
studentactivitycalendar.xyz {
reverse_proxy sac_webserver:8080
}
16 changes: 6 additions & 10 deletions deployment/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ services:
dockerfile: ../backend/Dockerfile.redis
container_name: redis_session
ports:
- 6380:6379
- "6379"
environment:
- REDIS_USERNAME=${SAC_REDIS_SESSION_USERNAME}
- REDIS_PASSWORD=${SAC_REDIS_SESSION_PASSWORD}
Expand All @@ -42,8 +42,8 @@ services:
context: ../backend
dockerfile: ../backend/Dockerfile.redis
container_name: redis_limiter
ports:
- 6381:6379
expose:
- "6379"
environment:
- REDIS_USERNAME=${SAC_REDIS_LIMITER_USERNAME}
- REDIS_PASSWORD=${SAC_REDIS_LIMITER_PASSWORD}
Expand Down Expand Up @@ -74,8 +74,9 @@ services:
ports:
- 9200:9200
- 9600:9600 # required for Performance Analyzer
networks:
- opensearch-net
expose:
- "9200"
- "9600"
opensearch-dashboards:
image: opensearchproject/opensearch-dashboards:latest
container_name: opensearch-dashboards
Expand All @@ -86,8 +87,6 @@ services:
environment:
OPENSEARCH_HOSTS: '["http://opensearch-node1:9200"]'
DISABLE_SECURITY_DASHBOARDS_PLUGIN: true
networks:
- opensearch-net

volumes:
redis-session-data:
Expand All @@ -96,6 +95,3 @@ volumes:
caddy_data:
external: true
caddy_config:

networks:
opensearch-net:

0 comments on commit 9f82213

Please sign in to comment.