update
This commit is contained in:
parent
f7df1224e0
commit
5edf656f53
15
build.zsh
15
build.zsh
@ -6,7 +6,18 @@ su=5000
|
||||
|
||||
go generate ./...
|
||||
cp -rf $d/ent/openapi.json $d/tmp/
|
||||
sed -i '' "s/255/$su/g" $d/ent/ogent/oas_parameters_gen.go
|
||||
sed -i '' "s/255/$su/g" $d/ent/openapi.json
|
||||
|
||||
case $OSTYPE in
|
||||
darwin*)
|
||||
sed -i '' "s/255/$su/g" $d/ent/ogent/oas_parameters_gen.go
|
||||
sed -i '' "s/255/$su/g" $d/ent/openapi.json
|
||||
;;
|
||||
linux*)
|
||||
sed -i "s/255/$su/g" $d/ent/ogent/oas_parameters_gen.go
|
||||
sed -i "s/255/$su/g" $d/ent/openapi.json
|
||||
;;
|
||||
esac
|
||||
|
||||
cp -rf $d/tmp/ogent ent/
|
||||
#PASS=`cat token.json|jq -r .password` TOKEN=`cat token.json|jq -r .token` go build
|
||||
#PASS=`cat token.json|jq -r .password` TOKEN=`cat token.json|jq -r .token` go run -mod=mod main.go
|
||||
|
133
docs/wiki.md
Normal file
133
docs/wiki.md
Normal file
@ -0,0 +1,133 @@
|
||||
### build
|
||||
|
||||
```sh
|
||||
$ vim ent/entc.go
|
||||
$ vim ent/schema/users.go
|
||||
$ go generate ./...
|
||||
$ go build
|
||||
$ ./card
|
||||
|
||||
$ go generate ./...
|
||||
$ PASS=`cat ./token.json|jq -r .password` TOKEN=`cat ./token.json|jq -r .token` go run -mod=mod main.go
|
||||
$ curl -X POST -H "Content-Type: application/json" -d "{\"username\":\"syui\",\"password\":\"$pass\"}" localhost:8080/users
|
||||
$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"password\":\"$pass\"}" localhost:8080/cards
|
||||
$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"card\":1,\"cp\":11,\"status\":\"normal\",\"password\":\"$pass\"}" localhost:8080/cards
|
||||
$ curl localhost:8080/users
|
||||
$ curl localhost:8080/cards
|
||||
$ curl localhost:8080/users/1
|
||||
$ curl localhost:8080/users/1/card
|
||||
```
|
||||
|
||||
### use
|
||||
|
||||
```sh
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"username":"syui",\"password\":\"$pass\"}' https://api.syui.ai/users
|
||||
|
||||
# onconflict
|
||||
$ !!
|
||||
|
||||
$ curl -sL https://api.syui.ai/users/1
|
||||
```
|
||||
|
||||
```sh
|
||||
# item select
|
||||
$ curl -sL "https://api.syui.ai/users?itemsPerPage=255"
|
||||
$ curl -sL "https://api.syui.ai/cards?itemsPerPage=255"
|
||||
$ curl -sL "https://api.syui.ai/users/1/card?itemsPerPage=255"
|
||||
```
|
||||
|
||||
### ref
|
||||
|
||||
```sh
|
||||
$ vim ./ent/ogent/ogent.go
|
||||
// 新規登録の停止
|
||||
// CreateUsers handles POST /users-slice requests.
|
||||
func (h *OgentHandler) CreateUsers(ctx context.Context, req CreateUsersReq) (CreateUsersRes, error) {
|
||||
b := h.client.Users.Create()
|
||||
//b.SetUser(req.User)
|
||||
b.SetUser("syui")
|
||||
}
|
||||
|
||||
// 削除の無効
|
||||
// DeleteUsers handles DELETE /users-slice/{id} requests.
|
||||
func (h *OgentHandler) DeleteUsers(ctx context.Context, params DeleteUsersParams) (DeleteUsersRes, error) {
|
||||
if params.ID != 1 {
|
||||
err := h.client.Users.DeleteOneID(params.ID).Exec(ctx)
|
||||
}
|
||||
return new(DeleteUsersNoContent), nil
|
||||
}
|
||||
|
||||
// 要素の書き換えの禁止
|
||||
// UpdateUsers handles PATCH /users-slice/{id} requests.
|
||||
func (h *OgentHandler) UpdateUsers(ctx context.Context, req UpdateUsersReq, params UpdateUsersParams) (UpdateUsersRes, error) {
|
||||
b := h.client.Users.UpdateOneID(params.ID)
|
||||
// Add all fields.
|
||||
//if v, ok := req.Hp.Get(); ok {
|
||||
// b.SetHp(v)
|
||||
//}
|
||||
```
|
||||
|
||||
### link
|
||||
|
||||
- https://entgo.io/ja/blog/2022/02/15/generate-rest-crud-with-ent-and-ogen/
|
||||
|
||||
- https://github.com/ariga/ogent/blob/main/example/todo/ent/entc.go
|
||||
|
||||
- https://github.com/ent/ent/blob/master/dialect/sql/schema/postgres_test.go
|
||||
|
||||
- https://github.com/go-kratos/beer-shop/tree/main/app/catalog/service/internal/data/ent
|
||||
|
||||
|
||||
### update
|
||||
|
||||
```sh
|
||||
$ curl --dump-header - 'https://api.syui.ai/users' -H 'Origin: https://card.syui.ai'|less
|
||||
```
|
||||
|
||||
> ent/ogent/oas_response_encoders_gen.go
|
||||
|
||||
```go
|
||||
func encodeCreateGroupResponse(response CreateGroupRes, w http.ResponseWriter, span trace.Span) error {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "https://card.syui.ai")
|
||||
switch response := response.(type) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "https://card.syui.ai")
|
||||
```
|
||||
|
||||
### northflank
|
||||
|
||||
#### backup sqlite
|
||||
|
||||
- `cron`, `repo(private)`, `pass(token)`
|
||||
|
||||
```sh
|
||||
#!/bin/zsh
|
||||
|
||||
pass=password
|
||||
/usr/bin/northflank exec service --project $project --service $service --cmd "/app/data/api/backup.sh $pass"
|
||||
|
||||
function f(){
|
||||
rm /app/data/api/backup.sh
|
||||
echo '#!/bin/bash
|
||||
pass=$1
|
||||
git config --global user.email syui@syui.ai
|
||||
git config --global user.name syui
|
||||
cp -rf /app/data/new.sqlite /app/data/api/latest.sqlite
|
||||
cp -rf /app/data/new.sqlite /app/data/api/`date '+%w'`.sqlite
|
||||
cd /app/data/api
|
||||
git remote add origin https://$pass@github.com/ai/api
|
||||
git add .
|
||||
git commit -m backup
|
||||
git push origin main
|
||||
git remote rm origin
|
||||
' >> /app/data/api/backup.sh
|
||||
chmod +x /app/data/api/backup.sh
|
||||
}
|
||||
```
|
||||
|
||||
#### setting
|
||||
|
||||
- ports : http, 8080, dns=api.syui.ai
|
||||
- env : PASS=xxx, TOKEN=xxx
|
||||
- cmd-override : /bin/api
|
||||
- volumes : /app/data
|
||||
|
@ -3,10 +3,10 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/card"
|
||||
"api/ent/user"
|
||||
"fmt"
|
||||
"strings"
|
||||
"t/ent/card"
|
||||
"t/ent/user"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
|
@ -3,7 +3,7 @@
|
||||
package card
|
||||
|
||||
import (
|
||||
"t/ent/predicate"
|
||||
"api/ent/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
|
@ -3,11 +3,11 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/card"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"t/ent/card"
|
||||
"t/ent/user"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -3,9 +3,9 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/card"
|
||||
"api/ent/predicate"
|
||||
"context"
|
||||
"t/ent/card"
|
||||
"t/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -3,12 +3,12 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/card"
|
||||
"api/ent/predicate"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"t/ent/card"
|
||||
"t/ent/predicate"
|
||||
"t/ent/user"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -3,12 +3,12 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/card"
|
||||
"api/ent/predicate"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"t/ent/card"
|
||||
"t/ent/predicate"
|
||||
"t/ent/user"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -8,12 +8,12 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"t/ent/migrate"
|
||||
"api/ent/migrate"
|
||||
|
||||
"t/ent/card"
|
||||
"t/ent/group"
|
||||
"t/ent/ue"
|
||||
"t/ent/user"
|
||||
"api/ent/card"
|
||||
"api/ent/group"
|
||||
"api/ent/ue"
|
||||
"api/ent/user"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
|
@ -3,14 +3,14 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/card"
|
||||
"api/ent/group"
|
||||
"api/ent/ue"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"t/ent/card"
|
||||
"t/ent/group"
|
||||
"t/ent/ue"
|
||||
"t/ent/user"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
|
@ -3,12 +3,12 @@
|
||||
package enttest
|
||||
|
||||
import (
|
||||
"api/ent"
|
||||
"context"
|
||||
"t/ent"
|
||||
// required by schema hooks.
|
||||
_ "t/ent/runtime"
|
||||
_ "api/ent/runtime"
|
||||
|
||||
"t/ent/migrate"
|
||||
"api/ent/migrate"
|
||||
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
)
|
||||
|
@ -3,9 +3,9 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/group"
|
||||
"fmt"
|
||||
"strings"
|
||||
"t/ent/group"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
@ -3,7 +3,7 @@
|
||||
package group
|
||||
|
||||
import (
|
||||
"t/ent/predicate"
|
||||
"api/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -3,11 +3,11 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/group"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"t/ent/group"
|
||||
"t/ent/user"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
|
@ -3,9 +3,9 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/group"
|
||||
"api/ent/predicate"
|
||||
"context"
|
||||
"t/ent/group"
|
||||
"t/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -3,13 +3,13 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/group"
|
||||
"api/ent/predicate"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"math"
|
||||
"t/ent/group"
|
||||
"t/ent/predicate"
|
||||
"t/ent/user"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -3,12 +3,12 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/group"
|
||||
"api/ent/predicate"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"t/ent/group"
|
||||
"t/ent/predicate"
|
||||
"t/ent/user"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -3,9 +3,9 @@
|
||||
package hook
|
||||
|
||||
import (
|
||||
"api/ent"
|
||||
"context"
|
||||
"fmt"
|
||||
"t/ent"
|
||||
)
|
||||
|
||||
// The CardFunc type is an adapter to allow the use of ordinary
|
||||
|
@ -129,7 +129,7 @@ var (
|
||||
{Name: "ten_post", Type: field.TypeString, Nullable: true},
|
||||
{Name: "ten_get", Type: field.TypeString, Nullable: true},
|
||||
{Name: "ten_at", Type: field.TypeTime, Nullable: true},
|
||||
{Name: "next", Type: field.TypeString, Nullable: true, Default: "20240213"},
|
||||
{Name: "next", Type: field.TypeString, Nullable: true, Default: "20240220"},
|
||||
{Name: "room", Type: field.TypeInt, Nullable: true},
|
||||
{Name: "model", Type: field.TypeBool, Nullable: true},
|
||||
{Name: "model_at", Type: field.TypeTime, Nullable: true},
|
||||
|
@ -3,15 +3,15 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/card"
|
||||
"api/ent/group"
|
||||
"api/ent/predicate"
|
||||
"api/ent/ue"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"t/ent/card"
|
||||
"t/ent/group"
|
||||
"t/ent/predicate"
|
||||
"t/ent/ue"
|
||||
"t/ent/user"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
package ogent
|
||||
|
||||
import "t/ent"
|
||||
import "api/ent"
|
||||
|
||||
func NewCardCreate(e *ent.Card) *CardCreate {
|
||||
if e == nil {
|
||||
|
@ -3,11 +3,11 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"t/ent/card"
|
||||
"t/ent/group"
|
||||
"t/ent/schema"
|
||||
"t/ent/ue"
|
||||
"t/ent/user"
|
||||
"api/ent/card"
|
||||
"api/ent/group"
|
||||
"api/ent/schema"
|
||||
"api/ent/ue"
|
||||
"api/ent/user"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
package runtime
|
||||
|
||||
// The schema-stitching logic is generated in t/ent/runtime.go
|
||||
// The schema-stitching logic is generated in api/ent/runtime.go
|
||||
|
||||
const (
|
||||
Version = "v0.11.10" // Version of ent codegen.
|
||||
|
@ -3,10 +3,10 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/ue"
|
||||
"api/ent/user"
|
||||
"fmt"
|
||||
"strings"
|
||||
"t/ent/ue"
|
||||
"t/ent/user"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
|
@ -3,7 +3,7 @@
|
||||
package ue
|
||||
|
||||
import (
|
||||
"t/ent/predicate"
|
||||
"api/ent/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
|
@ -3,11 +3,11 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/ue"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"t/ent/ue"
|
||||
"t/ent/user"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -3,9 +3,9 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/predicate"
|
||||
"api/ent/ue"
|
||||
"context"
|
||||
"t/ent/predicate"
|
||||
"t/ent/ue"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -3,12 +3,12 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/predicate"
|
||||
"api/ent/ue"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"t/ent/predicate"
|
||||
"t/ent/ue"
|
||||
"t/ent/user"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -3,12 +3,12 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/predicate"
|
||||
"api/ent/ue"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"t/ent/predicate"
|
||||
"t/ent/ue"
|
||||
"t/ent/user"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -3,9 +3,9 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/user"
|
||||
"fmt"
|
||||
"strings"
|
||||
"t/ent/user"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
|
@ -3,7 +3,7 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"t/ent/predicate"
|
||||
"api/ent/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
|
@ -3,12 +3,12 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/card"
|
||||
"api/ent/ue"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"t/ent/card"
|
||||
"t/ent/ue"
|
||||
"t/ent/user"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -3,9 +3,9 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/predicate"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"t/ent/predicate"
|
||||
"t/ent/user"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -3,14 +3,14 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/card"
|
||||
"api/ent/predicate"
|
||||
"api/ent/ue"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"math"
|
||||
"t/ent/card"
|
||||
"t/ent/predicate"
|
||||
"t/ent/ue"
|
||||
"t/ent/user"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
|
@ -3,13 +3,13 @@
|
||||
package ent
|
||||
|
||||
import (
|
||||
"api/ent/card"
|
||||
"api/ent/predicate"
|
||||
"api/ent/ue"
|
||||
"api/ent/user"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"t/ent/card"
|
||||
"t/ent/predicate"
|
||||
"t/ent/ue"
|
||||
"t/ent/user"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
|
4
go.mod
4
go.mod
@ -1,6 +1,6 @@
|
||||
module t
|
||||
module api
|
||||
|
||||
go 1.19
|
||||
go 1.21
|
||||
|
||||
//replace ariga.io/ogent => ../../
|
||||
|
||||
|
BIN
icon/card.png
Normal file
BIN
icon/card.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 230 KiB |
4
main.go
4
main.go
@ -5,8 +5,8 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"t/ent"
|
||||
"t/ent/ogent"
|
||||
"api/ent"
|
||||
"api/ent/ogent"
|
||||
"entgo.io/ent/dialect"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"entgo.io/ent/dialect/sql/schema"
|
||||
|
96
readme.md
96
readme.md
@ -1,94 +1,16 @@
|
||||
### build
|
||||
## ai `api`
|
||||
|
||||
<img src="./icon/card.png" width="100">
|
||||
|
||||
- name : ai `api`
|
||||
- base : [go](https://go.dev/)
|
||||
- host : [card.syui.ai](https://card.syui.ai)
|
||||
|
||||
```sh
|
||||
$ vim ent/entc.go
|
||||
$ vim ent/schema/users.go
|
||||
$ go generate ./...
|
||||
$ go build
|
||||
$ ./card
|
||||
|
||||
$ go generate ./...
|
||||
$ PASS=`cat ./token.json|jq -r .password` TOKEN=`cat ./token.json|jq -r .token` go run -mod=mod main.go
|
||||
$ curl -X POST -H "Content-Type: application/json" -d "{\"username\":\"syui\",\"password\":\"$pass\"}" localhost:8080/users
|
||||
$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"password\":\"$pass\"}" localhost:8080/cards
|
||||
$ curl -X POST -H "Content-Type: application/json" -d "{\"owner\":1,\"card\":1,\"cp\":11,\"status\":\"normal\",\"password\":\"$pass\"}" localhost:8080/cards
|
||||
$ curl localhost:8080/users
|
||||
$ curl localhost:8080/cards
|
||||
$ curl localhost:8080/users/1
|
||||
$ curl localhost:8080/users/1/card
|
||||
```
|
||||
|
||||
### use
|
||||
|
||||
```sh
|
||||
$ curl -X POST -H "Content-Type: application/json" -d '{"username":"syui",\"password\":\"$pass\"}' https://api.syui.ai/users
|
||||
|
||||
# onconflict
|
||||
$ !!
|
||||
|
||||
$ curl -sL https://api.syui.ai/users/1
|
||||
```
|
||||
|
||||
```sh
|
||||
# item select
|
||||
$ curl -sL "https://api.syui.ai/users?itemsPerPage=255"
|
||||
$ curl -sL "https://api.syui.ai/cards?itemsPerPage=255"
|
||||
$ curl -sL "https://api.syui.ai/users/1/card?itemsPerPage=255"
|
||||
```
|
||||
## link
|
||||
|
||||
### ref
|
||||
- https://github.com/ariga/ogent
|
||||
|
||||
```sh
|
||||
$ vim ./ent/ogent/ogent.go
|
||||
// 新規登録の停止
|
||||
// CreateUsers handles POST /users-slice requests.
|
||||
func (h *OgentHandler) CreateUsers(ctx context.Context, req CreateUsersReq) (CreateUsersRes, error) {
|
||||
b := h.client.Users.Create()
|
||||
//b.SetUser(req.User)
|
||||
b.SetUser("syui")
|
||||
}
|
||||
|
||||
// 削除の無効
|
||||
// DeleteUsers handles DELETE /users-slice/{id} requests.
|
||||
func (h *OgentHandler) DeleteUsers(ctx context.Context, params DeleteUsersParams) (DeleteUsersRes, error) {
|
||||
if params.ID != 1 {
|
||||
err := h.client.Users.DeleteOneID(params.ID).Exec(ctx)
|
||||
}
|
||||
return new(DeleteUsersNoContent), nil
|
||||
}
|
||||
|
||||
// 要素の書き換えの禁止
|
||||
// UpdateUsers handles PATCH /users-slice/{id} requests.
|
||||
func (h *OgentHandler) UpdateUsers(ctx context.Context, req UpdateUsersReq, params UpdateUsersParams) (UpdateUsersRes, error) {
|
||||
b := h.client.Users.UpdateOneID(params.ID)
|
||||
// Add all fields.
|
||||
//if v, ok := req.Hp.Get(); ok {
|
||||
// b.SetHp(v)
|
||||
//}
|
||||
```
|
||||
|
||||
### link
|
||||
|
||||
- https://entgo.io/ja/blog/2022/02/15/generate-rest-crud-with-ent-and-ogen/
|
||||
|
||||
- https://github.com/ariga/ogent/blob/main/example/todo/ent/entc.go
|
||||
|
||||
- https://github.com/ent/ent/blob/master/dialect/sql/schema/postgres_test.go
|
||||
|
||||
- https://github.com/go-kratos/beer-shop/tree/main/app/catalog/service/internal/data/ent
|
||||
|
||||
|
||||
### update
|
||||
|
||||
```sh
|
||||
$ curl --dump-header - 'https://api.syui.ai/users' -H 'Origin: https://card.syui.ai'|less
|
||||
```
|
||||
|
||||
> ent/ogent/oas_response_encoders_gen.go
|
||||
|
||||
```go
|
||||
func encodeCreateGroupResponse(response CreateGroupRes, w http.ResponseWriter, span trace.Span) error {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "https://card.syui.ai")
|
||||
switch response := response.(type) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "https://card.syui.ai")
|
||||
```
|
||||
|
3
run.zsh
3
run.zsh
@ -1,3 +0,0 @@
|
||||
#!/bin/zsh
|
||||
d=${0:a:h}
|
||||
PASS=`cat token.json|jq -r .password` go run -mod=mod main.go
|
23
scpt/card_day.zsh
Executable file
23
scpt/card_day.zsh
Executable file
@ -0,0 +1,23 @@
|
||||
#!/bin/zsh
|
||||
|
||||
case $OSTYPE in
|
||||
darwin*)
|
||||
alias date="/opt/homebrew/bin/gdate"
|
||||
;;
|
||||
esac
|
||||
host=https://api.syui.ai
|
||||
token=`cat ~/.config/atr/api_card.json|jq -r .token`
|
||||
host_users="$host/users?itemsPerPage=2550"
|
||||
data=`curl -sL "$host_users"|jq .`
|
||||
nd=`date +"%Y%m%d"`
|
||||
|
||||
n=`echo $data|jq length`
|
||||
n=$((n - 1))
|
||||
|
||||
for ((i=0;i<=$n;i++))
|
||||
do
|
||||
name=`echo $data|jq ".[$i]"|jq -r .username`
|
||||
id=`echo $data|jq ".[$i]"|jq -r .id`
|
||||
echo "{\"next\":\"$nd\"} -s $host/users/$id"
|
||||
curl -X PATCH -H "Content-Type: application/json" -d "{\"next\":\"$nd\",\"token\":\"$token\"}" -s $host/users/$id
|
||||
done
|
23
scpt/card_delete.zsh
Executable file
23
scpt/card_delete.zsh
Executable file
@ -0,0 +1,23 @@
|
||||
#!/bin/zsh
|
||||
|
||||
if [ -z "$1" ];then
|
||||
exit
|
||||
fi
|
||||
echo delete-id
|
||||
read
|
||||
id=$1
|
||||
data=`curl -sL "https://api.syui.ai/users/$id/card?itemsPerPage=2550"`
|
||||
token=`cat ~/.config/atr/api_card.json|jq -r .token`
|
||||
pass=`cat ~/.config/atr/api_card.json|jq -r .password`
|
||||
|
||||
n=`echo $data|jq length`
|
||||
|
||||
n=$((n - 1))
|
||||
|
||||
for ((i=0;i<=$n;i++))
|
||||
do
|
||||
card_id=`echo $data|jq -r ".[$i].id"`
|
||||
echo $card
|
||||
curl -X DELETE -H "Content-Type: application/json" -d "{\"owner\":$id,\"password\":\"$pass\"}" https://api.syui.ai/cards/$card_id
|
||||
done
|
||||
#curl -X DELETE -H "Content-Type: application/json" https://api.syui.ai/users/$id
|
24
scpt/card_limit.zsh
Executable file
24
scpt/card_limit.zsh
Executable file
@ -0,0 +1,24 @@
|
||||
#!/bin/zsh
|
||||
|
||||
case $OSTYPE in
|
||||
darwin*)
|
||||
alias date="/opt/homebrew/bin/gdate"
|
||||
;;
|
||||
esac
|
||||
host=https://api.syui.ai
|
||||
token=`cat ~/.config/atr/api_card.json|jq -r .token`
|
||||
host_users="$host/users?itemsPerPage=2550"
|
||||
updated_at_n=`date --iso-8601=seconds -d '1 days ago'`
|
||||
#updated_at_n=`date --iso-8601=seconds`
|
||||
data=`curl -sL "$host_users"|jq .`
|
||||
|
||||
n=`echo $data|jq length`
|
||||
n=$((n - 1))
|
||||
|
||||
for ((i=0;i<=$n;i++))
|
||||
do
|
||||
name=`echo $data|jq ".[$i]"|jq -r .username`
|
||||
id=`echo $data|jq ".[$i]"|jq -r .id`
|
||||
echo "{\"updated_at\":\"$updated_at_n\"} -s $host/users/$id"
|
||||
curl -X PATCH -H "Content-Type: application/json" -d "{\"raid_at\": \"$updated_at_n\",\"updated_at\":\"$updated_at_n\",\"token\":\"$token\",\"ten_at\":\"$updated_at_n\"}" -s $host/users/$id
|
||||
done
|
Loading…
Reference in New Issue
Block a user