Skip to content

Commit a4cc932

Browse files
authored
merge: v1.16.5 (#87)
* chore: Upgrade framework to v1.16.3 (auto) (#82) * chore: Upgrade framework to v1.16.3 (auto) * upgrade postgres v1.4.1 * optimize * upgrade: v1.16.4 (#85) * upgrade: v1.16.4 * upgrade: v1.16.4 * update mod * add queue shutdown * chore: [#807] Add model Json example (#86) * fix: [#807] queue.Shutdown doesn't stop the queue as expected * upgrade: v1.16.5 * optimize * update mod * optimize * optimize * update mod
1 parent bea377f commit a4cc932

File tree

16 files changed

+384
-974
lines changed

16 files changed

+384
-974
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ env:
2121
MINIO_ACCESS_KEY_ID: ${{ secrets.MINIO_ACCESS_KEY_ID }}
2222
MINIO_ACCESS_KEY_SECRET: ${{ secrets.MINIO_ACCESS_KEY_SECRET }}
2323
MINIO_BUCKET: ${{ secrets.MINIO_BUCKET }}
24-
CLOUDINARY_ACCESS_KEY_ID: ${{ secrets.CLOUDINARY_ACCESS_KEY_ID }}
25-
CLOUDINARY_ACCESS_KEY_SECRET: ${{ secrets.CLOUDINARY_ACCESS_KEY_SECRET }}
26-
CLOUDINARY_CLOUD: ${{ secrets.CLOUDINARY_CLOUD }}
2724
jobs:
2825
ubuntu:
2926
strategy:

app/http/controllers/user_controller.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"github.com/goravel/framework/contracts/http"
55
"github.com/goravel/framework/facades"
66

7+
"goravel/app/http/requests"
78
"goravel/app/models"
89
)
910

@@ -44,9 +45,25 @@ func (r *UserController) Show(ctx http.Context) http.Response {
4445
}
4546

4647
func (r *UserController) Store(ctx http.Context) http.Response {
48+
var userCreate requests.UserCreate
49+
errors, err := ctx.Request().ValidateRequest(&userCreate)
50+
if err != nil {
51+
return ctx.Response().Json(http.StatusBadRequest, http.Json{
52+
"message": err.Error(),
53+
})
54+
}
55+
if errors != nil {
56+
return ctx.Response().Json(http.StatusBadRequest, http.Json{
57+
"message": errors.All(),
58+
})
59+
}
60+
4761
user := models.User{
48-
Name: ctx.Request().Input("name"),
49-
Avatar: ctx.Request().Input("avatar"),
62+
Name: userCreate.Name,
63+
Avatar: userCreate.Avatar,
64+
Alias: userCreate.Alias,
65+
Mail: userCreate.Mail,
66+
Tags: userCreate.Tags,
5067
}
5168
if err := facades.Orm().Query().Create(&user); err != nil {
5269
return ctx.Response().Json(http.StatusBadRequest, http.Json{

app/http/controllers/validation_controller.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ func (r *ValidationController) Json(ctx http.Context) http.Response {
7575
}
7676

7777
func (r *ValidationController) Request(ctx http.Context) http.Response {
78-
var userCreate requests.UserCreate
79-
errors, err := ctx.Request().ValidateRequest(&userCreate)
78+
var validationCreate requests.ValidationCreate
79+
errors, err := ctx.Request().ValidateRequest(&validationCreate)
8080
if err != nil {
8181
return ctx.Response().Json(http.StatusBadRequest, http.Json{
8282
"message": err.Error(),
@@ -89,11 +89,11 @@ func (r *ValidationController) Request(ctx http.Context) http.Response {
8989
}
9090

9191
return ctx.Response().Success().Json(http.Json{
92-
"name": userCreate.Name,
93-
"tags": userCreate.Tags,
94-
"scores": userCreate.Scores,
95-
"date": userCreate.Date.ToDateTimeString(),
96-
"code": userCreate.Code,
92+
"name": validationCreate.Name,
93+
"tags": validationCreate.Tags,
94+
"scores": validationCreate.Scores,
95+
"date": validationCreate.Date.ToDateTimeString(),
96+
"code": validationCreate.Code,
9797
})
9898
}
9999

app/http/requests/user_create.go

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
package requests
22

33
import (
4+
"goravel/app/models"
5+
46
"github.com/goravel/framework/contracts/http"
5-
"github.com/goravel/framework/contracts/validation"
6-
"github.com/goravel/framework/support/carbon"
7-
"github.com/spf13/cast"
87
)
98

109
type UserCreate struct {
11-
Name string `form:"name" json:"name"`
12-
Tags []string `form:"tags" json:"tags"`
13-
Scores []int `form:"scores" json:"scores"`
14-
Date carbon.Carbon `form:"date" json:"date"`
15-
Code int `form:"code" json:"code"`
10+
Name string `form:"name" json:"name"`
11+
Avatar string `form:"avatar" json:"avatar"`
12+
Alias string `form:"alias" json:"alias"`
13+
Mail string `form:"mail" json:"mail"`
14+
Tags []models.UserTag `form:"tags" json:"tags"`
1615
}
1716

1817
func (r *UserCreate) Authorize(ctx http.Context) error {
@@ -21,32 +20,6 @@ func (r *UserCreate) Authorize(ctx http.Context) error {
2120

2221
func (r *UserCreate) Rules(ctx http.Context) map[string]string {
2322
return map[string]string{
24-
"name": "required",
25-
"tags.*": "required|string",
26-
"scores.*": "required|int",
27-
"date": "required|date",
28-
"code": `required|regex:^\d{4,6}$`,
29-
}
30-
}
31-
32-
func (r *UserCreate) Messages(ctx http.Context) map[string]string {
33-
return map[string]string{}
34-
}
35-
36-
func (r *UserCreate) Attributes(ctx http.Context) map[string]string {
37-
return map[string]string{}
38-
}
39-
40-
func (r *UserCreate) PrepareForValidation(ctx http.Context, data validation.Data) error {
41-
if scores, exist := data.Get("scores"); exist {
42-
return data.Set("scores", cast.ToIntSlice(scores))
43-
}
44-
45-
return nil
46-
}
47-
48-
func (r *UserCreate) Filters(ctx http.Context) map[string]string {
49-
return map[string]string{
50-
"name": "trim",
23+
"name": "required",
5124
}
5225
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package requests
2+
3+
import (
4+
"github.com/goravel/framework/contracts/http"
5+
"github.com/goravel/framework/contracts/validation"
6+
"github.com/goravel/framework/support/carbon"
7+
"github.com/spf13/cast"
8+
)
9+
10+
type ValidationCreate struct {
11+
Name string `form:"name" json:"name"`
12+
Tags []string `form:"tags" json:"tags"`
13+
Scores []int `form:"scores" json:"scores"`
14+
Date carbon.Carbon `form:"date" json:"date"`
15+
Code int `form:"code" json:"code"`
16+
}
17+
18+
func (r *ValidationCreate) Authorize(ctx http.Context) error {
19+
return nil
20+
}
21+
22+
func (r *ValidationCreate) Rules(ctx http.Context) map[string]string {
23+
return map[string]string{
24+
"name": "required",
25+
"tags.*": "required|string",
26+
"scores.*": "required|int",
27+
"date": "required|date",
28+
"code": `required|regex:^\d{4,6}$`,
29+
}
30+
}
31+
32+
func (r *ValidationCreate) Messages(ctx http.Context) map[string]string {
33+
return map[string]string{}
34+
}
35+
36+
func (r *ValidationCreate) Attributes(ctx http.Context) map[string]string {
37+
return map[string]string{}
38+
}
39+
40+
func (r *ValidationCreate) PrepareForValidation(ctx http.Context, data validation.Data) error {
41+
if scores, exist := data.Get("scores"); exist {
42+
return data.Set("scores", cast.ToIntSlice(scores))
43+
}
44+
45+
return nil
46+
}
47+
48+
func (r *ValidationCreate) Filters(ctx http.Context) map[string]string {
49+
return map[string]string{
50+
"name": "trim",
51+
}
52+
}

app/models/user.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package models
22

33
import (
4+
"database/sql/driver"
5+
"errors"
6+
47
"github.com/goravel/framework/database/orm"
8+
"github.com/goravel/framework/support/json"
59
)
610

711
type User struct {
@@ -10,5 +14,28 @@ type User struct {
1014
Avatar string
1115
Alias string
1216
Mail string
17+
Tags []UserTag `gorm:"serializer:json"`
1318
orm.SoftDeletes
1419
}
20+
21+
type UserTag struct {
22+
Key string `json:"key"`
23+
Val int `json:"value"`
24+
}
25+
26+
func (r *UserTag) Scan(value any) error {
27+
if value == nil {
28+
return nil
29+
}
30+
31+
bytes, ok := value.([]byte)
32+
if !ok {
33+
return errors.New("type assertion to []byte failed")
34+
}
35+
36+
return json.Unmarshal(bytes, r)
37+
}
38+
39+
func (r *UserTag) Value() (driver.Value, error) {
40+
return json.Marshal(r)
41+
}

config/app.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config
22

33
import (
4-
"github.com/goravel/cloudinary"
54
"github.com/goravel/cos"
65
"github.com/goravel/fiber"
76
"github.com/goravel/framework/auth"
@@ -26,6 +25,7 @@ import (
2625
"github.com/goravel/framework/testing"
2726
"github.com/goravel/framework/translation"
2827
"github.com/goravel/framework/validation"
28+
"github.com/goravel/framework/view"
2929
"github.com/goravel/gin"
3030
"github.com/goravel/minio"
3131
"github.com/goravel/mysql"
@@ -105,12 +105,7 @@ func init() {
105105
"providers": []foundation.ServiceProvider{
106106
&log.ServiceProvider{},
107107
&console.ServiceProvider{},
108-
&postgres.ServiceProvider{},
109-
&mysql.ServiceProvider{},
110-
&sqlserver.ServiceProvider{},
111-
&sqlite.ServiceProvider{},
112108
&database.ServiceProvider{},
113-
&redis.ServiceProvider{},
114109
&cache.ServiceProvider{},
115110
&http.ServiceProvider{},
116111
&route.ServiceProvider{},
@@ -127,6 +122,7 @@ func init() {
127122
&session.ServiceProvider{},
128123
&translation.ServiceProvider{},
129124
&testing.ServiceProvider{},
125+
&view.ServiceProvider{},
130126
&providers.AppServiceProvider{},
131127
&providers.AuthServiceProvider{},
132128
&providers.RouteServiceProvider{},
@@ -136,11 +132,15 @@ func init() {
136132
&providers.EventServiceProvider{},
137133
&providers.ValidationServiceProvider{},
138134
&providers.DatabaseServiceProvider{},
135+
&postgres.ServiceProvider{},
136+
&mysql.ServiceProvider{},
137+
&sqlserver.ServiceProvider{},
138+
&sqlite.ServiceProvider{},
139139
&s3.ServiceProvider{},
140140
&cos.ServiceProvider{},
141141
&oss.ServiceProvider{},
142-
&cloudinary.ServiceProvider{},
143142
&minio.ServiceProvider{},
143+
&redis.ServiceProvider{},
144144
&gin.ServiceProvider{},
145145
&fiber.ServiceProvider{},
146146
},

config/database.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ func init() {
111111
"driver": "default",
112112
"table": "migrations",
113113
},
114+
114115
"redis": map[string]any{
115116
"default": map[string]any{
116117
"host": config.Env("REDIS_HOST", ""),

config/filesystems.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package config
22

33
import (
4-
cloudinaryfacades "github.com/goravel/cloudinary/facades"
54
cosfacades "github.com/goravel/cos/facades"
65
"github.com/goravel/framework/contracts/filesystem"
76
"github.com/goravel/framework/facades"
@@ -69,15 +68,6 @@ func init() {
6968
return ossfacades.Oss("oss") // The `oss` value is the `disks` key
7069
},
7170
},
72-
"cloudinary": map[string]any{
73-
"driver": "custom",
74-
"cloud": config.Env("CLOUDINARY_CLOUD"),
75-
"key": config.Env("CLOUDINARY_ACCESS_KEY_ID"),
76-
"secret": config.Env("CLOUDINARY_ACCESS_KEY_SECRET"),
77-
"via": func() (filesystem.Driver, error) {
78-
return cloudinaryfacades.Cloudinary("cloudinary") // The `cloudinary` value is the `disks` key
79-
},
80-
},
8171
"minio": map[string]any{
8272
"driver": "custom",
8373
"key": config.Env("MINIO_ACCESS_KEY_ID"),

database/migrations/20210101000001_create_users_table.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func (r *M20210101000001CreateUsersTable) Up() error {
2020
table.BigIncrements("id")
2121
table.String("name").Default("")
2222
table.String("avatar").Default("")
23+
table.Json("tags").Nullable()
2324
table.Timestamps()
2425
table.SoftDeletes()
2526
table.Comment("user table")

0 commit comments

Comments
 (0)