201 lines
4.7 KiB
Go
201 lines
4.7 KiB
Go
|
// Code generated by entc, DO NOT EDIT.
|
||
|
|
||
|
package http
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"strconv"
|
||
|
"t/ent"
|
||
|
"time"
|
||
|
|
||
|
"github.com/mailru/easyjson"
|
||
|
)
|
||
|
|
||
|
// Basic HTTP Error Response
|
||
|
type ErrResponse struct {
|
||
|
Code int `json:"code"` // http response status code
|
||
|
Status string `json:"status"` // user-level status message
|
||
|
Errors interface{} `json:"errors,omitempty"` // application-level error
|
||
|
}
|
||
|
|
||
|
func (e ErrResponse) MarshalToHTTPResponseWriter(w http.ResponseWriter) (int, error) {
|
||
|
d, err := easyjson.Marshal(e)
|
||
|
if err != nil {
|
||
|
return 0, err
|
||
|
}
|
||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||
|
w.Header().Set("Content-Length", strconv.Itoa(len(d)))
|
||
|
w.WriteHeader(e.Code)
|
||
|
return w.Write(d)
|
||
|
}
|
||
|
|
||
|
func BadRequest(w http.ResponseWriter, msg interface{}) (int, error) {
|
||
|
return ErrResponse{
|
||
|
Code: http.StatusBadRequest,
|
||
|
Status: http.StatusText(http.StatusBadRequest),
|
||
|
Errors: msg,
|
||
|
}.MarshalToHTTPResponseWriter(w)
|
||
|
}
|
||
|
|
||
|
func Conflict(w http.ResponseWriter, msg interface{}) (int, error) {
|
||
|
return ErrResponse{
|
||
|
Code: http.StatusConflict,
|
||
|
Status: http.StatusText(http.StatusConflict),
|
||
|
Errors: msg,
|
||
|
}.MarshalToHTTPResponseWriter(w)
|
||
|
}
|
||
|
|
||
|
func Forbidden(w http.ResponseWriter, msg interface{}) (int, error) {
|
||
|
return ErrResponse{
|
||
|
Code: http.StatusForbidden,
|
||
|
Status: http.StatusText(http.StatusForbidden),
|
||
|
Errors: msg,
|
||
|
}.MarshalToHTTPResponseWriter(w)
|
||
|
}
|
||
|
|
||
|
func InternalServerError(w http.ResponseWriter, msg interface{}) (int, error) {
|
||
|
return ErrResponse{
|
||
|
Code: http.StatusInternalServerError,
|
||
|
Status: http.StatusText(http.StatusInternalServerError),
|
||
|
Errors: msg,
|
||
|
}.MarshalToHTTPResponseWriter(w)
|
||
|
}
|
||
|
|
||
|
func NotFound(w http.ResponseWriter, msg interface{}) (int, error) {
|
||
|
return ErrResponse{
|
||
|
Code: http.StatusNotFound,
|
||
|
Status: http.StatusText(http.StatusNotFound),
|
||
|
Errors: msg,
|
||
|
}.MarshalToHTTPResponseWriter(w)
|
||
|
}
|
||
|
|
||
|
func Unauthorized(w http.ResponseWriter, msg interface{}) (int, error) {
|
||
|
return ErrResponse{
|
||
|
Code: http.StatusUnauthorized,
|
||
|
Status: http.StatusText(http.StatusUnauthorized),
|
||
|
Errors: msg,
|
||
|
}.MarshalToHTTPResponseWriter(w)
|
||
|
}
|
||
|
|
||
|
type (
|
||
|
// Compartment3324871446View represents the data serialized for the following serialization group combinations:
|
||
|
// []
|
||
|
Compartment3324871446View struct {
|
||
|
ID int `json:"id,omitempty"`
|
||
|
}
|
||
|
Compartment3324871446Views []*Compartment3324871446View
|
||
|
)
|
||
|
|
||
|
func NewCompartment3324871446View(e *ent.Compartment) *Compartment3324871446View {
|
||
|
if e == nil {
|
||
|
return nil
|
||
|
}
|
||
|
return &Compartment3324871446View{
|
||
|
ID: e.ID,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func NewCompartment3324871446Views(es []*ent.Compartment) Compartment3324871446Views {
|
||
|
if len(es) == 0 {
|
||
|
return nil
|
||
|
}
|
||
|
r := make(Compartment3324871446Views, len(es))
|
||
|
for i, e := range es {
|
||
|
r[i] = NewCompartment3324871446View(e)
|
||
|
}
|
||
|
return r
|
||
|
}
|
||
|
|
||
|
type (
|
||
|
// Entry2675665849View represents the data serialized for the following serialization group combinations:
|
||
|
// []
|
||
|
Entry2675665849View struct {
|
||
|
ID string `json:"id,omitempty"`
|
||
|
User string `json:"user,omitempty"`
|
||
|
First int `json:"first,omitempty"`
|
||
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||
|
}
|
||
|
Entry2675665849Views []*Entry2675665849View
|
||
|
)
|
||
|
|
||
|
func NewEntry2675665849View(e *ent.Entry) *Entry2675665849View {
|
||
|
if e == nil {
|
||
|
return nil
|
||
|
}
|
||
|
return &Entry2675665849View{
|
||
|
ID: e.ID,
|
||
|
User: e.User,
|
||
|
First: e.First,
|
||
|
CreatedAt: e.CreatedAt,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func NewEntry2675665849Views(es []*ent.Entry) Entry2675665849Views {
|
||
|
if len(es) == 0 {
|
||
|
return nil
|
||
|
}
|
||
|
r := make(Entry2675665849Views, len(es))
|
||
|
for i, e := range es {
|
||
|
r[i] = NewEntry2675665849View(e)
|
||
|
}
|
||
|
return r
|
||
|
}
|
||
|
|
||
|
type (
|
||
|
// Fridge2211356377View represents the data serialized for the following serialization group combinations:
|
||
|
// []
|
||
|
Fridge2211356377View struct {
|
||
|
ID int `json:"id,omitempty"`
|
||
|
}
|
||
|
Fridge2211356377Views []*Fridge2211356377View
|
||
|
)
|
||
|
|
||
|
func NewFridge2211356377View(e *ent.Fridge) *Fridge2211356377View {
|
||
|
if e == nil {
|
||
|
return nil
|
||
|
}
|
||
|
return &Fridge2211356377View{
|
||
|
ID: e.ID,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func NewFridge2211356377Views(es []*ent.Fridge) Fridge2211356377Views {
|
||
|
if len(es) == 0 {
|
||
|
return nil
|
||
|
}
|
||
|
r := make(Fridge2211356377Views, len(es))
|
||
|
for i, e := range es {
|
||
|
r[i] = NewFridge2211356377View(e)
|
||
|
}
|
||
|
return r
|
||
|
}
|
||
|
|
||
|
type (
|
||
|
// Item1548468123View represents the data serialized for the following serialization group combinations:
|
||
|
// []
|
||
|
Item1548468123View struct {
|
||
|
ID int `json:"id,omitempty"`
|
||
|
}
|
||
|
Item1548468123Views []*Item1548468123View
|
||
|
)
|
||
|
|
||
|
func NewItem1548468123View(e *ent.Item) *Item1548468123View {
|
||
|
if e == nil {
|
||
|
return nil
|
||
|
}
|
||
|
return &Item1548468123View{
|
||
|
ID: e.ID,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func NewItem1548468123Views(es []*ent.Item) Item1548468123Views {
|
||
|
if len(es) == 0 {
|
||
|
return nil
|
||
|
}
|
||
|
r := make(Item1548468123Views, len(es))
|
||
|
for i, e := range es {
|
||
|
r[i] = NewItem1548468123View(e)
|
||
|
}
|
||
|
return r
|
||
|
}
|