Skip to content

Commit 2328fa7

Browse files
committed
Merge branch 'main' of https://github.com/GenerateNU/skillspark into vindema/mobile-landing-page-redesign
2 parents 92e9765 + 5482b7e commit 2328fa7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+6374
-8538
lines changed

backend/api/openapi.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,15 @@ paths:
18951895
summary: Creates a saved event
18961896
description: Creates a saved event
18971897
operationId: create-saved
1898+
parameters:
1899+
- name: Accept-Language
1900+
in: header
1901+
schema:
1902+
type: string
1903+
default: en-US
1904+
enum:
1905+
- en-US
1906+
- th-TH
18981907
requestBody:
18991908
content:
19001909
application/json:
@@ -1948,6 +1957,14 @@ paths:
19481957
default: 10
19491958
minimum: 1
19501959
maximum: 100
1960+
- name: Accept-Language
1961+
in: header
1962+
schema:
1963+
type: string
1964+
default: en-US
1965+
enum:
1966+
- en-US
1967+
- th-TH
19511968
responses:
19521969
"200":
19531970
description: OK
@@ -3390,6 +3407,7 @@ components:
33903407
- name
33913408
- active
33923409
- presigned_url
3410+
- location_id
33933411
- created_at
33943412
- updated_at
33953413
- stripe_account_id

backend/cmd/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ func main() {
3636
}
3737
}()
3838

39-
4039
port := cfg.Application.Port
4140

4241
// Listen for connections with a goroutine
@@ -54,7 +53,6 @@ func main() {
5453

5554
slog.Info("Shutting down server")
5655

57-
5856
// Shutdown server with timeout
5957
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 30*time.Second)
6058
defer shutdownCancel()

backend/internal/models/saved.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type CreateSavedInput struct {
1919
GuardianID uuid.UUID `json:"guardian_id" db:"guardian_id" doc:"ID of the guardian that saved this."`
2020
EventID uuid.UUID `json:"event_id" db:"event_id" doc:"ID of this saved event."`
2121
}
22+
AcceptLanguage string `header:"Accept-Language" default:"en-US" enum:"en-US,th-TH"`
2223
}
2324

