Add login
This commit is contained in:
67
storage/model/error.go
Executable file
67
storage/model/error.go
Executable file
@@ -0,0 +1,67 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/lib/pq"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var (
|
||||
// 400
|
||||
ErrBadRequestFormat = APIError{
|
||||
Type: "bad_format",
|
||||
HTTPCode: http.StatusBadRequest,
|
||||
Description: "unable to read request body, please check that the json is valid",
|
||||
}
|
||||
ErrDataValidation = APIError{
|
||||
Type: "data_validation",
|
||||
HTTPCode: http.StatusBadRequest,
|
||||
Description: "the data are not valid",
|
||||
}
|
||||
|
||||
// 404
|
||||
ErrNotFound = APIError{
|
||||
Type: "not_found",
|
||||
HTTPCode: http.StatusNotFound,
|
||||
}
|
||||
|
||||
// 40x
|
||||
ErrAlreadyExists = APIError{
|
||||
Type: "already_exists",
|
||||
HTTPCode: http.StatusConflict,
|
||||
}
|
||||
|
||||
// 50x
|
||||
ErrInternalServer = APIError{
|
||||
Type: "internal_server_error",
|
||||
HTTPCode: http.StatusInternalServerError,
|
||||
}
|
||||
)
|
||||
|
||||
type APIError struct {
|
||||
HTTPCode int `json:"-"`
|
||||
Type string `json:"error"`
|
||||
Description string `json:"error_description"`
|
||||
Details []FieldError `json:"error_details,omitempty"`
|
||||
Headers map[string][]string `json:"-"`
|
||||
}
|
||||
|
||||
type FieldError struct {
|
||||
Field string `json:"field"`
|
||||
Constraint string `json:"constraint"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
func (e *APIError) Error() string {
|
||||
return fmt.Sprintf("error : %d, %s, %s, %v", e.HTTPCode, e.Type, e.Description, e.Details)
|
||||
}
|
||||
|
||||
func FromPostgresError(err *pq.Error) *APIError {
|
||||
return &APIError{
|
||||
HTTPCode: 0,
|
||||
Type: "",
|
||||
Description: "",
|
||||
Details: nil,
|
||||
Headers: nil,
|
||||
}
|
||||
}
|
||||
16
storage/model/user.go
Executable file
16
storage/model/user.go
Executable file
@@ -0,0 +1,16 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type User struct {
|
||||
UserEditable
|
||||
ID string `json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt *time.Time `json:"updatedAt"`
|
||||
GoogleId string `json:"-"`
|
||||
}
|
||||
|
||||
type UserEditable struct {
|
||||
Email string `json:"email" validate:"required"`
|
||||
Nickname string `json:"nickname" validate:"required"`
|
||||
}
|
||||
17
storage/model/user_data.go
Normal file
17
storage/model/user_data.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type UserData struct {
|
||||
UserEditable
|
||||
ID string `json:"id"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt *time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
type UserDataEditable struct {
|
||||
UserId string `json:'userId'`
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
Reference in New Issue
Block a user