-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.go
63 lines (50 loc) · 1.61 KB
/
account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package account
import (
"strconv"
"github.com/dfang/qor-demo/config/auth"
"github.com/dfang/qor-demo/models/users"
"github.com/dfang/qor-demo/utils/funcmapmaker"
"github.com/go-chi/chi"
"github.com/qor/application"
"github.com/qor/qor"
"github.com/qor/render"
)
// New new home app
func New(config *Config) *App {
return &App{Config: config}
}
// NewWithDefault New App With No Config
func NewWithDefault() *App {
return &App{Config: &Config{}}
}
// App home app
type App struct {
Config *Config
}
// Config home config struct
type Config struct {
}
// ConfigureApplication configure application
func (app App) ConfigureApplication(application *application.Application) {
controller := &Controller{View: render.New(&render.Config{AssetFileSystem: application.AssetFS.NameSpace("account")}, "app/account/views")}
funcmapmaker.AddFuncMapMaker(controller.View)
app.ConfigureAdmin(application.Admin)
application.Router.Mount("/auth/", auth.Auth.NewServeMux())
application.Router.With(auth.Authority.Authorize()).Route("/account", func(r chi.Router) {
r.Get("/", controller.Orders)
r.With(auth.Authority.Authorize("logged_in_half_hour")).Post("/add_user_credit", controller.AddCredit)
r.Get("/profile", controller.Profile)
r.Post("/profile", controller.Update)
})
}
func userAddressesCollection(resource interface{}, context *qor.Context) (results [][]string) {
var (
user users.User
DB = context.DB
)
DB.Preload("Addresses").Where(context.ResourceID).First(&user)
for _, address := range user.Addresses {
results = append(results, []string{strconv.Itoa(int(address.ID)), address.Stringify()})
}
return
}