2425
type CreateSavedOutput struct {
@@ -36,9 +37,10 @@ type DeleteSavedOutput struct {
3637
}
3738

3839
type GetSavedInput struct {
39-
ID uuid.UUID `path:"id"`
40-
Page int `query:"page" minimum:"1" default:"1" doc:"Page number (starts at 1)"`
41-
PageSize int `query:"page_size" minimum:"1" maximum:"100" default:"10" doc:"Number of items per page"`
40+
ID uuid.UUID `path:"id"`
41+
Page int `query:"page" minimum:"1" default:"1" doc:"Page number (starts at 1)"`
42+
PageSize int `query:"page_size" minimum:"1" maximum:"100" default:"10" doc:"Number of items per page"`
43+
AcceptLanguage string `header:"Accept-Language" default:"en-US" enum:"en-US,th-TH"`
4244
}
4345

4446
type GetSavedOutput struct {

backend/internal/service/handler/saved/getByGuardianID.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
"github.com/google/uuid"
1010
)
1111

12-
func (h *Handler) GetByGuardianID(ctx context.Context, id uuid.UUID, pagination utils.Pagination) ([]models.Saved, error) {
12+
func (h *Handler) GetByGuardianID(ctx context.Context, id uuid.UUID, pagination utils.Pagination, AcceptLanguage string) ([]models.Saved, error) {
1313

1414
if _, err := h.GuardianRepository.GetGuardianByID(ctx, id); err != nil {
1515
return nil, errs.BadRequest("Invalid guardian_id: guardian does not exist")
1616
}
1717

18-
reviews, httpErr := h.SavedRepository.GetByGuardianID(ctx, id, pagination)
18+
reviews, httpErr := h.SavedRepository.GetByGuardianID(ctx, id, pagination, AcceptLanguage)
1919
if httpErr != nil {
2020
return nil, httpErr
2121
}

backend/internal/service/handler/saved/handler_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func TestHandler_GetByGuardianID(t *testing.T) {
3737
mock.Anything,
3838
uuid.MustParse("11111111-1111-1111-1111-111111111111"),
3939
mock.AnythingOfType("utils.Pagination"),
40+
mock.AnythingOfType("string"),
4041
).Return([]models.Saved{
4142
{
4243
ID: uuid.MustParse("20000000-0000-0000-0000-000000000001"),
@@ -81,6 +82,7 @@ func TestHandler_GetByGuardianID(t *testing.T) {
8182
mock.Anything,
8283
uuid.MustParse("22222222-2222-2222-2222-222222222222"),
8384
mock.AnythingOfType("utils.Pagination"),
85+
mock.AnythingOfType("string"),
8486
).Return(nil, errs.BadRequest("cannot fetch saved"))
8587
},
8688
wantSaved: nil,
@@ -105,7 +107,7 @@ func TestHandler_GetByGuardianID(t *testing.T) {
105107

106108
pagination := utils.Pagination{Page: 1, Limit: 10}
107109

108-
saved, err := handler.GetByGuardianID(context.Background(), tt.guardianID, pagination)
110+
saved, err := handler.GetByGuardianID(context.Background(), tt.guardianID, pagination, "en-US")
109111

110112
if tt.wantErr {
111113
assert.Error(t, err)

backend/internal/service/routes/saved.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func SetUpSavedRoutes(api huma.API, repo *storage.Repository) {
3838
Limit: limit,
3939
}
4040

41-
saveds, err := savedHandler.SavedRepository.GetByGuardianID(ctx, input.ID, pagination)
41+
saveds, err := savedHandler.SavedRepository.GetByGuardianID(ctx, input.ID, pagination, input.AcceptLanguage)
4242
if err != nil {
4343
return nil, err
4444
}

backend/internal/service/routes/saved_routes_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func TestGetSavedByGuardianID_Success(t *testing.T) {
7171
mock.Anything,
7272
guardianID,
7373
utils.Pagination{Page: 1, Limit: 10},
74+
mock.AnythingOfType("string"),
7475
).Return(expectedSaved, nil)
7576

7677
app, _ := setupSavedTestAPI(mockRepo)
@@ -141,6 +142,7 @@ func TestGetSavedByGuardianID_WithPagination(t *testing.T) {
141142
mock.Anything,
142143
guardianID,
143144
utils.Pagination{Page: 2, Limit: 10},
145+
mock.AnythingOfType("string"),
144146
).Return(expectedSaved, nil)
145147

146148
app, _ := setupSavedTestAPI(mockRepo)

backend/internal/storage/postgres/schema/saved/create.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"skillspark/internal/storage/postgres/schema"
88
)
99

10-
const language = "en-US"
10+
var language string
1111

1212
func (r *SavedRepository) CreateSaved(ctx context.Context, saved *models.CreateSavedInput) (*models.Saved, error) {
13+
language = saved.AcceptLanguage
1314

1415
query, err := schema.ReadSQLBaseScript("create.sql", SqlSavedFiles)
1516
if err != nil {

backend/internal/storage/postgres/schema/saved/get_all_for_user.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/google/uuid"
1111
)
1212

13-
func (r *SavedRepository) GetByGuardianID(ctx context.Context, user_id uuid.UUID, pagination utils.Pagination) ([]models.Saved, error) {
13+
func (r *SavedRepository) GetByGuardianID(ctx context.Context, user_id uuid.UUID, pagination utils.Pagination, AcceptLanguage string) ([]models.Saved, error) {
1414

1515
query, err := schema.ReadSQLBaseScript("get_all_for_user.sql", SqlSavedFiles)
1616
if err != nil {
@@ -64,7 +64,7 @@ func (r *SavedRepository) GetByGuardianID(ctx context.Context, user_id uuid.UUID
6464
return nil, &err
6565
}
6666

67-
switch language {
67+
switch AcceptLanguage {
6868
case "th-TH":
6969
if titleTH != nil {
7070
s.Event.Title = *titleTH

backend/internal/storage/postgres/schema/saved/get_all_for_user_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestGetReviewsByGuardianID(t *testing.T) {
4646
}
4747

4848
pagination := utils.Pagination{Limit: 10, Page: 1}
49-
reviews, err := repo.GetByGuardianID(ctx, firstSaved.GuardianID, pagination)
49+
reviews, err := repo.GetByGuardianID(ctx, firstSaved.GuardianID, pagination, "en-US")
5050
require.Nil(t, err)
5151
require.Len(t, reviews, len(expectedSaved))
5252
}
@@ -60,7 +60,7 @@ func TestGetReviewsByGuardianID_NoReviews(t *testing.T) {
6060
g := guardian.CreateTestGuardian(t, ctx, testDB)
6161

6262
pagination := utils.Pagination{Limit: 10, Page: 1}
63-
reviews, err := repo.GetByGuardianID(ctx, g.ID, pagination)
63+
reviews, err := repo.GetByGuardianID(ctx, g.ID, pagination, "en-US")
6464

6565
require.Nil(t, err)
6666
require.NotNil(t, reviews)

0 commit comments

Comments
 (0)