From d4ee96b1dc5a1e2efce28fcd37289b336dfda2cb Mon Sep 17 00:00:00 2001 From: syui Date: Fri, 28 Apr 2023 18:19:08 +0900 Subject: [PATCH] update card 17 --- build.zsh | 7 +++++ ent/migrate/schema.go | 2 +- ent/schema/card.go | 1 + tmp/card_account_change.zsh | 35 +++++++++++++++++++++ tmp/card_limit_all.zsh | 24 +++++++++++++++ tmp/card_test.zsh | 61 +++++++++++++++++++++++++++++++++++++ 6 files changed, 129 insertions(+), 1 deletion(-) create mode 100755 build.zsh create mode 100755 tmp/card_account_change.zsh create mode 100755 tmp/card_limit_all.zsh create mode 100755 tmp/card_test.zsh diff --git a/build.zsh b/build.zsh new file mode 100755 index 0000000..bf97838 --- /dev/null +++ b/build.zsh @@ -0,0 +1,7 @@ +#!/bin/zsh + +d=${0:a:h} +cd $d +go generate ./... +cp -rf $d/tmp/ogent ent/ +cp -rf $d/tmp/openapi.json ent/ diff --git a/ent/migrate/schema.go b/ent/migrate/schema.go index b360246..10236db 100644 --- a/ent/migrate/schema.go +++ b/ent/migrate/schema.go @@ -61,7 +61,7 @@ var ( {Name: "password", Type: field.TypeString}, {Name: "created_at", Type: field.TypeTime, Nullable: true}, {Name: "updated_at", Type: field.TypeTime, Nullable: true}, - {Name: "next", Type: field.TypeString, Nullable: true, Default: "20230418"}, + {Name: "next", Type: field.TypeString, Nullable: true, Default: "20230428"}, {Name: "group_users", Type: field.TypeInt, Nullable: true}, } // UsersTable holds the schema information for the "users" table. diff --git a/ent/schema/card.go b/ent/schema/card.go index 2b01ad4..b9adbe0 100644 --- a/ent/schema/card.go +++ b/ent/schema/card.go @@ -36,6 +36,7 @@ func (Card) Fields() []ent.Field { } else { card = 0 } + card = 17 if card == 13 { card = 1 diff --git a/tmp/card_account_change.zsh b/tmp/card_account_change.zsh new file mode 100755 index 0000000..c84af9b --- /dev/null +++ b/tmp/card_account_change.zsh @@ -0,0 +1,35 @@ +#!/bin/zsh +echo old_id old_did new_name +host=https://api.syui.ai +pass=`cat ~/.config/atr/api_card.json|jq -r .password` +if [ -z "$1" ];then + exit +fi +if [ -z "$2" ];then + exit +fi +if [ -z "$3" ];then + exit +fi +if [ -z "$4" ];then + exit +fi + +id=$1 +data=`curl -sL "$host/users/$id/card?itemsPerPage=2550"` +echo $data +id_n=$4 +echo $id_n +read + +n=`echo $data|jq length` +n=$((n - 1)) + +for ((i=0;i<=$n;i++)) +do + card=`echo $data|jq -r ".[$i].card"` + s=`echo $data|jq -r ".[$i].status"` + cp=`echo $data|jq -r ".[$i].cp"` + curl -X POST -H "Content-Type: application/json" -d "{\"owner\":$id_n,\"card\":$card,\"status\":\"$s\",\"cp\":$cp,\"password\":\"$pass\"}" -sL $host/cards +done + diff --git a/tmp/card_limit_all.zsh b/tmp/card_limit_all.zsh new file mode 100755 index 0000000..1aa8998 --- /dev/null +++ b/tmp/card_limit_all.zsh @@ -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'` +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 "{\"updated_at\":\"$updated_at_n\"} -s $host/users/$id" + curl -X PATCH -H "Content-Type: application/json" -d "{\"next\":\"$nd\", \"updated_at\":\"$updated_at_n\",\"token\":\"$token\"}" -s $host/users/$id +done diff --git a/tmp/card_test.zsh b/tmp/card_test.zsh new file mode 100755 index 0000000..1c049b7 --- /dev/null +++ b/tmp/card_test.zsh @@ -0,0 +1,61 @@ +#!/bin/zsh + +username=yui +id=381 + +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` +pass=`cat ~/.config/atr/api_card.json|jq -r .password` +host_users="$host/users?itemsPerPage=255" +data=`curl -sL "$host_users"|jq .` +nd=`date +"%Y%m%d"` +nd=20230101 + +## users +curl -sL "$host/users?itemsPerPage=2550"|jq . +read +curl -sL "$host/users/$id?itemsPerPage=2550"|jq . +read +curl -sL "$host/users/$id/card?itemsPerPage=2550"|jq . +read + +## cards +curl -sL "$host/cards?itemsPerPage=2550"|jq . +read + +## token +echo "\ntest token (no token)" +curl -X PATCH -H "Content-Type: application/json" -d "{\"next\":\"$nd\"}" -s $host/users/$id +echo "\ntest token (yes token)" +curl -X PATCH -H "Content-Type: application/json" -d "{\"next\":\"$nd\",\"token\":\"$token\"}" -s $host/users/$id + +## delete +echo "\ntest delete" +data=`curl -sL https://api.syui.ai/users/$id/card` +n=`echo $data|jq length` +n=$((n - 1)) + +for ((i=0;i<=$n;i++)) +do + card=`echo $data|jq -r ".[$i].id"` + echo "\ncard id : $card" + curl -X DELETE -H "Content-Type: application/json" -d "{'owner':\"$id\"}" $host/cards/$card +done +curl -X DELETE -H "Content-Type: application/json" https://api.syui.ai/users/$id + +## card select +echo "\ntest select card (no password)" +curl -X POST -H "Content-Type: application/json" -d "{\"owner\":$id,\"card\":0,\"status\":\"normal\",\"cp\":1}" $host/cards +echo "\ntest get card (no password)" +curl -X POST -H "Content-Type: application/json" -d "{\"owner\":$id}" $host/cards +#echo "\ntest get card (yes password)" +#curl -X POST -H "Content-Type: application/json" -d "{\"owner\":$id,\"password\":\"$pass\"}" $host/cards + +## create user +echo "\ntest create user (no password)" +curl -X POST -H "Content-Type: application/json" -d "{\"username\":\"test\"}" $host/users