Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .devcontainer/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM mcr.microsoft.com/devcontainers/go:2-1.25-trixie

RUN go install github.com/pressly/goose/v3/cmd/goose@latest
RUN go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
RUN go install go install github.com/hieunguyent12/swag/v2/cmd/swag@bcae90f384b937c1c47dbe9b5d8e7ba8cbe96aac
25 changes: 25 additions & 0 deletions .devcontainer/api/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
{
"name": "api-devcontainer",
"dockerComposeFile": ["../../docker-compose.yml"],
"service": "api-devcontainer",
"shutdownAction": "none",
"workspaceFolder": "/core/apps/api",
"features": {
"ghcr.io/devcontainers/features/git:1": {}
},


// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
3 changes: 3 additions & 0 deletions .devcontainer/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM mcr.microsoft.com/devcontainers/typescript-node:4-24-trixie

RUN npm install -g pnpm
26 changes: 26 additions & 0 deletions .devcontainer/web/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/typescript-node
{
"name": "web-devcontainer",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
// "image": "mcr.microsoft.com/devcontainers/typescript-node:4-24-trixie",
"dockerComposeFile": ["../../docker-compose.yml"],
"service": "web-devcontainer",
"shutdownAction": "none",
"workspaceFolder": "/core/apps/web",
"features": {
"ghcr.io/devcontainers/features/git:1": {}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "pnpm i",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
"remoteUser": "root"
}
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
4 changes: 2 additions & 2 deletions .github/workflows/sqlc_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v4
- uses: sqlc-dev/setup-sqlc@v3
with:
sqlc-version: '1.29.0'
sqlc-version: '1.30.0'
- run: sqlc diff

vet:
Expand All @@ -26,7 +26,7 @@ jobs:
- uses: actions/checkout@v4
- uses: sqlc-dev/setup-sqlc@v3
with:
sqlc-version: '1.29.0'
sqlc-version: '1.30.0'
# Start a PostgreSQL server
- uses: sqlc-dev/action-setup-postgres@master
with:
Expand Down
2 changes: 1 addition & 1 deletion apps/api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.25-alpine AS builder
FROM golang:1.26-alpine AS builder

RUN apk add --no-cache build-base ca-certificates

Expand Down
19 changes: 12 additions & 7 deletions apps/api/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
include .env.dev

migrate-up:
@goose -dir ./internal/db/migrations postgres ${DATABASE_URL_MIGRATION} up
@goose -dir ./internal/database/migrations postgres ${DATABASE_URL_MIGRATION} up

migrate-down:
@goose -dir ./internal/db/migrations postgres ${DATABASE_URL_MIGRATION} down
@goose -dir ./internal/database/migrations postgres ${DATABASE_URL_MIGRATION} down

# Use this command when developing inside a dev container.
# Maybe we could figure out a way to connect directly to the host's localhost, instead of using docker network to connect to the postgres db
migrate-up-devcontainer:
@goose -dir ./internal/database/migrations postgres ${DATABASE_URL} up

migrate-down-devcontainer:
@goose -dir ./internal/database/migrations postgres ${DATABASE_URL} down

generate:
@sqlc generate

openapi-generate:
swag init --dir cmd/api,internal/api/handlers --parseDependency --requiredByDefault -v3.1

openapi-format:
swag f --dir cmd/api,internal/api/handlers
generate-openapi:
chmod +x download-openapi.sh && ./download-openapi.sh
2 changes: 1 addition & 1 deletion apps/api/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.0
v1.0.0
2 changes: 1 addition & 1 deletion apps/api/cmd/BAT_worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.25-alpine AS base
FROM golang:1.26-alpine AS base

WORKDIR /app

Expand Down
41 changes: 23 additions & 18 deletions apps/api/cmd/BAT_worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import (

"github.com/hibiken/asynq"
"github.com/swamphacks/core/apps/api/internal/config"
"github.com/swamphacks/core/apps/api/internal/db"
"github.com/swamphacks/core/apps/api/internal/db/repository"
"github.com/swamphacks/core/apps/api/internal/email"
"github.com/swamphacks/core/apps/api/internal/database"
"github.com/swamphacks/core/apps/api/internal/database/repository"
"github.com/swamphacks/core/apps/api/internal/domains/application"
"github.com/swamphacks/core/apps/api/internal/domains/bat"
"github.com/swamphacks/core/apps/api/internal/domains/email"
"github.com/swamphacks/core/apps/api/internal/domains/hackathon"
"github.com/swamphacks/core/apps/api/internal/emailutils"
"github.com/swamphacks/core/apps/api/internal/logger"
"github.com/swamphacks/core/apps/api/internal/services"
"github.com/swamphacks/core/apps/api/internal/storage"
"github.com/swamphacks/core/apps/api/internal/tasks"
"github.com/swamphacks/core/apps/api/internal/workers"
)
Expand All @@ -34,7 +38,7 @@ V V V }' `\ /' `{ V V V

func main() {
logger := logger.New()
cfg := config.Load()
cfg := config.LoadConfig()

redisOpt, err := asynq.ParseRedisURI(cfg.RedisURL)
if err != nil {
Expand Down Expand Up @@ -70,23 +74,24 @@ func main() {
taskQueueClient := asynq.NewClient(redisOpt)
defer taskQueueClient.Close()

database := db.NewDB(cfg.DatabaseURL)
defer database.Close()
db := database.NewDB(cfg.DatabaseURL)
defer db.Close()

txm := db.NewTransactionManager(database)
txm := database.NewTransactionManager(db)

applicationRepo := repository.NewApplicationRepository(database)
eventRepo := repository.NewEventRespository(database)
userRepo := repository.NewUserRepository(database)
eventService := services.NewEventService(eventRepo, userRepo, nil, nil, logger)
batRunsRepo := repository.NewBatRunsRepository(database)
hackathonRepo := repository.NewHackathonRepository(db)
applicationRepo := repository.NewApplicationRepository(db)
userRepo := repository.NewUserRepository(db)
batRunsRepo := repository.NewBatRunsRepository(db)
eventInterestsRepo := repository.NewEventInterestsRepository(db)

sesClient := email.NewSESClient(cfg.AWS.AccessKey, cfg.AWS.AccessKeySecret, cfg.AWS.Region, logger)
emailService := services.NewEmailService(taskQueueClient, sesClient, nil, logger)
batService := services.NewBatService(applicationRepo, eventRepo, userRepo, batRunsRepo, emailService, txm, nil, scheduler, logger)
applicationService := services.NewApplicationService(applicationRepo, userRepo, eventService, emailService, txm, nil, nil, scheduler, logger)
sesClient := emailutils.NewSESClient(cfg.AWS.AccessKey, cfg.AWS.AccessKeySecret, cfg.AWS.Region, logger)
emailService := email.NewEmailService(hackathonRepo, userRepo, taskQueueClient, sesClient, nil, logger, cfg)
batService := bat.NewBatService(applicationRepo, hackathonRepo, userRepo, batRunsRepo, emailService, txm, nil, scheduler, cfg, logger)
applicationService := application.NewService(applicationRepo, userRepo, hackathonRepo, txm, nil, nil, scheduler, emailService, batService, cfg, logger)
hackathonService := hackathon.NewService(hackathonRepo, userRepo, eventInterestsRepo, &storage.R2Client{}, nil, logger)

BATWorker := workers.NewBATWorker(batService, applicationService, eventService, scheduler, taskQueueClient, logger)
BATWorker := workers.NewBATWorker(batService, applicationService, hackathonService, scheduler, taskQueueClient, cfg, logger)

mux := asynq.NewServeMux()
mux.HandleFunc(tasks.TypeCalculateAdmissions, BATWorker.HandleCalculateAdmissionsTask)
Expand Down
114 changes: 1 addition & 113 deletions apps/api/cmd/api/main.go
Original file line number Diff line number Diff line change
@@ -1,121 +1,9 @@
package main

import (
"net/http"
"time"

"github.com/hibiken/asynq"
"github.com/rs/zerolog/log"
"github.com/swamphacks/core/apps/api/internal/api"
"github.com/swamphacks/core/apps/api/internal/api/handlers"
"github.com/swamphacks/core/apps/api/internal/api/middleware"
"github.com/swamphacks/core/apps/api/internal/config"
"github.com/swamphacks/core/apps/api/internal/db"
"github.com/swamphacks/core/apps/api/internal/db/repository"
"github.com/swamphacks/core/apps/api/internal/email"
"github.com/swamphacks/core/apps/api/internal/logger"
"github.com/swamphacks/core/apps/api/internal/services"
"github.com/swamphacks/core/apps/api/internal/storage"
)

// @title SwampHacks Test API
// @version 1.0
// @description This is SwampHacks' OpenAPI documentation.
// @termsOfService TODO

// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
func main() {
logger := logger.New()
cfg := config.Load()

// Init database connection and defer close
database := db.NewDB(cfg.DatabaseURL)
defer database.Close()

// Create transaction manager
txm := db.NewTransactionManager(database)

// Create injectable http client
client := &http.Client{
Timeout: 10 * time.Second,
Transport: &http.Transport{
MaxIdleConns: 100,
MaxIdleConnsPerHost: 10,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
},
}

// Create SES Client for email service
sesClient := email.NewSESClient(cfg.AWS.AccessKey, cfg.AWS.AccessKeySecret, cfg.AWS.Region, logger)

// Create asynq client
redisOpt, err := asynq.ParseRedisURI(cfg.RedisURL)
if err != nil {
logger.Fatal().Msg("Failed to parse REDIS_URL")
}
taskQueueClient := asynq.NewClient(redisOpt)

// Create new middleware injectable
mw := middleware.NewMiddleware(database, logger, cfg)

// Initialize storage clients
r2Client, err := storage.NewR2Client(cfg.CF.AccountID, cfg.CF.AccessKeyId, cfg.CF.AccessKeySecret, logger)
if err != nil {
logger.Fatal().Err(err).Msg("Failed to create R2 client")
}

// Injections into repositories
userRepo := repository.NewUserRepository(database)
accountRepo := repository.NewAccountRespository(database)
sessionRepo := repository.NewSessionRepository(database)
eventInterestRepo := repository.NewEventInterestRepository(database)
eventRepo := repository.NewEventRespository(database)
applicationRepo := repository.NewApplicationRepository(database)
teamRepo := repository.NewTeamRespository(database)
teamMemberRepo := repository.NewTeamMemberRespository(database)
teamJoinRequestRepo := repository.NewTeamJoinRequestRepository(database)
batRunsRepo := repository.NewBatRunsRepository(database)
redeemablesRepo := repository.NewRedeemablesRepository(database)

// Injections into services
authService := services.NewAuthService(userRepo, accountRepo, sessionRepo, txm, client, logger, &cfg.Auth)
userService := services.NewUserService(userRepo, logger)
eventInterestService := services.NewEventInterestService(eventInterestRepo, logger)
eventService := services.NewEventService(eventRepo, userRepo, r2Client, &cfg.CoreBuckets, logger)
emailService := services.NewEmailService(taskQueueClient, sesClient, r2Client, logger)
applicationService := services.NewApplicationService(applicationRepo, userRepo, eventService, emailService, txm, r2Client, &cfg.CoreBuckets, nil, logger)
teamService := services.NewTeamService(teamRepo, teamMemberRepo, teamJoinRequestRepo, eventRepo, txm, logger)
batService := services.NewBatService(applicationRepo, eventRepo, userRepo, batRunsRepo, emailService, txm, taskQueueClient, nil, logger)
redeemablesService := services.NewRedeemablesService(redeemablesRepo, logger)
discordService := services.NewDiscordService(eventRepo, logger)

// Injections into handlers
apiHandlers := handlers.NewHandlers(
authService,
userService,
eventInterestService,
eventService,
emailService,
applicationService,
teamService,
batService,
redeemablesService,
discordService,
cfg,
logger,
)

api := api.NewAPI(&logger, apiHandlers, mw)

logger.Info().Msgf("API listening on port %s", cfg.Port)
if err := http.ListenAndServe(":"+cfg.Port, api.Router); err != nil {
log.Fatal().Msg("Failed to start server.")
}
api.Run()
}
2 changes: 1 addition & 1 deletion apps/api/cmd/email_worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.25-alpine AS base
FROM golang:1.26-alpine AS base

WORKDIR /app

Expand Down
21 changes: 16 additions & 5 deletions apps/api/cmd/email_worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import (

"github.com/hibiken/asynq"
"github.com/swamphacks/core/apps/api/internal/config"
"github.com/swamphacks/core/apps/api/internal/email"
"github.com/swamphacks/core/apps/api/internal/database"
"github.com/swamphacks/core/apps/api/internal/database/repository"
"github.com/swamphacks/core/apps/api/internal/domains/email"
"github.com/swamphacks/core/apps/api/internal/emailutils"
"github.com/swamphacks/core/apps/api/internal/logger"
"github.com/swamphacks/core/apps/api/internal/services"
"github.com/swamphacks/core/apps/api/internal/tasks"
"github.com/swamphacks/core/apps/api/internal/workers"
)

func main() {
logger := logger.New()
cfg := config.Load()
cfg := config.LoadConfig()

redisOpt, err := asynq.ParseRedisURI(cfg.RedisURL)
if err != nil {
Expand All @@ -38,10 +40,19 @@ func main() {
},
)

taskQueueClient := asynq.NewClient(redisOpt)
defer taskQueueClient.Close()

db := database.NewDB(cfg.DatabaseURL)
defer db.Close()

hackathonRepo := repository.NewHackathonRepository(db)
userRepo := repository.NewUserRepository(db)

// Create ses client
sesClient := email.NewSESClient(cfg.AWS.AccessKey, cfg.AWS.AccessKeySecret, cfg.AWS.Region, logger)
sesClient := emailutils.NewSESClient(cfg.AWS.AccessKey, cfg.AWS.AccessKeySecret, cfg.AWS.Region, logger)

emailService := services.NewEmailService(nil, sesClient, nil, logger)
emailService := email.NewEmailService(hackathonRepo, userRepo, taskQueueClient, sesClient, nil, logger, cfg)
emailWorker := workers.NewEmailWorker(emailService, logger)

mux := asynq.NewServeMux()
Expand Down
Loading
Loading