Documentation
¶
Index ¶
- Variables
- type API
- func (a *API) EnablePrometheusMetrics(prometheusID string)
- func (a *API) HandleCreateBooking(r *Request) (interface{}, error)
- func (a *API) HandleGetBooking(r *Request) (interface{}, error)
- func (a *API) HandleGetBookingPetitions(r *Request) (interface{}, error)
- func (a *API) HandleGetBookingRequests(r *Request) (interface{}, error)
- func (a *API) HandleGetPendingRatings(r *Request) (interface{}, error)
- func (a *API) HandleRateBooking(r *Request) (interface{}, error)
- func (a *API) HandleReturnBooking(r *Request) (interface{}, error)
- func (a *API) Start(host string, port int)
- type BookingResponse
- type CreateBookingRequest
- type HTTPContext
- type HTTPError
- type Info
- type Login
- type LoginResponse
- type RateRequest
- type Register
- type Request
- type Response
- type ResponseHeader
- type RouterHandlerFn
- type Tool
- type ToolID
- type ToolSearch
- type ToolsWrapper
- type UserProfile
- type UsersWrapper
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidRegisterAuthToken = fmt.Errorf("invalid register auth token") ErrInvalidRequestBodyData = fmt.Errorf("invalid request body data") ErrCouldNotInsertToDatabase = fmt.Errorf("could not insert to database") ErrWrongLogin = fmt.Errorf("wrong password or email") ErrInvalidHash = fmt.Errorf("invalid hash") ErrImageNotFound = fmt.Errorf("image not found") ErrInvalidImageFormat = fmt.Errorf("invalid image format") ErrInvalidJSON = fmt.Errorf("invalid json body") ErrBookingDatesConflict = fmt.Errorf("booking dates conflict with existing booking") ErrToolNotFound = fmt.Errorf("tool not found") ErrInvalidBookingDates = fmt.Errorf("invalid booking dates") ErrBookingNotFound = fmt.Errorf("booking not found") ErrOnlyOwnerCanReturn = fmt.Errorf("only tool owner can mark as returned") ErrBookingAlreadyReturned = fmt.Errorf("booking already marked as returned") ErrInvalidRating = fmt.Errorf("invalid rating value") ErrBookingAlreadyRated = fmt.Errorf("booking already rated") )
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct { Router *chi.Mux // contains filtered or unexported fields }
API type represents the API HTTP server with JWT authentication capabilities.
func (*API) EnablePrometheusMetrics ¶
EnablePrometheusMetrics enables go-chi prometheus metrics under specified ID. If ID empty, the default "gochi_http" is used.
func (*API) HandleCreateBooking ¶
HandleCreateBooking handles POST /bookings
func (*API) HandleGetBooking ¶
HandleGetBooking handles GET /bookings/{bookingId}
func (*API) HandleGetBookingPetitions ¶
HandleGetBookingPetitions handles GET /bookings/petitions
func (*API) HandleGetBookingRequests ¶
HandleGetBookingRequests handles GET /bookings/requests
func (*API) HandleGetPendingRatings ¶
HandleGetPendingRatings handles GET /bookings/rates
func (*API) HandleRateBooking ¶
HandleRateBooking handles POST /bookings/rates
func (*API) HandleReturnBooking ¶
HandleReturnBooking handles POST /bookings/{bookingId}/return
type BookingResponse ¶
type BookingResponse struct { ID string `json:"id"` ToolID string `json:"toolId"` FromUserID string `json:"fromUserId"` ToUserID string `json:"toUserId"` StartDate int64 `json:"startDate"` EndDate int64 `json:"endDate"` Contact string `json:"contact"` Comments string `json:"comments"` BookingStatus string `json:"bookingStatus"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` }
BookingResponse represents the API response for a booking
type CreateBookingRequest ¶
type CreateBookingRequest struct { ToolID string `json:"toolId"` StartDate int64 `json:"startDate"` EndDate int64 `json:"endDate"` Contact string `json:"contact"` Comments string `json:"comments"` }
CreateBookingRequest represents the request to create a new booking
type HTTPContext ¶
type HTTPContext struct { Writer http.ResponseWriter Request *http.Request }
HTTPContext is the Context for an HTTP request.
func (*HTTPContext) Send ¶
func (h *HTTPContext) Send(msg []byte, httpStatusCode int) error
Send replies the request with the provided message.
func (*HTTPContext) URLParam ¶
func (h *HTTPContext) URLParam(key string) string
URLParam is a wrapper around go-chi to get a URL parameter (specified in the path pattern as {key})
type LoginResponse ¶
type RateRequest ¶
RateRequest represents the request body for rating a booking
type Register ¶
type Register struct { UserEmail string `json:"email"` RegisterAuthToken string `json:"invitationToken"` UserProfile }
type Request ¶
type Request struct { Data []byte Path []string Context *HTTPContext UserID string }
Request represents an HTTP request to the API. It contains the request Body data, the URL path and the HTTP context. The context can be used for obtaining URL parameters and sending responses.
type Response ¶
type Response struct { Header ResponseHeader `json:"header"` Data any `json:"data,omitempty"` }
Response is the default response of the API
type ResponseHeader ¶
type ResponseHeader struct { Success bool `json:"success"` Message string `json:"message,omitempty"` ErrorCode int `json:"errorCode,omitempty"` }
ResponseHeader is the header of the response
type RouterHandlerFn ¶
RouterHandlerFn is the function signature for adding handlers to the HTTProuter.
type Tool ¶
type Tool struct { ID int64 `json:"id"` Title string `json:"title"` Description string `json:"description"` MayBeFree *bool `json:"mayBeFree"` AskWithFee *bool `json:"askWithFee"` Cost *uint64 `json:"cost"` Images []types.HexBytes `json:"images"` TransportOptions []int `json:"transportOptions"` Category int `json:"category"` Location db.Location `json:"location"` EstimatedValue uint64 `json:"estimatedValue"` Height uint32 `json:"height"` Weight uint32 `json:"weight"` }
Tool is the type of the tool
type ToolSearch ¶
type ToolSearch struct { Term string `json:"term"` Categories []int `json:"categories"` Distance int `json:"distance"` MaxCost *uint64 `json:"maxCost"` MayBeFree *bool `json:"mayBeFree"` AvailableFrom int `json:"availableFrom"` }
ToolSearch is the type of the tool search