1
0

fix card id 1,2

This commit is contained in:
syui 2023-04-08 11:23:05 +09:00
parent 175ab09869
commit e454d97086
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56
5 changed files with 10 additions and 23 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ t
*.json
*.sqlite
#*.zsh
tmp/card_limit.zsh

View File

@ -59,7 +59,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: "20230406"},
{Name: "next", Type: field.TypeString, Nullable: true, Default: "20230409"},
{Name: "group_users", Type: field.TypeInt, Nullable: true},
}
// UsersTable holds the schema information for the "users" table.

View File

@ -12,11 +12,8 @@ import (
"t/ent/user"
"github.com/go-faster/jx"
"os"
)
var password = os.Getenv("PASS")
var zero = "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
// OgentHandler implements the ogen generated Handler interface and uses Ent as data layer.
type OgentHandler struct {
client *ent.Client
@ -53,12 +50,7 @@ func (h *OgentHandler) CreateCard(ctx context.Context, req *CreateCardReq) (Crea
b.SetCreatedAt(v)
}
// Add all edges.
if req.Password == password {
b.SetOwnerID(req.Owner)
} else {
b.SetOwnerID(0)
}
b.SetOwnerID(req.Owner)
// Persist to storage.
e, err := b.Save(ctx)
if err != nil {
@ -118,7 +110,7 @@ func (h *OgentHandler) ReadCard(ctx context.Context, params ReadCardParams) (Rea
// UpdateCard handles PATCH /cards/{id} requests.
func (h *OgentHandler) UpdateCard(ctx context.Context, req *UpdateCardReq, params UpdateCardParams) (UpdateCardRes, error) {
b := h.client.Card.UpdateOneID(0)
b := h.client.Card.UpdateOneID(params.ID)
// Add all fields.
// Add all edges.
if v, ok := req.Owner.Get(); ok {
@ -157,7 +149,7 @@ func (h *OgentHandler) UpdateCard(ctx context.Context, req *UpdateCardReq, param
// DeleteCard handles DELETE /cards/{id} requests.
func (h *OgentHandler) DeleteCard(ctx context.Context, params DeleteCardParams) (DeleteCardRes, error) {
err := h.client.Card.DeleteOneID(0).Exec(ctx)
err := h.client.Card.DeleteOneID(params.ID).Exec(ctx)
if err != nil {
switch {
case ent.IsNotFound(err):
@ -311,7 +303,7 @@ func (h *OgentHandler) ReadGroup(ctx context.Context, params ReadGroupParams) (R
// UpdateGroup handles PATCH /groups/{id} requests.
func (h *OgentHandler) UpdateGroup(ctx context.Context, req *UpdateGroupReq, params UpdateGroupParams) (UpdateGroupRes, error) {
b := h.client.Group.UpdateOneID(0)
b := h.client.Group.UpdateOneID(params.ID)
// Add all fields.
if v, ok := req.Name.Get(); ok {
b.SetName(v)
@ -454,11 +446,7 @@ func (h *OgentHandler) ListGroupUsers(ctx context.Context, params ListGroupUsers
func (h *OgentHandler) CreateUser(ctx context.Context, req *CreateUserReq) (CreateUserRes, error) {
b := h.client.User.Create()
// Add all fields.
if req.Password == password {
b.SetUsername(req.Username)
} else {
b.SetUsername("")
}
b.SetUsername(req.Username)
b.SetPassword(req.Password)
if v, ok := req.CreatedAt.Get(); ok {
b.SetCreatedAt(v)
@ -473,7 +461,6 @@ func (h *OgentHandler) CreateUser(ctx context.Context, req *CreateUserReq) (Crea
b.AddCardIDs(req.Card...)
// Persist to storage.
e, err := b.Save(ctx)
if err != nil {
switch {
case ent.IsNotSingular(err):
@ -576,7 +563,7 @@ func (h *OgentHandler) UpdateUser(ctx context.Context, req *UpdateUserReq, param
// DeleteUser handles DELETE /users/{id} requests.
func (h *OgentHandler) DeleteUser(ctx context.Context, params DeleteUserParams) (DeleteUserRes, error) {
err := h.client.User.DeleteOneID(0).Exec(ctx)
err := h.client.User.DeleteOneID(params.ID).Exec(ctx)
if err != nil {
switch {
case ent.IsNotFound(err):

View File

@ -66,9 +66,9 @@ func (Card) Fields() []ent.Field {
rand.Seed(time.Now().UnixNano())
var cp = 1 + rand.Intn(100)
if cp == 2 {
cp = 50 + rand.Intn(200)
cp = 50 + rand.Intn(100)
}
if card > 2 {
if card >= 1 {
cp = 50 + cp + rand.Intn(200)
}
if super == "super" {

View File

@ -45,6 +45,5 @@ do
l_cards
fi
done
done