Skip to content

Commit eb543b9

Browse files
feat: HOLY SHIT IT WORKS LMFAO
1 parent ca6f69c commit eb543b9

7 files changed

Lines changed: 537 additions & 73 deletions

File tree

‎apps/api/cmd/BAT_worker/main.go‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"github.com/hibiken/asynq"
77
"github.com/swamphacks/core/apps/api/internal/bat"
88
"github.com/swamphacks/core/apps/api/internal/config"
9+
"github.com/swamphacks/core/apps/api/internal/db"
10+
"github.com/swamphacks/core/apps/api/internal/db/repository"
911
"github.com/swamphacks/core/apps/api/internal/logger"
1012
"github.com/swamphacks/core/apps/api/internal/services"
1113
"github.com/swamphacks/core/apps/api/internal/tasks"
@@ -59,7 +61,13 @@ func main() {
5961
logger.Fatal().Err(err).Msg("Bat engine failed to initialize.")
6062
}
6163

62-
batService := services.NewBatService(batEngine, nil, logger)
64+
database := db.NewDB(cfg.DatabaseURL)
65+
defer database.Close()
66+
67+
eventRepo := repository.NewEventRespository(database)
68+
applicationRepo := repository.NewApplicationRepository(database)
69+
70+
batService := services.NewBatService(batEngine, applicationRepo, eventRepo, nil, logger)
6371

6472
BATWorker := workers.NewBATWorker(batService, logger)
6573

‎apps/api/cmd/api/main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func main() {
9797
emailService := services.NewEmailService(taskQueueClient, sesClient, logger)
9898
applicationService := services.NewApplicationService(applicationRepo, eventService, emailService, txm, r2Client, &cfg.CoreBuckets, logger)
9999
teamService := services.NewTeamService(teamRepo, teamMemberRepo, teamJoinRequestRepo, eventRepo, txm, logger)
100-
batService := services.NewBatService(batEngine, taskQueueClient, logger)
100+
batService := services.NewBatService(batEngine, applicationRepo, eventRepo, taskQueueClient, logger)
101101

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

‎apps/api/internal/db/queries/applications.sql‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,23 @@ WHERE event_id = $1
3939
ORDER BY
4040
user_id ASC;
4141

42-
-- name: ListApplicationsByEventAndStatus :many
43-
SELECT user_id, application, experience_rating, passion_rating
44-
FROM applications
45-
WHERE event_id = $1
46-
AND status = $2;
42+
-- name: ListAdmissionCandidatesByEvent :many
43+
SELECT a.user_id,
44+
a.passion_rating,
45+
a.experience_rating,
46+
a.application,
47+
t.id as team_id
48+
FROM applications a
49+
LEFT JOIN team_members tm
50+
ON tm.user_id = a.user_id
51+
LEFT JOIN teams t
52+
ON t.id = tm.team_id
53+
AND t.event_id = a.event_id
54+
WHERE a.event_id = $1
55+
AND a.status = 'under_review'
56+
AND a.passion_rating IS NOT NULL
57+
AND a.experience_rating IS NOT NULL;
58+
4759

4860
-- name: AssignApplicationsToReviewer :exec
4961
UPDATE applications

‎apps/api/internal/db/repository/application.go‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,11 @@ func (r *ApplicationRepository) GetApplicationByUserAndEventID(ctx context.Conte
6666
return &application, nil
6767
}
6868

69-
func (r *ApplicationRepository) ListApplicationsByEventAndStatus(ctx context.Context, eventId uuid.UUID, status sqlc.ApplicationStatus) ([]sqlc.ListApplicationsByEventAndStatusRow, error) {
70-
applications, err := r.db.Query.ListApplicationsByEventAndStatus(ctx, sqlc.ListApplicationsByEventAndStatusParams{
71-
EventID: eventId,
72-
Status: sqlc.NullApplicationStatus{
73-
Valid: true,
74-
ApplicationStatus: status,
75-
},
76-
})
77-
if err != nil {
78-
return []sqlc.ListApplicationsByEventAndStatusRow{}, err
79-
}
80-
return applications, nil
69+
// List all candidates considered for admission for an eventId.
70+
// This queries for all applications who are 'under_review' and have their rating fields filled out.
71+
// It also LEFT JOINs in their team id (if they have one) for further grouping based on teams.
72+
func (r *ApplicationRepository) ListAdmissionCandidatesByEvent(ctx context.Context, eventId uuid.UUID) ([]sqlc.ListAdmissionCandidatesByEventRow, error) {
73+
return r.db.Query.ListAdmissionCandidatesByEvent(ctx, eventId)
8174
}
8275

8376
func (r *ApplicationRepository) SubmitApplication(ctx context.Context, data any, userId, eventId uuid.UUID) error {

‎apps/api/internal/db/sqlc/applications.sql.go‎

Lines changed: 49 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)