Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PrepareForValidation Context fixes [#589] #859

Open
wants to merge 61 commits into
base: v1.15.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e8dea15
fix: artisan bug (#802)
hwbrzzl Dec 31, 2024
736808b
upgrade v1.15.2
hwbrzzl Dec 31, 2024
951b489
chore: optimize grpc link (#806)
hwbrzzl Jan 1, 2025
273efc8
chore(deps): Update non-major dependencies (#807)
renovate[bot] Jan 4, 2025
9f64a3c
chore(deps): Update non-major dependencies (#811)
renovate[bot] Jan 8, 2025
634f3b3
chore: [#539] Remove the SQL migrator module (#809)
hwbrzzl Jan 9, 2025
bc907a5
chore: move testing.http to a single folder (#814)
hwbrzzl Jan 10, 2025
225df76
chore(deps): Update github.com/charmbracelet/huh/spinner digest to 6c…
renovate[bot] Jan 10, 2025
28200d6
test: submodule (#816)
hwbrzzl Jan 10, 2025
458efb9
feat: migrator support to change table column (#813)
almas1992 Jan 11, 2025
aa6a927
README
hwbrzzl Jan 12, 2025
0f24e0c
chore(deps): Update module google.golang.org/grpc to v1.69.4 (#817)
renovate[bot] Jan 13, 2025
d747f79
chore(deps): Update dependency go to v1.23.5 (#822)
renovate[bot] Jan 17, 2025
8c46b8a
chore: optimize make:command for auto-generated Signature and simplif…
almas1992 Jan 17, 2025
cdd2b8b
feat: [#540] Move the Postgres driver to a single package (#810)
hwbrzzl Jan 18, 2025
29c6fd4
feat: [#540] Remove contracts/database/config.go::Driver (#823)
hwbrzzl Jan 21, 2025
c28d76f
feat: [#540] Remove SQL in show_command.go (#825)
hwbrzzl Jan 22, 2025
85749fc
feat: [#540] Remove database.connections.* (#827)
hwbrzzl Jan 22, 2025
737d24e
chore: add GetContent and PutContent methods to support/file (#824)
almas1992 Jan 22, 2025
187beae
chore(deps): Update module google.golang.org/grpc to v1.70.0 (#832)
renovate[bot] Jan 24, 2025
1026257
feat: [#540] Remove DriverSchema (#828)
hwbrzzl Jan 25, 2025
463cb24
chore: [#540] Add common functions (#833)
hwbrzzl Jan 25, 2025
9f9dfdb
chore: [#540] Fix tests (#834)
hwbrzzl Jan 26, 2025
208f44e
chore(deps): Update module github.com/samber/lo to v1.48.0 (#835)
renovate[bot] Jan 26, 2025
5c8f7f9
chore(deps): Update module github.com/samber/lo to v1.49.0 (#837)
renovate[bot] Jan 27, 2025
5496ec6
chore(deps): Update module github.com/samber/lo to v1.49.1 (#838)
renovate[bot] Jan 28, 2025
ec545a6
chore(deps): Update non-major dependencies (#839)
renovate[bot] Jan 29, 2025
724ab86
chore(deps): Update github.com/charmbracelet/huh/spinner digest to c7…
renovate[bot] Jan 30, 2025
9826b37
chore(deps): Update module github.com/brianvoe/gofakeit/v7 to v7.2.1 …
renovate[bot] Jan 31, 2025
219c1fd
chore: merge v1.15.3 (#842)
hwbrzzl Feb 1, 2025
49649aa
chore: update tests (#843)
hwbrzzl Feb 1, 2025
cbb806d
feat: [#540] Adapt Mysql driver (#844)
hwbrzzl Feb 2, 2025
702075c
chore: [#540] Add test cases (#845)
hwbrzzl Feb 3, 2025
d0de53e
chore(deps): Update github.com/charmbracelet/huh/spinner digest to f0…
renovate[bot] Feb 4, 2025
656636e
chore: update tests mod (#846)
hwbrzzl Feb 4, 2025
9aa404b
chore(deps): Update non-major dependencies (#849)
renovate[bot] Feb 5, 2025
ffb840d
chore: upgrade db packages (#848)
hwbrzzl Feb 5, 2025
dc45fb9
feat: grpc graceful shutdown (#850)
devhaozi Feb 5, 2025
90fdd5f
chore(deps): Update golang.org/x/exp digest to f9890c6 (#852)
renovate[bot] Feb 7, 2025
b635f38
chore: [#585] update db config to use proper casing for DB server nam…
almas1992 Feb 7, 2025
b9727ea
chore(deps): Update tests module (#854)
almas1992 Feb 7, 2025
2105677
update renovate
hwbrzzl Feb 7, 2025
dbb8ec6
update renovate
hwbrzzl Feb 7, 2025
98a0ffd
update renovate
hwbrzzl Feb 7, 2025
7ed72e5
test renovate
hwbrzzl Feb 7, 2025
de582d3
test renovate
hwbrzzl Feb 7, 2025
b777507
refactor: queue pr part 1 (#808)
devhaozi Feb 7, 2025
e60cacf
test renovate
hwbrzzl Feb 7, 2025
482669b
test renovate
hwbrzzl Feb 7, 2025
1f9e5b3
test renovate
hwbrzzl Feb 7, 2025
57590a7
chore: Update github.com/goravel/postgres digest to e505779 (#857)
renovate[bot] Feb 7, 2025
69f41c5
chore: Update dependency go to v1.23.6 (#858)
renovate[bot] Feb 7, 2025
e3f5532
fix: PrepareForValidation Context fixes [#589]
ahmed3mar Feb 7, 2025
b8242bc
chore: restructure testing folder (#861)
hwbrzzl Feb 7, 2025
26901e3
fix: unit test
ahmed3mar Feb 7, 2025
782a508
chore: Update upgrade DB packages (#862)
renovate[bot] Feb 7, 2025
5ae99eb
Merge branch 'master' into patch-5
ahmed3mar Feb 7, 2025
d969b31
Merge branch 'v1.15.x' into patch-5
ahmed3mar Feb 8, 2025
c43112d
reset
ahmed3mar Feb 8, 2025
f1b8e7b
update
ahmed3mar Feb 8, 2025
a7df673
unit test
ahmed3mar Feb 8, 2025
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
2 changes: 1 addition & 1 deletion validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (r *Validation) Make(data any, rules map[string]string, options ...validate
options = append(options, Rules(rules), CustomRules(r.rules), CustomFilters(r.filters))
generateOptions := GenerateOptions(options)
if generateOptions["prepareForValidation"] != nil {
if err := generateOptions["prepareForValidation"].(func(ctx http.Context, data validatecontract.Data) error)(nil, NewData(dataFace)); err != nil {
if err := generateOptions["prepareForValidation"].(func(ctx http.Context, data validatecontract.Data) error)(generateOptions["ctx"].(http.Context), NewData(dataFace)); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need check if existing: ctx, ok := generateOptions["ctx"].(http.Context)

return nil, err
}
}
Expand Down
16 changes: 16 additions & 0 deletions validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/goravel/framework/contracts/http"
httpvalidate "github.com/goravel/framework/contracts/validation"
"github.com/goravel/framework/errors"
goravelhttp "github.com/goravel/framework/http"
)

func TestMake(t *testing.T) {
Expand Down Expand Up @@ -81,6 +82,9 @@ func TestMake(t *testing.T) {
rules: map[string]string{"a": "required"},
options: []httpvalidate.Option{
Filters(map[string]string{"a": "trim"}),
func(o map[string]any) {
o["ctx"] = goravelhttp.NewContext()
},
Comment on lines +85 to +87
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can create a new Context method like Filters, and set a value to the ctx, then test whether the value can be obtained as expected.

PrepareForValidation(func(ctx http.Context, data httpvalidate.Data) error {
return ErrInvalidData
}),
Expand All @@ -93,6 +97,9 @@ func TestMake(t *testing.T) {
rules: map[string]string{"a": "required"},
options: []httpvalidate.Option{
Filters(map[string]string{"a": "trim"}),
func(o map[string]any) {
o["ctx"] = goravelhttp.NewContext()
},
PrepareForValidation(func(ctx http.Context, data httpvalidate.Data) error {
if _, exist := data.Get("a"); exist {
return data.Set("a", "c")
Expand All @@ -116,6 +123,9 @@ func TestMake(t *testing.T) {
Attributes(map[string]string{
"b": "B",
}),
func(o map[string]any) {
o["ctx"] = goravelhttp.NewContext()
},
PrepareForValidation(func(ctx http.Context, data httpvalidate.Data) error {
if _, exist := data.Get("a"); exist {
return data.Set("a", "c")
Expand All @@ -135,6 +145,9 @@ func TestMake(t *testing.T) {
rules: map[string]string{"A": "required"},
options: []httpvalidate.Option{
Filters(map[string]string{"A": "trim"}),
func(o map[string]any) {
o["ctx"] = goravelhttp.NewContext()
},
PrepareForValidation(func(ctx http.Context, data httpvalidate.Data) error {
if _, exist := data.Get("A"); exist {
return data.Set("A", "c")
Expand All @@ -158,6 +171,9 @@ func TestMake(t *testing.T) {
Attributes(map[string]string{
"B": "b",
}),
func(o map[string]any) {
o["ctx"] = goravelhttp.NewContext()
},
PrepareForValidation(func(ctx http.Context, data httpvalidate.Data) error {
if _, exist := data.Get("a"); exist {
return data.Set("a", "c")
Expand Down
Loading