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
6 changes: 3 additions & 3 deletions internal/path_variable_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ func GetDateFromRequestPath(varName string, req *http.Request) (time.Time, bool)
return date, err == nil
}

func GetIntFromRequestPath(varName string, req *http.Request) (int32, bool) {
func GetIntFromRequestPath(varName string, req *http.Request) (int, bool) {
val := req.PathValue(varName)
if val == "" {
return 0, false
}
id, err := strconv.ParseInt(val, 10, 32)
id, err := strconv.Atoi(val)
if err != nil || id <= 0 {
return 0, false
Comment thread
jlpdeveloper marked this conversation as resolved.
}
return int32(id), true
return id, true
}
9 changes: 1 addition & 8 deletions internal/path_variable_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestGetIntFromRequestPath(t *testing.T) {
name string
varName string
pathVal string
want int32
want int
wantOk bool
}{
{
Expand Down Expand Up @@ -99,13 +99,6 @@ func TestGetIntFromRequestPath(t *testing.T) {
want: 0,
wantOk: false,
},
{
name: "Overflow ID",
varName: "id",
pathVal: "2147483648",
want: 0,
wantOk: false,
},
}

for _, tt := range tests {
Expand Down
33 changes: 10 additions & 23 deletions internal/platform/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type mockPlatformQuerier struct {
err error
createPlatform func(ctx context.Context, arg CreatePlatformParams) error
getPlatforms func(ctx context.Context) ([]Platform, error)
getPlatform func(ctx context.Context, id int32) (Platform, error)
deletePlatform func(ctx context.Context, id int32) (int32, error)
updatePlatform func(ctx context.Context, arg UpdatePlatformParams) (int32, error)
getPlatform func(ctx context.Context, id int) (Platform, error)
deletePlatform func(ctx context.Context, id int) (int, error)
updatePlatform func(ctx context.Context, arg UpdatePlatformParams) (int, error)
}

func (m *mockPlatformQuerier) CreatePlatform(ctx context.Context, arg CreatePlatformParams) error {
Expand All @@ -30,14 +30,14 @@ func (m *mockPlatformQuerier) CreatePlatform(ctx context.Context, arg CreatePlat
return m.err
}

func (m *mockPlatformQuerier) DeletePlatform(ctx context.Context, id int32) (int32, error) {
func (m *mockPlatformQuerier) DeletePlatform(ctx context.Context, id int) (int, error) {
if m.deletePlatform != nil {
return m.deletePlatform(ctx, id)
}
return -1, m.err
}

func (m *mockPlatformQuerier) GetPlatform(ctx context.Context, id int32) (Platform, error) {
func (m *mockPlatformQuerier) GetPlatform(ctx context.Context, id int) (Platform, error) {
if m.getPlatform != nil {
return m.getPlatform(ctx, id)
}
Expand All @@ -51,7 +51,7 @@ func (m *mockPlatformQuerier) GetPlatforms(ctx context.Context) ([]Platform, err
return nil, m.err
}

func (m *mockPlatformQuerier) UpdatePlatform(ctx context.Context, arg UpdatePlatformParams) (int32, error) {
func (m *mockPlatformQuerier) UpdatePlatform(ctx context.Context, arg UpdatePlatformParams) (int, error) {
if m.updatePlatform != nil {
return m.updatePlatform(ctx, arg)
}
Expand Down Expand Up @@ -223,13 +223,6 @@ func TestGetPlatform(t *testing.T) {
dbErr: nil,
expectedStatus: http.StatusBadRequest,
},
{
name: "Invalid ID (Overflow)",
id: "2147483648",
dbPlatform: Platform{},
dbErr: nil,
expectedStatus: http.StatusBadRequest,
},
{
name: "Not Found",
id: "999",
Expand All @@ -250,7 +243,7 @@ func TestGetPlatform(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
mDB := &mockPlatformQuerier{
err: tt.dbErr,
getPlatform: func(ctx context.Context, id int32) (Platform, error) {
getPlatform: func(ctx context.Context, id int) (Platform, error) {
return tt.dbPlatform, tt.dbErr
},
}
Expand Down Expand Up @@ -326,12 +319,6 @@ func TestDeletePlatform(t *testing.T) {
dbErr: nil,
expectedStatus: http.StatusBadRequest,
},
{
name: "Invalid ID (Overflow)",
id: "2147483648",
dbErr: nil,
expectedStatus: http.StatusBadRequest,
},
{
name: "Not Found",
id: "999",
Expand All @@ -344,9 +331,9 @@ func TestDeletePlatform(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
mDB := &mockPlatformQuerier{
err: tt.dbErr,
deletePlatform: func(ctx context.Context, id int32) (int32, error) {
deletePlatform: func(ctx context.Context, id int) (int, error) {
if i, e := strconv.Atoi(tt.id); e == nil {
return int32(i), tt.dbErr
return int(i), tt.dbErr
}
return -1, tt.dbErr
},
Expand Down Expand Up @@ -484,7 +471,7 @@ func TestUpdatePlatform(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
mDB := &mockPlatformQuerier{
err: tt.dbErr,
updatePlatform: func(ctx context.Context, arg UpdatePlatformParams) (int32, error) {
updatePlatform: func(ctx context.Context, arg UpdatePlatformParams) (int, error) {
if tt.name == "Success" {
expectedBody := tt.requestBody.(Platform)
if arg.ID != expectedBody.ID {
Expand Down
14 changes: 7 additions & 7 deletions internal/platform/models.gen.go

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

10 changes: 5 additions & 5 deletions internal/platform/platforms.sql.gen.go

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

6 changes: 3 additions & 3 deletions internal/platform/querier.gen.go

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

4 changes: 2 additions & 2 deletions internal/platform/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ func (r *createPlatformRequest) ToParams() CreatePlatformParams {
}

type updatePlatformRequest struct {
ID int32 `json:"id"`
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
}

func (r *updatePlatformRequest) ToParams(id int32) UpdatePlatformParams {
func (r *updatePlatformRequest) ToParams(id int) UpdatePlatformParams {
return UpdatePlatformParams{
ID: id,
Name: r.Name,
Expand Down
4 changes: 2 additions & 2 deletions internal/platform/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestUpdatePlatformRequest_ToParams(t *testing.T) {
Name: "Updated Platform",
Description: "Updated Description",
}
id := int32(1)
id := 1

params := req.ToParams(id)

Expand Down Expand Up @@ -101,7 +101,7 @@ func TestUpdatePlatformRequest_ToParams_IDPrecedence(t *testing.T) {
Name: "Precedence Test",
Description: "Testing ID precedence",
}
pathID := int32(200) // ID from path/argument
pathID := 200 // ID from path/argument

params := req.ToParams(pathID)

Expand Down
Loading
Loading