386 lines
7.5 KiB
Go
386 lines
7.5 KiB
Go
package request
|
|
|
|
/*
|
|
Hello! This file is auto-generated from `docs/src/spec.json`.
|
|
|
|
For development:
|
|
In order to update the generated files, edit this file under the location,
|
|
add your struct fields, imports, API definitions and whatever you want, and:
|
|
|
|
1. run [spec](https://github.com/titpetric/spec) in the same folder,
|
|
2. run `./_gen.php` in this folder.
|
|
|
|
You may edit `user.go`, `user.util.go` or `user_test.go` to
|
|
implement your API calls, helper functions and tests. The file `user.go`
|
|
is only generated the first time, and will not be overwritten if it exists.
|
|
*/
|
|
|
|
import (
|
|
"io"
|
|
"strings"
|
|
|
|
"encoding/json"
|
|
"mime/multipart"
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi"
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/crusttech/crust/system/types"
|
|
)
|
|
|
|
var _ = chi.URLParam
|
|
var _ = multipart.FileHeader{}
|
|
|
|
// User list request parameters
|
|
type UserList struct {
|
|
Query string
|
|
Username string
|
|
Email string
|
|
}
|
|
|
|
func NewUserList() *UserList {
|
|
return &UserList{}
|
|
}
|
|
|
|
func (usReq *UserList) Fill(r *http.Request) (err error) {
|
|
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
|
err = json.NewDecoder(r.Body).Decode(usReq)
|
|
|
|
switch {
|
|
case err == io.EOF:
|
|
err = nil
|
|
case err != nil:
|
|
return errors.Wrap(err, "error parsing http request body")
|
|
}
|
|
}
|
|
|
|
if err = r.ParseForm(); err != nil {
|
|
return err
|
|
}
|
|
|
|
get := map[string]string{}
|
|
post := map[string]string{}
|
|
urlQuery := r.URL.Query()
|
|
for name, param := range urlQuery {
|
|
get[name] = string(param[0])
|
|
}
|
|
postVars := r.Form
|
|
for name, param := range postVars {
|
|
post[name] = string(param[0])
|
|
}
|
|
|
|
if val, ok := get["query"]; ok {
|
|
|
|
usReq.Query = val
|
|
}
|
|
if val, ok := get["username"]; ok {
|
|
|
|
usReq.Username = val
|
|
}
|
|
if val, ok := get["email"]; ok {
|
|
|
|
usReq.Email = val
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
var _ RequestFiller = NewUserList()
|
|
|
|
// User create request parameters
|
|
type UserCreate struct {
|
|
Email string
|
|
Name string
|
|
Handle string
|
|
Kind types.UserKind
|
|
}
|
|
|
|
func NewUserCreate() *UserCreate {
|
|
return &UserCreate{}
|
|
}
|
|
|
|
func (usReq *UserCreate) Fill(r *http.Request) (err error) {
|
|
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
|
err = json.NewDecoder(r.Body).Decode(usReq)
|
|
|
|
switch {
|
|
case err == io.EOF:
|
|
err = nil
|
|
case err != nil:
|
|
return errors.Wrap(err, "error parsing http request body")
|
|
}
|
|
}
|
|
|
|
if err = r.ParseForm(); err != nil {
|
|
return err
|
|
}
|
|
|
|
get := map[string]string{}
|
|
post := map[string]string{}
|
|
urlQuery := r.URL.Query()
|
|
for name, param := range urlQuery {
|
|
get[name] = string(param[0])
|
|
}
|
|
postVars := r.Form
|
|
for name, param := range postVars {
|
|
post[name] = string(param[0])
|
|
}
|
|
|
|
if val, ok := post["email"]; ok {
|
|
|
|
usReq.Email = val
|
|
}
|
|
if val, ok := post["name"]; ok {
|
|
|
|
usReq.Name = val
|
|
}
|
|
if val, ok := post["handle"]; ok {
|
|
|
|
usReq.Handle = val
|
|
}
|
|
if val, ok := post["kind"]; ok {
|
|
|
|
usReq.Kind = types.UserKind(val)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
var _ RequestFiller = NewUserCreate()
|
|
|
|
// User update request parameters
|
|
type UserUpdate struct {
|
|
UserID uint64 `json:",string"`
|
|
Email string
|
|
Name string
|
|
Handle string
|
|
Kind types.UserKind
|
|
}
|
|
|
|
func NewUserUpdate() *UserUpdate {
|
|
return &UserUpdate{}
|
|
}
|
|
|
|
func (usReq *UserUpdate) Fill(r *http.Request) (err error) {
|
|
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
|
err = json.NewDecoder(r.Body).Decode(usReq)
|
|
|
|
switch {
|
|
case err == io.EOF:
|
|
err = nil
|
|
case err != nil:
|
|
return errors.Wrap(err, "error parsing http request body")
|
|
}
|
|
}
|
|
|
|
if err = r.ParseForm(); err != nil {
|
|
return err
|
|
}
|
|
|
|
get := map[string]string{}
|
|
post := map[string]string{}
|
|
urlQuery := r.URL.Query()
|
|
for name, param := range urlQuery {
|
|
get[name] = string(param[0])
|
|
}
|
|
postVars := r.Form
|
|
for name, param := range postVars {
|
|
post[name] = string(param[0])
|
|
}
|
|
|
|
usReq.UserID = parseUInt64(chi.URLParam(r, "userID"))
|
|
if val, ok := post["email"]; ok {
|
|
|
|
usReq.Email = val
|
|
}
|
|
if val, ok := post["name"]; ok {
|
|
|
|
usReq.Name = val
|
|
}
|
|
if val, ok := post["handle"]; ok {
|
|
|
|
usReq.Handle = val
|
|
}
|
|
if val, ok := post["kind"]; ok {
|
|
|
|
usReq.Kind = types.UserKind(val)
|
|
}
|
|
|
|
return err
|
|
}
|
|
|
|
var _ RequestFiller = NewUserUpdate()
|
|
|
|
// User read request parameters
|
|
type UserRead struct {
|
|
UserID uint64 `json:",string"`
|
|
}
|
|
|
|
func NewUserRead() *UserRead {
|
|
return &UserRead{}
|
|
}
|
|
|
|
func (usReq *UserRead) Fill(r *http.Request) (err error) {
|
|
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
|
err = json.NewDecoder(r.Body).Decode(usReq)
|
|
|
|
switch {
|
|
case err == io.EOF:
|
|
err = nil
|
|
case err != nil:
|
|
return errors.Wrap(err, "error parsing http request body")
|
|
}
|
|
}
|
|
|
|
if err = r.ParseForm(); err != nil {
|
|
return err
|
|
}
|
|
|
|
get := map[string]string{}
|
|
post := map[string]string{}
|
|
urlQuery := r.URL.Query()
|
|
for name, param := range urlQuery {
|
|
get[name] = string(param[0])
|
|
}
|
|
postVars := r.Form
|
|
for name, param := range postVars {
|
|
post[name] = string(param[0])
|
|
}
|
|
|
|
usReq.UserID = parseUInt64(chi.URLParam(r, "userID"))
|
|
|
|
return err
|
|
}
|
|
|
|
var _ RequestFiller = NewUserRead()
|
|
|
|
// User delete request parameters
|
|
type UserDelete struct {
|
|
UserID uint64 `json:",string"`
|
|
}
|
|
|
|
func NewUserDelete() *UserDelete {
|
|
return &UserDelete{}
|
|
}
|
|
|
|
func (usReq *UserDelete) Fill(r *http.Request) (err error) {
|
|
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
|
err = json.NewDecoder(r.Body).Decode(usReq)
|
|
|
|
switch {
|
|
case err == io.EOF:
|
|
err = nil
|
|
case err != nil:
|
|
return errors.Wrap(err, "error parsing http request body")
|
|
}
|
|
}
|
|
|
|
if err = r.ParseForm(); err != nil {
|
|
return err
|
|
}
|
|
|
|
get := map[string]string{}
|
|
post := map[string]string{}
|
|
urlQuery := r.URL.Query()
|
|
for name, param := range urlQuery {
|
|
get[name] = string(param[0])
|
|
}
|
|
postVars := r.Form
|
|
for name, param := range postVars {
|
|
post[name] = string(param[0])
|
|
}
|
|
|
|
usReq.UserID = parseUInt64(chi.URLParam(r, "userID"))
|
|
|
|
return err
|
|
}
|
|
|
|
var _ RequestFiller = NewUserDelete()
|
|
|
|
// User suspend request parameters
|
|
type UserSuspend struct {
|
|
UserID uint64 `json:",string"`
|
|
}
|
|
|
|
func NewUserSuspend() *UserSuspend {
|
|
return &UserSuspend{}
|
|
}
|
|
|
|
func (usReq *UserSuspend) Fill(r *http.Request) (err error) {
|
|
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
|
err = json.NewDecoder(r.Body).Decode(usReq)
|
|
|
|
switch {
|
|
case err == io.EOF:
|
|
err = nil
|
|
case err != nil:
|
|
return errors.Wrap(err, "error parsing http request body")
|
|
}
|
|
}
|
|
|
|
if err = r.ParseForm(); err != nil {
|
|
return err
|
|
}
|
|
|
|
get := map[string]string{}
|
|
post := map[string]string{}
|
|
urlQuery := r.URL.Query()
|
|
for name, param := range urlQuery {
|
|
get[name] = string(param[0])
|
|
}
|
|
postVars := r.Form
|
|
for name, param := range postVars {
|
|
post[name] = string(param[0])
|
|
}
|
|
|
|
usReq.UserID = parseUInt64(chi.URLParam(r, "userID"))
|
|
|
|
return err
|
|
}
|
|
|
|
var _ RequestFiller = NewUserSuspend()
|
|
|
|
// User unsuspend request parameters
|
|
type UserUnsuspend struct {
|
|
UserID uint64 `json:",string"`
|
|
}
|
|
|
|
func NewUserUnsuspend() *UserUnsuspend {
|
|
return &UserUnsuspend{}
|
|
}
|
|
|
|
func (usReq *UserUnsuspend) Fill(r *http.Request) (err error) {
|
|
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
|
err = json.NewDecoder(r.Body).Decode(usReq)
|
|
|
|
switch {
|
|
case err == io.EOF:
|
|
err = nil
|
|
case err != nil:
|
|
return errors.Wrap(err, "error parsing http request body")
|
|
}
|
|
}
|
|
|
|
if err = r.ParseForm(); err != nil {
|
|
return err
|
|
}
|
|
|
|
get := map[string]string{}
|
|
post := map[string]string{}
|
|
urlQuery := r.URL.Query()
|
|
for name, param := range urlQuery {
|
|
get[name] = string(param[0])
|
|
}
|
|
postVars := r.Form
|
|
for name, param := range postVars {
|
|
post[name] = string(param[0])
|
|
}
|
|
|
|
usReq.UserID = parseUInt64(chi.URLParam(r, "userID"))
|
|
|
|
return err
|
|
}
|
|
|
|
var _ RequestFiller = NewUserUnsuspend()
|