Add some missing files from previous commits
This commit is contained in:
parent
fc56c1406a
commit
ee76dddf2f
3 changed files with 122 additions and 0 deletions
22
platform/session.go
Normal file
22
platform/session.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package platform
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type session struct {
|
||||
Impersonating *User
|
||||
NotificationCounts notificationCounts
|
||||
}
|
||||
|
||||
func SessionCurrent(ctx context.Context, user User) (*session, error) {
|
||||
counts, err := NotificationCountsForUser(ctx, user)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get notifications: %w", err)
|
||||
}
|
||||
return &session{
|
||||
Impersonating: nil,
|
||||
NotificationCounts: *counts,
|
||||
}, nil
|
||||
}
|
||||
6
platform/types/service_area.go
Normal file
6
platform/types/service_area.go
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
package types
|
||||
|
||||
type ServiceArea struct {
|
||||
Min Location `json:"min"`
|
||||
Max Location `json:"max"`
|
||||
}
|
||||
94
resource/session.go
Normal file
94
resource/session.go
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
package resource
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/html"
|
||||
nhttp "github.com/Gleipnir-Technology/nidus-sync/http"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
||||
)
|
||||
|
||||
type sessionR struct {
|
||||
router *router
|
||||
}
|
||||
|
||||
func Session(r *router) *sessionR {
|
||||
return &sessionR{
|
||||
router: r,
|
||||
}
|
||||
}
|
||||
|
||||
type organization struct {
|
||||
ID int32 `json:"organization_id"`
|
||||
ServiceArea *types.ServiceArea `json:"service_area"`
|
||||
}
|
||||
|
||||
type session struct {
|
||||
Impersonating *string `json:"impersonating"`
|
||||
NotificationCounts sessionNotificationCounts `json:"notification_counts"`
|
||||
Organization organization `json:"organization"`
|
||||
Self user `json:"self"`
|
||||
URLs sessionURL `json:"urls"`
|
||||
}
|
||||
type sessionNotificationCounts struct {
|
||||
Communications uint `json:"communication"`
|
||||
Home uint `json:"home"`
|
||||
Review uint `json:"review"`
|
||||
}
|
||||
|
||||
type sessionURL struct {
|
||||
API sessionURLAPI `json:"api"`
|
||||
Tegola string `json:"tegola"`
|
||||
Tile string `json:"tile"`
|
||||
}
|
||||
type sessionURLAPI struct {
|
||||
Avatar string `json:"avatar"`
|
||||
Communication string `json:"communication"`
|
||||
PublicreportMessage string `json:"publicreport_message"`
|
||||
ReviewTask string `json:"review_task"`
|
||||
Signal string `json:"signal"`
|
||||
Upload string `json:"upload"`
|
||||
User string `json:"user"`
|
||||
}
|
||||
|
||||
func (res *sessionR) Get(ctx context.Context, r *http.Request, user platform.User, query QueryParams) (*session, *nhttp.ErrorWithStatus) {
|
||||
urls := html.NewContentURL()
|
||||
counts, err := platform.NotificationCountsForUser(ctx, user)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("get counst: %w", err)
|
||||
}
|
||||
usr := User(res.router)
|
||||
u, err := usr.response(&user)
|
||||
if err != nil {
|
||||
return nil, nhttp.NewError("create user: %w", err)
|
||||
}
|
||||
return &session{
|
||||
Impersonating: nil,
|
||||
NotificationCounts: sessionNotificationCounts{
|
||||
Communications: counts.Communications,
|
||||
Home: counts.Home,
|
||||
Review: counts.Review,
|
||||
},
|
||||
Organization: organization{
|
||||
ID: user.Organization.ID,
|
||||
ServiceArea: user.Organization.ServiceArea,
|
||||
},
|
||||
Self: *u,
|
||||
URLs: sessionURL{
|
||||
API: sessionURLAPI{
|
||||
Avatar: config.MakeURLNidus("/api/avatar"),
|
||||
Communication: urls.API.Communication,
|
||||
PublicreportMessage: urls.API.Publicreport.Message,
|
||||
ReviewTask: config.MakeURLNidus("/api/review-task"),
|
||||
Signal: config.MakeURLNidus("/api/signal"),
|
||||
Upload: config.MakeURLNidus("/api/upload"),
|
||||
User: config.MakeURLNidus("/api/user"),
|
||||
},
|
||||
Tegola: urls.Tegola,
|
||||
Tile: config.MakeURLNidus("/api/tile/{z}/{y}/{x}"),
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue