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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/api/.env.dev.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ AUTH_DISCORD_CLIENT_ID=
AUTH_DISCORD_CLIENT_SECRET=
AUTH_DISCORD_REDIRECT_URI="http://localhost:8080/auth/callback"

# CF
CORE_BUCKETS_USER_QRCODES_BASE_URL=

# For cookies
COOKIE_DOMAIN=localhost
COOKIE_SECURE=false
Expand Down
2 changes: 1 addition & 1 deletion apps/api/cmd/BAT_worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func main() {
batRunsRepo := repository.NewBatRunsRepository(database)

sesClient := email.NewSESClient(cfg.AWS.AccessKey, cfg.AWS.AccessKeySecret, cfg.AWS.Region, logger)
emailService := services.NewEmailService(taskQueueClient, sesClient, 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)

Expand Down
2 changes: 1 addition & 1 deletion apps/api/cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func main() {
userService := services.NewUserService(userRepo, logger)
eventInterestService := services.NewEventInterestService(eventInterestRepo, logger)
eventService := services.NewEventService(eventRepo, userRepo, r2Client, &cfg.CoreBuckets, logger)
emailService := services.NewEmailService(taskQueueClient, sesClient, 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)
Expand Down
2 changes: 1 addition & 1 deletion apps/api/cmd/email_worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
// Create ses client
sesClient := email.NewSESClient(cfg.AWS.AccessKey, cfg.AWS.AccessKeySecret, cfg.AWS.Region, logger)

emailService := services.NewEmailService(nil, sesClient, logger)
emailService := services.NewEmailService(nil, sesClient, nil, logger)
emailWorker := workers.NewEmailWorker(emailService, logger)

mux := asynq.NewServeMux()
Expand Down
1 change: 1 addition & 0 deletions apps/api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ require (
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/redis/go-redis/v9 v9.7.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/sv-tools/openapi v0.4.0 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
Expand Down
2 changes: 2 additions & 0 deletions apps/api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUz
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w=
github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
2 changes: 2 additions & 0 deletions apps/api/internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ func (api *API) setupRoutes(mw *mw.Middleware) {

// Admin-only
r.With(ensureEventAdmin).Post("/queue-confirmation-email", api.Handlers.Email.QueueConfirmationEmail)
r.With(ensureEventAdmin).Post("/queue-welcome-email", api.Handlers.Email.QueueWelcomeEmail)
r.With(ensureEventAdmin).Post("/send-welcome-emails", api.Handlers.Bat.SendWelcomeEmails)
r.With(ensureEventAdmin).Post("/calc-admissions", api.Handlers.Admission.HandleCalculateAdmissionsRequest)
r.With(ensureEventAdmin).Patch("/transition-waitlisted-applications", api.Handlers.Application.TransitionWaitlistedApplications)
r.With(ensureEventAdmin).Post("/begin-waitlist-transition", api.Handlers.Bat.QueueScheduleWaitlistTransitionTask)
Expand Down
26 changes: 26 additions & 0 deletions apps/api/internal/api/handlers/bat.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,29 @@ func (h *BatHandler) QueueShutdownWaitlistSchedulerTask(w http.ResponseWriter, r

res.Send(w, http.StatusOK, nil)
}

// Send welcome emails
//
// @Summary Sends welcome emails to attendees
// @Description
// @Tags
//
// @Param eventId path string true "ID of the event"
// @Success 200 "Welcome emails began to queue successfully"
// @Failure 400 {object} res.ErrorResponse "Bad request: invalid event ID"
// @Failure 500 {object} res.ErrorResponse "Server error: failed to begin queuing welcome emails"
// @Router /events/{eventId}/send-welcome-emails [post]
func (h *BatHandler) SendWelcomeEmails(w http.ResponseWriter, r *http.Request) {
eventId, err := web.PathParamToUUID(r, "eventId")
if err != nil {
res.SendError(w, http.StatusBadRequest, res.NewError("invalid_event_id", "The event ID is not valid."))
return
}

err = h.BatService.SendWelcomeEmailToAttendees(r.Context(), eventId)
if err != nil {
res.SendError(w, http.StatusInternalServerError, res.NewError("internal_err", "Failed to create ScheduleWaitlistTransition task."))
}

res.Send(w, http.StatusCreated, nil)
}
59 changes: 59 additions & 0 deletions apps/api/internal/api/handlers/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"

"github.com/go-playground/validator/v10"
"github.com/google/uuid"
"github.com/rs/zerolog"
res "github.com/swamphacks/core/apps/api/internal/api/response"
"github.com/swamphacks/core/apps/api/internal/email"
Expand Down Expand Up @@ -82,6 +83,18 @@ type QueueConfirmationEmailFields struct {
FirstName string `json:"firstName" validate:"required"`
}

// Queue a Confirmation Email
//
// @Summary Queue a Confirmation Email Request
// @Description Push a Confirmation Email request to the task queue
// @Tags Email
// @Accept json
// @Produce json
// @Param request body QueueConfirmationEmailFields true "Email data"
// @Success 201 {object} string "OK: Email request queued"
// @Failure 400 {object} response.ErrorResponse "Bad request/Malformed request. The email request is potentially invalid."
// @Failure 500 {object} response.ErrorResponse "Server Error: The server went kaput while queueing email sending"
// @Router /email/queue [post]
func (h *EmailHandler) QueueConfirmationEmail(w http.ResponseWriter, r *http.Request) {
var req QueueConfirmationEmailFields
decoder := json.NewDecoder(r.Body)
Expand All @@ -103,3 +116,49 @@ func (h *EmailHandler) QueueConfirmationEmail(w http.ResponseWriter, r *http.Req

res.Send(w, http.StatusOK, nil)
}

type QueueWelcomeEmailFields struct {
Email string `json:"email" validate:"required"`
FirstName string `json:"firstName" validate:"required"`
UserId string `json:userId validate:"required"`
}

// Queue a Welcome Email
//
// @Summary Queue a Welcome Email
// @Description Push an Welcome Email request to the task queue
// @Tags Email
// @Accept json
// @Produce json
// @Param request body QueueConfirmationEmailFields true "Email data"
// @Success 201 {object} string "OK: Email request queued"
// @Failure 400 {object} response.ErrorResponse "Bad request/Malformed request. The email request is potentially invalid."
// @Failure 500 {object} response.ErrorResponse "Server Error: The server went kaput while queueing email sending"
func (h *EmailHandler) QueueWelcomeEmail(w http.ResponseWriter, r *http.Request) {
var req QueueWelcomeEmailFields
decoder := json.NewDecoder(r.Body)
decoder.DisallowUnknownFields()
err := decoder.Decode(&req)
if err != nil {
res.SendError(w, http.StatusBadRequest, res.NewError("invalid_request", "Could not parse request body"))
return
}

validate := validator.New()
if err := validate.Struct(req); err != nil {
res.SendError(w, http.StatusBadRequest, res.NewError("invalid_request", err.Error()))
}

parsedUserId, err := uuid.Parse(req.UserId)
if err != nil {
res.SendError(w, http.StatusBadRequest, res.NewError("invalid_request", "userId must be of type uuid"))
return
}

err = h.emailService.QueueWelcomeEmail(r.Context(), req.Email, req.FirstName, parsedUserId)
if err != nil {
res.SendError(w, http.StatusInternalServerError, res.NewError("internal_err", "Hacker email could not be queued."))
}

res.Send(w, http.StatusOK, nil)
}
2 changes: 2 additions & 0 deletions apps/api/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ type AWSConfig struct {

type CoreBuckets struct {
Avatars string `env:"USER_AVATARS" envDefault:"core-user-avatars-dev"`
QRCodes string `env:"USER_QRCODES" envDefault:"core-user-qrcodes-dev"`
ApplicationResumes string `env:"APPLICATION_RESUMES" envDefault:"core-application-resumes-dev"`
EventAssets string `env:"EVENT_ASSETS" envDefault:"core-event-assets-dev"`
AvatarsBaseUrl string `env:"USER_AVATARS_BASE_URL"`
QRCodesBaseUrl string `env:"USER_QRCODES_BASE_URL"`
EventAssetsBaseUrl string `env:"EVENT_ASSETS_BASE_URL"`
}

Expand Down
7 changes: 6 additions & 1 deletion apps/api/internal/db/queries/event_roles.sql
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ SELECT COUNT(*) FROM event_roles AS er
WHERE er.event_id = @event_id::uuid
AND er.role = 'attendee';

-- name: GetAttendeeUserIdsByEventId :many
SELECT er.user_id FROM event_roles AS er
WHERE er.event_id = @event_id::uuid
AND er.role = 'attendee';

-- name: GetUserByRFID :one
SELECT u.*
FROM auth.users u
JOIN event_roles er ON u.id = er.user_id
WHERE er.event_id = $1
AND er.rfid = $2;
AND er.rfid = $2;
6 changes: 5 additions & 1 deletion apps/api/internal/db/repository/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,8 @@ func (r *EventRepository) GetEventRoleByDiscordIDAndEventId(ctx context.Context,
}

return &eventRole, nil
}
}

func (r *EventRepository) GetAttendeeUserIdsByEventId(ctx context.Context, eventID uuid.UUID) ([]uuid.UUID, error) {
return r.db.Query.GetAttendeeUserIdsByEventId(ctx, eventID)
}
26 changes: 26 additions & 0 deletions apps/api/internal/db/sqlc/event_roles.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading