This commit is contained in:
Martin Pander
2023-12-09 19:34:45 +01:00
parent 32346e0aa9
commit 8addda35ea
144 changed files with 7247 additions and 3268 deletions

View File

@ -16,6 +16,14 @@ import (
// InboxApiRouter defines the required methods for binding the api requests to a responses for the InboxApi
// The InboxApiRouter implementation should parse necessary information from the http request,
// pass the data to a InboxApiServicer to perform the required actions, then write the service results to the http response.
type InboxApiRouter interface {
AddInboxItem(http.ResponseWriter, *http.Request)
DeleteInboxItem(http.ResponseWriter, *http.Request)
GetInboxItems(http.ResponseWriter, *http.Request)
}
// JournalApiRouter defines the required methods for binding the api requests to a responses for the JournalApi
// The JournalApiRouter implementation should parse necessary information from the http request,
// pass the data to a JournalApiServicer to perform the required actions, then write the service results to the http response.
@ -35,6 +43,25 @@ type PlanApiRouter interface {
SavePlanForMonth(http.ResponseWriter, *http.Request)
SavePlanForWeek(http.ResponseWriter, *http.Request)
}
// TrackingApiRouter defines the required methods for binding the api requests to a responses for the TrackingApi
// The TrackingApiRouter implementation should parse necessary information from the http request,
// pass the data to a TrackingApiServicer to perform the required actions, then write the service results to the http response.
type TrackingApiRouter interface {
GetTrackingCategories(http.ResponseWriter, *http.Request)
GetTrackingEntryForDate(http.ResponseWriter, *http.Request)
WriteTrackingEntry(http.ResponseWriter, *http.Request)
}
// InboxApiServicer defines the api actions for the InboxApi service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type InboxApiServicer interface {
AddInboxItem(context.Context, InboxItem) (ImplResponse, error)
DeleteInboxItem(context.Context, int32) (ImplResponse, error)
GetInboxItems(context.Context) (ImplResponse, error)
}
// JournalApiServicer defines the api actions for the JournalApi service
@ -60,3 +87,14 @@ type PlanApiServicer interface {
SavePlanForMonth(context.Context, PlanMonth) (ImplResponse, error)
SavePlanForWeek(context.Context, PlanWeek) (ImplResponse, error)
}
// TrackingApiServicer defines the api actions for the TrackingApi service
// This interface intended to stay up to date with the openapi yaml used to generate it,
// while the service implementation can be ignored with the .openapi-generator-ignore file
// and updated with the logic required for the API.
type TrackingApiServicer interface {
GetTrackingCategories(context.Context) (ImplResponse, error)
GetTrackingEntryForDate(context.Context, string) (ImplResponse, error)
WriteTrackingEntry(context.Context, TrackingEntry) (ImplResponse, error)
}

View File

