@@ -0,0 +1,48 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// SpeciesCategories lists active categories available to ordinary users.
|
||||
func (c *Client) SpeciesCategories(ctx context.Context) ([]SpeciesCategory, *Response, error) {
|
||||
return c.speciesCategories(ctx, "v1/species-categories")
|
||||
}
|
||||
|
||||
// AdminSpeciesCategories lists all categories, including inactive ones.
|
||||
func (c *Client) AdminSpeciesCategories(ctx context.Context) ([]SpeciesCategory, *Response, error) {
|
||||
return c.speciesCategories(ctx, "v1/admin/species-categories")
|
||||
}
|
||||
|
||||
func (c *Client) speciesCategories(ctx context.Context, path string) ([]SpeciesCategory, *Response, error) {
|
||||
var envelope struct {
|
||||
Categories []SpeciesCategory `json:"categories"`
|
||||
}
|
||||
response, err := c.do(ctx, http.MethodGet, path, nil, &envelope)
|
||||
return envelope.Categories, response, err
|
||||
}
|
||||
|
||||
// CreateAdminSpeciesCategory adds an application-wide species category.
|
||||
func (c *Client) CreateAdminSpeciesCategory(ctx context.Context, input SpeciesCategoryInput) (SpeciesCategory, *Response, error) {
|
||||
return c.writeSpeciesCategory(ctx, http.MethodPost, "v1/admin/species-categories", input)
|
||||
}
|
||||
|
||||
// UpdateAdminSpeciesCategory changes an application-wide species category.
|
||||
func (c *Client) UpdateAdminSpeciesCategory(ctx context.Context, id int, input SpeciesCategoryInput) (SpeciesCategory, *Response, error) {
|
||||
return c.writeSpeciesCategory(ctx, http.MethodPatch, "v1/admin/species-categories/"+strconv.Itoa(id), input)
|
||||
}
|
||||
|
||||
// DeleteAdminSpeciesCategory removes an unused species category.
|
||||
func (c *Client) DeleteAdminSpeciesCategory(ctx context.Context, id int) (*Response, error) {
|
||||
return c.do(ctx, http.MethodDelete, "v1/admin/species-categories/"+strconv.Itoa(id), nil, nil)
|
||||
}
|
||||
|
||||
func (c *Client) writeSpeciesCategory(ctx context.Context, method, path string, input SpeciesCategoryInput) (SpeciesCategory, *Response, error) {
|
||||
var envelope struct {
|
||||
Category SpeciesCategory `json:"category"`
|
||||
}
|
||||
response, err := c.do(ctx, method, path, input, &envelope)
|
||||
return envelope.Category, response, err
|
||||
}
|
||||
Reference in New Issue
Block a user