test seven
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
"api/ent/group"
|
||||
"api/ent/ma"
|
||||
"api/ent/ue"
|
||||
"api/ent/sev"
|
||||
"api/ent/user"
|
||||
|
||||
"os"
|
||||
@ -781,6 +782,263 @@ func (h *OgentHandler) ReadMaOwner(ctx context.Context, params ReadMaOwnerParams
|
||||
return NewMaOwnerRead(e), nil
|
||||
}
|
||||
|
||||
// CreateSev handles POST /sevs requests.
|
||||
func (h *OgentHandler) CreateSev(ctx context.Context, req *CreateSevReq) (CreateSevRes, error) {
|
||||
b := h.client.Sev.Create()
|
||||
// Add all fields.
|
||||
b.SetPassword(req.Password)
|
||||
if v, ok := req.Token.Get(); ok {
|
||||
b.SetToken(v)
|
||||
}
|
||||
if v, ok := req.Limit.Get(); ok {
|
||||
b.SetLimit(v)
|
||||
}
|
||||
if v, ok := req.Count.Get(); ok {
|
||||
b.SetCount(v)
|
||||
}
|
||||
if v, ok := req.Handle.Get(); ok {
|
||||
b.SetHandle(v)
|
||||
}
|
||||
if v, ok := req.Did.Get(); ok {
|
||||
b.SetDid(v)
|
||||
}
|
||||
if v, ok := req.UID.Get(); ok {
|
||||
b.SetUID(v)
|
||||
}
|
||||
if v, ok := req.Cid.Get(); ok {
|
||||
b.SetCid(v)
|
||||
}
|
||||
if v, ok := req.UpdatedAt.Get(); ok {
|
||||
b.SetUpdatedAt(v)
|
||||
}
|
||||
if v, ok := req.CreatedAt.Get(); ok {
|
||||
b.SetCreatedAt(v)
|
||||
}
|
||||
|
||||
// Add all edges.
|
||||
//b.SetOwnerID(req.Owner)
|
||||
if req.Password == password {
|
||||
b.SetOwnerID(req.Owner)
|
||||
} else {
|
||||
b.SetOwnerID(0)
|
||||
}
|
||||
// Persist to storage.
|
||||
e, err := b.Save(ctx)
|
||||
if err != nil {
|
||||
switch {
|
||||
case ent.IsNotSingular(err):
|
||||
return &R409{
|
||||
Code: http.StatusConflict,
|
||||
Status: http.StatusText(http.StatusConflict),
|
||||
Errors: rawError(err),
|
||||
}, nil
|
||||
case ent.IsConstraintError(err):
|
||||
return &R409{
|
||||
Code: http.StatusConflict,
|
||||
Status: http.StatusText(http.StatusConflict),
|
||||
Errors: rawError(err),
|
||||
}, nil
|
||||
default:
|
||||
// Let the server handle the error.
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
// Reload the entity to attach all eager-loaded edges.
|
||||
q := h.client.Sev.Query().Where(sev.ID(e.ID))
|
||||
e, err = q.Only(ctx)
|
||||
if err != nil {
|
||||
// This should never happen.
|
||||
return nil, err
|
||||
}
|
||||
return NewSevCreate(e), nil
|
||||
}
|
||||
|
||||
// ReadSev handles GET /sevs/{id} requests.
|
||||
func (h *OgentHandler) ReadSev(ctx context.Context, params ReadSevParams) (ReadSevRes, error) {
|
||||
q := h.client.Sev.Query().Where(sev.IDEQ(params.ID))
|
||||
e, err := q.Only(ctx)
|
||||
if err != nil {
|
||||
switch {
|
||||
case ent.IsNotFound(err):
|
||||
return &R404{
|
||||
Code: http.StatusNotFound,
|
||||
Status: http.StatusText(http.StatusNotFound),
|
||||
Errors: rawError(err),
|
||||
}, nil
|
||||
case ent.IsNotSingular(err):
|
||||
return &R409{
|
||||
Code: http.StatusConflict,
|
||||
Status: http.StatusText(http.StatusConflict),
|
||||
Errors: rawError(err),
|
||||
}, nil
|
||||
default:
|
||||
// Let the server handle the error.
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return NewSevRead(e), nil
|
||||
}
|
||||
|
||||
// UpdateSev handles PATCH /sevs/{id} requests.
|
||||
func (h *OgentHandler) UpdateSev(ctx context.Context, req *UpdateSevReq, params UpdateSevParams) (UpdateSevRes, error) {
|
||||
b := h.client.Sev.UpdateOneID(params.ID)
|
||||
// Add all fields.
|
||||
if v, ok := req.Token.Get(); ok {
|
||||
b.SetToken(v)
|
||||
}
|
||||
if v, ok := req.Limit.Get(); ok {
|
||||
b.SetLimit(v)
|
||||
}
|
||||
if v, ok := req.Count.Get(); ok {
|
||||
b.SetCount(v)
|
||||
}
|
||||
if v, ok := req.Handle.Get(); ok {
|
||||
b.SetHandle(v)
|
||||
}
|
||||
if v, ok := req.Did.Get(); ok {
|
||||
b.SetDid(v)
|
||||
}
|
||||
if v, ok := req.UID.Get(); ok {
|
||||
b.SetUID(v)
|
||||
}
|
||||
if v, ok := req.Cid.Get(); ok {
|
||||
b.SetCid(v)
|
||||
}
|
||||
if v, ok := req.UpdatedAt.Get(); ok {
|
||||
b.SetUpdatedAt(v)
|
||||
}
|
||||
// Add all edges.
|
||||
//if v, ok := req.Owner.Get(); ok {
|
||||
// b.SetOwnerID(v)
|
||||
//}
|
||||
if v, ok := req.Token.Get(); ok {
|
||||
if v == token {
|
||||
b.SetToken(v)
|
||||
if v, ok := req.Owner.Get(); ok {
|
||||
b.SetOwnerID(v)
|
||||
}
|
||||
}
|
||||
// Persist to storage.
|
||||
e, err := b.Save(ctx)
|
||||
if err != nil {
|
||||
switch {
|
||||
case ent.IsNotFound(err):
|
||||
return &R404{
|
||||
Code: http.StatusNotFound,
|
||||
Status: http.StatusText(http.StatusNotFound),
|
||||
Errors: rawError(err),
|
||||
}, nil
|
||||
case ent.IsConstraintError(err):
|
||||
return &R409{
|
||||
Code: http.StatusConflict,
|
||||
Status: http.StatusText(http.StatusConflict),
|
||||
Errors: rawError(err),
|
||||
}, nil
|
||||
default:
|
||||
// Let the server handle the error.
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
// Reload the entity to attach all eager-loaded edges.
|
||||
q := h.client.Sev.Query().Where(sev.ID(e.ID))
|
||||
e, err = q.Only(ctx)
|
||||
if err != nil {
|
||||
// This should never happen.
|
||||
return nil, err
|
||||
}
|
||||
return NewSevUpdate(e), nil
|
||||
}
|
||||
|
||||
// DeleteSev handles DELETE /sevs/{id} requests.
|
||||
func (h *OgentHandler) DeleteSev(ctx context.Context, params DeleteSevParams) (DeleteSevRes, error) {
|
||||
//err := h.client.Sev.DeleteOneID(params.ID).Exec(ctx)
|
||||
err := h.client.Sev.DeleteOneID(0).Exec(ctx)
|
||||
if err != nil {
|
||||
switch {
|
||||
case ent.IsNotFound(err):
|
||||
return &R404{
|
||||
Code: http.StatusNotFound,
|
||||
Status: http.StatusText(http.StatusNotFound),
|
||||
Errors: rawError(err),
|
||||
}, nil
|
||||
case ent.IsConstraintError(err):
|
||||
return &R409{
|
||||
Code: http.StatusConflict,
|
||||
Status: http.StatusText(http.StatusConflict),
|
||||
Errors: rawError(err),
|
||||
}, nil
|
||||
default:
|
||||
// Let the server handle the error.
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return new(DeleteSevNoContent), nil
|
||||
|
||||
}
|
||||
|
||||
// ListSev handles GET /sevs requests.
|
||||
func (h *OgentHandler) ListSev(ctx context.Context, params ListSevParams) (ListSevRes, error) {
|
||||
q := h.client.Sev.Query()
|
||||
page := 1
|
||||
if v, ok := params.Page.Get(); ok {
|
||||
page = v
|
||||
}
|
||||
itemsPerPage := 30
|
||||
if v, ok := params.ItemsPerPage.Get(); ok {
|
||||
itemsPerPage = v
|
||||
}
|
||||
q.Limit(itemsPerPage).Offset((page - 1) * itemsPerPage)
|
||||
|
||||
es, err := q.All(ctx)
|
||||
if err != nil {
|
||||
switch {
|
||||
case ent.IsNotFound(err):
|
||||
return &R404{
|
||||
Code: http.StatusNotFound,
|
||||
Status: http.StatusText(http.StatusNotFound),
|
||||
Errors: rawError(err),
|
||||
}, nil
|
||||
case ent.IsNotSingular(err):
|
||||
return &R409{
|
||||
Code: http.StatusConflict,
|
||||
Status: http.StatusText(http.StatusConflict),
|
||||
Errors: rawError(err),
|
||||
}, nil
|
||||
default:
|
||||
// Let the server handle the error.
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
r := NewSevLists(es)
|
||||
return (*ListSevOKApplicationJSON)(&r), nil
|
||||
}
|
||||
|
||||
// ReadSevOwner handles GET /sevs/{id}/owner requests.
|
||||
func (h *OgentHandler) ReadSevOwner(ctx context.Context, params ReadSevOwnerParams) (ReadSevOwnerRes, error) {
|
||||
q := h.client.Sev.Query().Where(sev.IDEQ(params.ID)).QueryOwner()
|
||||
e, err := q.Only(ctx)
|
||||
if err != nil {
|
||||
switch {
|
||||
case ent.IsNotFound(err):
|
||||
return &R404{
|
||||
Code: http.StatusNotFound,
|
||||
Status: http.StatusText(http.StatusNotFound),
|
||||
Errors: rawError(err),
|
||||
}, nil
|
||||
case ent.IsNotSingular(err):
|
||||
return &R409{
|
||||
Code: http.StatusConflict,
|
||||
Status: http.StatusText(http.StatusConflict),
|
||||
Errors: rawError(err),
|
||||
}, nil
|
||||
default:
|
||||
// Let the server handle the error.
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return NewSevOwnerRead(e), nil
|
||||
}
|
||||
|
||||
// CreateUe handles POST /ues requests.
|
||||
func (h *OgentHandler) CreateUe(ctx context.Context, req *CreateUeReq) (CreateUeRes, error) {
|
||||
b := h.client.Ue.Create()
|
||||
@ -1671,3 +1929,39 @@ func (h *OgentHandler) ListUserMa(ctx context.Context, params ListUserMaParams)
|
||||
r := NewUserMaLists(es)
|
||||
return (*ListUserMaOKApplicationJSON)(&r), nil
|
||||
}
|
||||
|
||||
// ListUserSev handles GET /users/{id}/sev requests.
|
||||
func (h *OgentHandler) ListUserSev(ctx context.Context, params ListUserSevParams) (ListUserSevRes, error) {
|
||||
q := h.client.User.Query().Where(user.IDEQ(params.ID)).QuerySev()
|
||||
page := 1
|
||||
if v, ok := params.Page.Get(); ok {
|
||||
page = v
|
||||
}
|
||||
itemsPerPage := 30
|
||||
if v, ok := params.ItemsPerPage.Get(); ok {
|
||||
itemsPerPage = v
|
||||
}
|
||||
q.Limit(itemsPerPage).Offset((page - 1) * itemsPerPage)
|
||||
es, err := q.All(ctx)
|
||||
if err != nil {
|
||||
switch {
|
||||
case ent.IsNotFound(err):
|
||||
return &R404{
|
||||
Code: http.StatusNotFound,
|
||||
Status: http.StatusText(http.StatusNotFound),
|
||||
Errors: rawError(err),
|
||||
}, nil
|
||||
case ent.IsNotSingular(err):
|
||||
return &R409{
|
||||
Code: http.StatusConflict,
|
||||
Status: http.StatusText(http.StatusConflict),
|
||||
Errors: rawError(err),
|
||||
}, nil
|
||||
default:
|
||||
// Let the server handle the error.
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
r := NewUserSevLists(es)
|
||||
return (*ListUserSevOKApplicationJSON)(&r), nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user