mirror of
https://github.com/emo2007/block-accounting.git
synced 2025-01-18 15:36:27 +00:00
small fixes
This commit is contained in:
parent
55c6c14630
commit
c3854a7606
@ -464,14 +464,48 @@ Fetch licenses
|
|||||||
## POST **/organizations/{organization_id}/license**
|
## POST **/organizations/{organization_id}/license**
|
||||||
New licese
|
New licese
|
||||||
|
|
||||||
## GET **/organizations/{organization_id}/invite/{hash}**
|
## GET **/invite/{hash}**
|
||||||
Open invite link
|
Open invite link
|
||||||
|
### Request body
|
||||||
|
{}
|
||||||
|
### Example
|
||||||
|
Request:
|
||||||
|
```bash
|
||||||
|
curl --request GET \
|
||||||
|
--url http://localhost:8081/invite/YR9vO4ZXYTgtIyi4aScsi6UZr0vNS74x9b8Y8SKF84g=
|
||||||
|
```
|
||||||
|
Response:
|
||||||
|
```bash
|
||||||
|
{
|
||||||
|
"Ok": true
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## POST **/organizations/{organization_id}/invite/{hash}/join**
|
## POST **/invite/{hash}/join**
|
||||||
Join with invite link
|
Join with invite link
|
||||||
|
// todo
|
||||||
|
|
||||||
## POST **/organizations/{organization_id}/participants/invite**
|
## POST **/organizations/{organization_id}/participants/invite**
|
||||||
Create new invite link
|
Create new invite link
|
||||||
|
### Request body
|
||||||
|
{} empty json
|
||||||
|
### Example
|
||||||
|
Request:
|
||||||
|
```bash
|
||||||
|
curl --request POST \
|
||||||
|
--url http://localhost:8081/organizations/018fb246-1616-7f1b-9fe2-1a3202224695/participants/invite \
|
||||||
|
--header 'Authorization: Bearer token' \
|
||||||
|
--header 'X-Seed: a b c 1 2 3' \
|
||||||
|
--header 'accept: application/json' \
|
||||||
|
--header 'content-type: application/json' \
|
||||||
|
--data '{}'
|
||||||
|
```
|
||||||
|
Response:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"link": "/018fb246-1616-7f1b-9fe2-1a3202224695/invite/%2nIYC4E6ipLjUpjH0ctbqGFkneMJoF3JW41I4tThgM="
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
# Deprecated
|
# Deprecated
|
||||||
## GET **/{organization_id}/transactions**
|
## GET **/{organization_id}/transactions**
|
||||||
|
@ -32,6 +32,7 @@ type AuthController interface {
|
|||||||
Login(w http.ResponseWriter, req *http.Request) ([]byte, error)
|
Login(w http.ResponseWriter, req *http.Request) ([]byte, error)
|
||||||
Invite(w http.ResponseWriter, req *http.Request) ([]byte, error)
|
Invite(w http.ResponseWriter, req *http.Request) ([]byte, error)
|
||||||
Refresh(w http.ResponseWriter, req *http.Request) ([]byte, error)
|
Refresh(w http.ResponseWriter, req *http.Request) ([]byte, error)
|
||||||
|
InviteGet(w http.ResponseWriter, req *http.Request) ([]byte, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type authController struct {
|
type authController struct {
|
||||||
@ -191,6 +192,13 @@ func (c *authController) Invite(w http.ResponseWriter, r *http.Request) ([]byte,
|
|||||||
"&", "#",
|
"&", "#",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
createdAt := time.Now()
|
||||||
|
expDate := createdAt.Add(time.Hour * 24 * 7)
|
||||||
|
|
||||||
|
if request.ExpirationDate > 0 {
|
||||||
|
expDate = time.UnixMilli(int64(request.ExpirationDate))
|
||||||
|
}
|
||||||
|
|
||||||
c.log.Debug(
|
c.log.Debug(
|
||||||
"",
|
"",
|
||||||
slog.String("link", linkHashString),
|
slog.String("link", linkHashString),
|
||||||
@ -198,9 +206,10 @@ func (c *authController) Invite(w http.ResponseWriter, r *http.Request) ([]byte,
|
|||||||
|
|
||||||
if err := c.repo.AddInvite(ctx, auth.AddInviteParams{
|
if err := c.repo.AddInvite(ctx, auth.AddInviteParams{
|
||||||
LinkHash: linkHashString,
|
LinkHash: linkHashString,
|
||||||
|
OrganizationID: organizationID,
|
||||||
CreatedBy: *user,
|
CreatedBy: *user,
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: createdAt,
|
||||||
ExpiredAt: time.UnixMilli(int64(request.ExpirationDate)),
|
ExpiredAt: expDate,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, fmt.Errorf("error add new invite link. %w", err)
|
return nil, fmt.Errorf("error add new invite link. %w", err)
|
||||||
}
|
}
|
||||||
@ -209,5 +218,10 @@ func (c *authController) Invite(w http.ResponseWriter, r *http.Request) ([]byte,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *authController) JoinWithInvite(w http.ResponseWriter, req *http.Request) ([]byte, error) {
|
func (c *authController) JoinWithInvite(w http.ResponseWriter, req *http.Request) ([]byte, error) {
|
||||||
|
|
||||||
return nil, nil // implement
|
return nil, nil // implement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *authController) InviteGet(w http.ResponseWriter, req *http.Request) ([]byte, error) {
|
||||||
|
return presenters.ResponseOK()
|
||||||
|
}
|
||||||
|
@ -96,6 +96,11 @@ func (s *Server) buildRouter() {
|
|||||||
router.Post("/login", s.handle(s.controllers.Auth.Login, "login"))
|
router.Post("/login", s.handle(s.controllers.Auth.Login, "login"))
|
||||||
router.Get("/refresh", s.handle(s.controllers.Auth.Refresh, "refresh"))
|
router.Get("/refresh", s.handle(s.controllers.Auth.Refresh, "refresh"))
|
||||||
|
|
||||||
|
// open invite link
|
||||||
|
router.Get("/invite/{hash}", s.handle(s.controllers.Auth.InviteGet, "invite_open"))
|
||||||
|
// join via invite link
|
||||||
|
router.Post("/invite/{hash}/join", s.handle(s.controllers.Auth.JoinWithInvite, "invite_join"))
|
||||||
|
|
||||||
router.Route("/organizations", func(r chi.Router) {
|
router.Route("/organizations", func(r chi.Router) {
|
||||||
r = r.With(s.withAuthorization)
|
r = r.With(s.withAuthorization)
|
||||||
|
|
||||||
@ -116,26 +121,18 @@ func (s *Server) buildRouter() {
|
|||||||
r.Route("/payrolls", func(r chi.Router) {
|
r.Route("/payrolls", func(r chi.Router) {
|
||||||
r.Get("/", s.handle(s.controllers.Transactions.ListPayrolls, "list_payrolls"))
|
r.Get("/", s.handle(s.controllers.Transactions.ListPayrolls, "list_payrolls"))
|
||||||
r.Post("/", s.handle(s.controllers.Transactions.NewPayroll, "new_payroll"))
|
r.Post("/", s.handle(s.controllers.Transactions.NewPayroll, "new_payroll"))
|
||||||
r.Put("/", nil) // todo
|
|
||||||
})
|
})
|
||||||
|
|
||||||
r.Route("/multisig", func(r chi.Router) {
|
r.Route("/multisig", func(r chi.Router) {
|
||||||
r.Post("/", s.handle(s.controllers.Transactions.NewMultisig, "new_multisig"))
|
r.Post("/", s.handle(s.controllers.Transactions.NewMultisig, "new_multisig"))
|
||||||
r.Get("/", s.handle(s.controllers.Transactions.ListMultisigs, "list_multisig"))
|
r.Get("/", s.handle(s.controllers.Transactions.ListMultisigs, "list_multisig"))
|
||||||
r.Put("/", nil) // todo
|
|
||||||
})
|
})
|
||||||
|
|
||||||
r.Route("/license", func(r chi.Router) {
|
r.Route("/license", func(r chi.Router) {
|
||||||
r.Get("/", nil) // list license
|
r.Get("/", nil) // list license
|
||||||
r.Post("/", nil) // deploy contract
|
r.Post("/", nil) // deploy contract
|
||||||
r.Put("/", nil) // todo
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// open invite link
|
|
||||||
r.Get("/invite/{hash}", s.handle(nil, "invite_open"))
|
|
||||||
// join via invite link
|
|
||||||
r.Post("/invite/{hash}/join", s.handle(s.controllers.Auth.JoinWithInvite, "invite_join"))
|
|
||||||
|
|
||||||
r.Route("/participants", func(r chi.Router) {
|
r.Route("/participants", func(r chi.Router) {
|
||||||
r.Get("/", s.handle(s.controllers.Participants.List, "participants_list"))
|
r.Get("/", s.handle(s.controllers.Participants.List, "participants_list"))
|
||||||
r.Post("/", s.handle(s.controllers.Participants.New, "new_participant"))
|
r.Post("/", s.handle(s.controllers.Participants.New, "new_participant"))
|
||||||
|
@ -186,6 +186,7 @@ func (r *repositorySQL) GetTokens(ctx context.Context, params GetTokenParams) (*
|
|||||||
|
|
||||||
type AddInviteParams struct {
|
type AddInviteParams struct {
|
||||||
LinkHash string
|
LinkHash string
|
||||||
|
OrganizationID uuid.UUID
|
||||||
CreatedBy models.User
|
CreatedBy models.User
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
ExpiredAt time.Time
|
ExpiredAt time.Time
|
||||||
@ -198,11 +199,13 @@ func (r *repositorySQL) AddInvite(
|
|||||||
return sqltools.Transaction(ctx, r.db, func(ctx context.Context) error {
|
return sqltools.Transaction(ctx, r.db, func(ctx context.Context) error {
|
||||||
query := sq.Insert("invites").Columns(
|
query := sq.Insert("invites").Columns(
|
||||||
"link_hash",
|
"link_hash",
|
||||||
|
"organization_id",
|
||||||
"created_by",
|
"created_by",
|
||||||
"created_at",
|
"created_at",
|
||||||
"expired_at",
|
"expired_at",
|
||||||
).Values(
|
).Values(
|
||||||
params.LinkHash,
|
params.LinkHash,
|
||||||
|
params.OrganizationID,
|
||||||
params.CreatedBy.Id(),
|
params.CreatedBy.Id(),
|
||||||
params.CreatedAt,
|
params.CreatedAt,
|
||||||
params.ExpiredAt,
|
params.ExpiredAt,
|
||||||
|
@ -195,6 +195,7 @@ create index if not exists idx_multisig_confirmations_owners_owner_id
|
|||||||
|
|
||||||
create table invites (
|
create table invites (
|
||||||
link_hash varchar(64) primary key,
|
link_hash varchar(64) primary key,
|
||||||
|
organization_id uuid,
|
||||||
created_by uuid not null references users(id),
|
created_by uuid not null references users(id),
|
||||||
created_at timestamp default current_timestamp,
|
created_at timestamp default current_timestamp,
|
||||||
expired_at timestamp default null,
|
expired_at timestamp default null,
|
||||||
|
Loading…
Reference in New Issue
Block a user