@ -0,0 +1,129 @@
/*
* Dash API
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 0.1
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package dashapi
import (
"encoding/json"
"net/http"
"strings"
"github.com/gorilla/mux"
)
// InboxApiController binds http requests to an api service and writes the service results to the http response
type InboxApiController struct {
service InboxApiServicer
errorHandler ErrorHandler
}
// InboxApiOption for how the controller is set up.
type InboxApiOption func(*InboxApiController)
// WithInboxApiErrorHandler inject ErrorHandler into controller
func WithInboxApiErrorHandler(h ErrorHandler) InboxApiOption {
return func(c *InboxApiController) {
c.errorHandler = h
}
}
// NewInboxApiController creates a default api controller
func NewInboxApiController(s InboxApiServicer, opts ...InboxApiOption) Router {
controller := &InboxApiController{
service: s,
errorHandler: DefaultErrorHandler,
}
for _, opt := range opts {
opt(controller)
}
return controller
}
// Routes returns all the api routes for the InboxApiController
func (c *InboxApiController) Routes() Routes {
return Routes{
{
"AddInboxItem",
strings.ToUpper("Post"),
"/api/v1/inbox/",
c.AddInboxItem,
},
{
"DeleteInboxItem",
strings.ToUpper("Delete"),
"/api/v1/inbox/{item}",
c.DeleteInboxItem,
},
{
"GetInboxItems",
strings.ToUpper("Get"),
"/api/v1/inbox/",
c.GetInboxItems,
},
}
}
// AddInboxItem -
func (c *InboxApiController) AddInboxItem(w http.ResponseWriter, r *http.Request) {
inboxItemParam := InboxItem{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
if err := d.Decode(&inboxItemParam); err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
if err := AssertInboxItemRequired(inboxItemParam); err != nil {
c.errorHandler(w, r, err, nil)
return
}
result, err := c.service.AddInboxItem(r.Context(), inboxItemParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}
// DeleteInboxItem -
func (c *InboxApiController) DeleteInboxItem(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
itemParam, err := parseInt32Parameter(params["item"], true)
if err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
result, err := c.service.DeleteInboxItem(r.Context(), itemParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}
// GetInboxItems -
func (c *InboxApiController) GetInboxItems(w http.ResponseWriter, r *http.Request) {
result, err := c.service.GetInboxItems(r.Context())
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}

View File

@ -0,0 +1,60 @@
/*
* Dash API
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 0.1
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package dashapi
import (
"context"
"net/http"
"errors"
)
// InboxApiService is a service that implements the logic for the InboxApiServicer
// This service should implement the business logic for every endpoint for the InboxApi API.
// Include any external packages or services that will be required by this service.
type InboxApiService struct {
}
// NewInboxApiService creates a default api service
func NewInboxApiService() InboxApiServicer {
return &InboxApiService{}
}
// AddInboxItem -
func (s *InboxApiService) AddInboxItem(ctx context.Context, inboxItem InboxItem) (ImplResponse, error) {
// TODO - update AddInboxItem with the required logic for this service method.
// Add api_inbox_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, {}) or use other options such as http.Ok ...
//return Response(200, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("AddInboxItem method not implemented")
}
// DeleteInboxItem -
func (s *InboxApiService) DeleteInboxItem(ctx context.Context, item int32) (ImplResponse, error) {
// TODO - update DeleteInboxItem with the required logic for this service method.
// Add api_inbox_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, {}) or use other options such as http.Ok ...
//return Response(200, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("DeleteInboxItem method not implemented")
}
// GetInboxItems -
func (s *InboxApiService) GetInboxItems(ctx context.Context) (ImplResponse, error) {
// TODO - update GetInboxItems with the required logic for this service method.
// Add api_inbox_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, []InboxItem{}) or use other options such as http.Ok ...
//return Response(200, []InboxItem{}), nil
return Response(http.StatusNotImplemented, nil), errors.New("GetInboxItems method not implemented")
}

View File

@ -0,0 +1,125 @@
/*
* Dash API
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 0.1
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package dashapi
import (
"encoding/json"
"net/http"
"strings"
"github.com/gorilla/mux"
)
// TrackingApiController binds http requests to an api service and writes the service results to the http response
type TrackingApiController struct {
service TrackingApiServicer
errorHandler ErrorHandler
}
// TrackingApiOption for how the controller is set up.
type TrackingApiOption func(*TrackingApiController)
// WithTrackingApiErrorHandler inject ErrorHandler into controller
func WithTrackingApiErrorHandler(h ErrorHandler) TrackingApiOption {
return func(c *TrackingApiController) {
c.errorHandler = h
}
}
// NewTrackingApiController creates a default api controller
func NewTrackingApiController(s TrackingApiServicer, opts ...TrackingApiOption) Router {
controller := &TrackingApiController{
service: s,
errorHandler: DefaultErrorHandler,
}
for _, opt := range opts {
opt(controller)
}
return controller
}
// Routes returns all the api routes for the TrackingApiController
func (c *TrackingApiController) Routes() Routes {
return Routes{
{
"GetTrackingCategories",
strings.ToUpper("Get"),
"/api/v1/tracking/categories",
c.GetTrackingCategories,
},
{
"GetTrackingEntryForDate",
strings.ToUpper("Get"),
"/api/v1/tracking/entry/{date}",
c.GetTrackingEntryForDate,
},
{
"WriteTrackingEntry",
strings.ToUpper("Post"),
"/api/v1/tracking/entry",
c.WriteTrackingEntry,
},
}
}
// GetTrackingCategories -
func (c *TrackingApiController) GetTrackingCategories(w http.ResponseWriter, r *http.Request) {
result, err := c.service.GetTrackingCategories(r.Context())
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}
// GetTrackingEntryForDate -
func (c *TrackingApiController) GetTrackingEntryForDate(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
dateParam := params["date"]
result, err := c.service.GetTrackingEntryForDate(r.Context(), dateParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}
// WriteTrackingEntry -
func (c *TrackingApiController) WriteTrackingEntry(w http.ResponseWriter, r *http.Request) {
trackingEntryParam := TrackingEntry{}
d := json.NewDecoder(r.Body)
d.DisallowUnknownFields()
if err := d.Decode(&trackingEntryParam); err != nil {
c.errorHandler(w, r, &ParsingError{Err: err}, nil)
return
}
if err := AssertTrackingEntryRequired(trackingEntryParam); err != nil {
c.errorHandler(w, r, err, nil)
return
}
result, err := c.service.WriteTrackingEntry(r.Context(), trackingEntryParam)
// If an error occurred, encode the error with the status code
if err != nil {
c.errorHandler(w, r, err, &result)
return
}
// If no error, encode the body and the result code
EncodeJSONResponse(result.Body, &result.Code, w)
}

View File

@ -0,0 +1,60 @@
/*
* Dash API
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 0.1
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package dashapi
import (
"context"
"net/http"
"errors"
)
// TrackingApiService is a service that implements the logic for the TrackingApiServicer
// This service should implement the business logic for every endpoint for the TrackingApi API.
// Include any external packages or services that will be required by this service.
type TrackingApiService struct {
}
// NewTrackingApiService creates a default api service
func NewTrackingApiService() TrackingApiServicer {
return &TrackingApiService{}
}
// GetTrackingCategories -
func (s *TrackingApiService) GetTrackingCategories(ctx context.Context) (ImplResponse, error) {
// TODO - update GetTrackingCategories with the required logic for this service method.
// Add api_tracking_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, TrackingCategories{}) or use other options such as http.Ok ...
//return Response(200, TrackingCategories{}), nil
return Response(http.StatusNotImplemented, nil), errors.New("GetTrackingCategories method not implemented")
}
// GetTrackingEntryForDate -
func (s *TrackingApiService) GetTrackingEntryForDate(ctx context.Context, date string) (ImplResponse, error) {
// TODO - update GetTrackingEntryForDate with the required logic for this service method.
// Add api_tracking_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, TrackingEntry{}) or use other options such as http.Ok ...
//return Response(200, TrackingEntry{}), nil
return Response(http.StatusNotImplemented, nil), errors.New("GetTrackingEntryForDate method not implemented")
}
// WriteTrackingEntry -
func (s *TrackingApiService) WriteTrackingEntry(ctx context.Context, trackingEntry TrackingEntry) (ImplResponse, error) {
// TODO - update WriteTrackingEntry with the required logic for this service method.
// Add api_tracking_service.go to the .openapi-generator-ignore to avoid overwriting this service implementation when updating open api generation.
//TODO: Uncomment the next line to return response Response(200, {}) or use other options such as http.Ok ...
//return Response(200, nil),nil
return Response(http.StatusNotImplemented, nil), errors.New("WriteTrackingEntry method not implemented")
}

View File

@ -0,0 +1,43 @@
/*
* Dash API
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 0.1
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package dashapi
type InboxItem struct {
Id int32 `json:"id,omitempty"`
Item string `json:"item"`
}
// AssertInboxItemRequired checks if the required fields are not zero-ed
func AssertInboxItemRequired(obj InboxItem) error {
elements := map[string]interface{}{
"item": obj.Item,
}
for name, el := range elements {
if isZero := IsZeroValue(el); isZero {
return &RequiredError{Field: name}
}
}
return nil
}
// AssertRecurseInboxItemRequired recursively checks if required fields are not zero-ed in a nested slice.
// Accepts only nested slice of InboxItem (e.g. [][]InboxItem), otherwise ErrTypeAssertionError is thrown.
func AssertRecurseInboxItemRequired(objSlice interface{}) error {
return AssertRecurseInterfaceRequired(objSlice, func(obj interface{}) error {
aInboxItem, ok := obj.(InboxItem)
if !ok {
return ErrTypeAssertionError
}
return AssertInboxItemRequired(aInboxItem)
})
}

View File

@ -13,7 +13,7 @@ type PlanWeekItem struct {
Item string `json:"item"`
NumTodos int32 `json:"numTodos,omitempty"`
NumTodo int32 `json:"numTodo,omitempty"`
NumDone int32 `json:"numDone,omitempty"`
}

View File

@ -0,0 +1,37 @@
/*
* Dash API
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 0.1
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package dashapi
type TrackingCategories struct {
Categories []TrackingCategory `json:"categories,omitempty"`
}
// AssertTrackingCategoriesRequired checks if the required fields are not zero-ed
func AssertTrackingCategoriesRequired(obj TrackingCategories) error {
for _, el := range obj.Categories {
if err := AssertTrackingCategoryRequired(el); err != nil {
return err
}
}
return nil
}
// AssertRecurseTrackingCategoriesRequired recursively checks if required fields are not zero-ed in a nested slice.
// Accepts only nested slice of TrackingCategories (e.g. [][]TrackingCategories), otherwise ErrTypeAssertionError is thrown.
func AssertRecurseTrackingCategoriesRequired(objSlice interface{}) error {
return AssertRecurseInterfaceRequired(objSlice, func(obj interface{}) error {
aTrackingCategories, ok := obj.(TrackingCategories)
if !ok {
return ErrTypeAssertionError
}
return AssertTrackingCategoriesRequired(aTrackingCategories)
})
}

View File

@ -0,0 +1,46 @@
/*
* Dash API
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 0.1
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package dashapi
type TrackingCategory struct {
Type string `json:"type"`
Name string `json:"name"`
Items []string `json:"items,omitempty"`
}
// AssertTrackingCategoryRequired checks if the required fields are not zero-ed
func AssertTrackingCategoryRequired(obj TrackingCategory) error {
elements := map[string]interface{}{
"type": obj.Type,
"name": obj.Name,
}
for name, el := range elements {
if isZero := IsZeroValue(el); isZero {
return &RequiredError{Field: name}
}
}
return nil
}
// AssertRecurseTrackingCategoryRequired recursively checks if required fields are not zero-ed in a nested slice.
// Accepts only nested slice of TrackingCategory (e.g. [][]TrackingCategory), otherwise ErrTypeAssertionError is thrown.
func AssertRecurseTrackingCategoryRequired(objSlice interface{}) error {
return AssertRecurseInterfaceRequired(objSlice, func(obj interface{}) error {
aTrackingCategory, ok := obj.(TrackingCategory)
if !ok {
return ErrTypeAssertionError
}
return AssertTrackingCategoryRequired(aTrackingCategory)
})
}

View File

@ -0,0 +1,49 @@
/*
* Dash API
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 0.1
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package dashapi
type TrackingEntry struct {
Date string `json:"date"`
Items []TrackingItem `json:"items"`
}
// AssertTrackingEntryRequired checks if the required fields are not zero-ed
func AssertTrackingEntryRequired(obj TrackingEntry) error {
elements := map[string]interface{}{
"date": obj.Date,
"items": obj.Items,
}
for name, el := range elements {
if isZero := IsZeroValue(el); isZero {
return &RequiredError{Field: name}
}
}
for _, el := range obj.Items {
if err := AssertTrackingItemRequired(el); err != nil {
return err
}
}
return nil
}
// AssertRecurseTrackingEntryRequired recursively checks if required fields are not zero-ed in a nested slice.
// Accepts only nested slice of TrackingEntry (e.g. [][]TrackingEntry), otherwise ErrTypeAssertionError is thrown.
func AssertRecurseTrackingEntryRequired(objSlice interface{}) error {
return AssertRecurseInterfaceRequired(objSlice, func(obj interface{}) error {
aTrackingEntry, ok := obj.(TrackingEntry)
if !ok {
return ErrTypeAssertionError
}
return AssertTrackingEntryRequired(aTrackingEntry)
})
}

View File

@ -0,0 +1,47 @@
/*
* Dash API
*
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* API version: 0.1
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package dashapi
type TrackingItem struct {
Date string `json:"date"`
Type string `json:"type"`
Value string `json:"value"`
}
// AssertTrackingItemRequired checks if the required fields are not zero-ed
func AssertTrackingItemRequired(obj TrackingItem) error {
elements := map[string]interface{}{
"date": obj.Date,
"type": obj.Type,
"value": obj.Value,
}
for name, el := range elements {
if isZero := IsZeroValue(el); isZero {
return &RequiredError{Field: name}
}
}
return nil
}
// AssertRecurseTrackingItemRequired recursively checks if required fields are not zero-ed in a nested slice.
// Accepts only nested slice of TrackingItem (e.g. [][]TrackingItem), otherwise ErrTypeAssertionError is thrown.
func AssertRecurseTrackingItemRequired(objSlice interface{}) error {
return AssertRecurseInterfaceRequired(objSlice, func(obj interface{}) error {
aTrackingItem, ok := obj.(TrackingItem)
if !ok {
return ErrTypeAssertionError
}
return AssertTrackingItemRequired(aTrackingItem)
})
}