Files
dash/backend/service/api_plan_service.go
2022-11-26 18:41:39 +01:00

103 lines
4.0 KiB
Go

/*
* 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 service
import (
"context"
"errors"
"log"
"net/http"
"github.com/moustachioed/dash/backend/dashapi"
"github.com/moustachioed/dash/backend/mapping"
)
// PlanApiService is a service that implements the logic for the PlanApiServicer
// This service should implement the business logic for every endpoint for the PlanApi API.
// Include any external packages or services that will be required by this service.
type PlanApiService struct {
ds DataStore
mapper mapping.Mapper
}
// NewPlanApiService creates a default api service
func NewPlanApiService(ds DataStore, mapper mapping.Mapper) dashapi.PlanApiServicer {
service := PlanApiService{
ds: ds,
mapper: mapper,
}
return &service
}
// GetPlanDayForDate -
func (s *PlanApiService) GetPlanDayForDate(ctx context.Context, date string) (dashapi.ImplResponse, error) {
d, err := s.mapper.StringToDate(date)
if err != nil {
log.Fatal(err)
}
dbEntry, _ := s.ds.GetPlanDayForDate(d)
planDay := s.mapper.PlanDayDsToApi(dbEntry)
return dashapi.Response(200, planDay), nil
}
// GetPlanMonthForDate -
func (s *PlanApiService) GetPlanMonthForDate(ctx context.Context, date string) (dashapi.ImplResponse, error) {
// TODO - update GetPlanMonthForDate with the required logic for this service method.
// Add api_plan_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, PlanMonth{}) or use other options such as http.Ok ...
//return Response(200, PlanMonth{}), nil
return dashapi.Response(http.StatusNotImplemented, nil), errors.New("GetPlanMonthForDate method not implemented")
}
// GetPlanWeekForDate -
func (s *PlanApiService) GetPlanWeekForDate(ctx context.Context, date string) (dashapi.ImplResponse, error) {
// TODO - update GetPlanWeekForDate with the required logic for this service method.
// Add api_plan_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, PlanWeek{}) or use other options such as http.Ok ...
//return Response(200, PlanWeek{}), nil
return dashapi.Response(http.StatusNotImplemented, nil), errors.New("GetPlanWeekForDate method not implemented")
}
// SavePlanForDay -
func (s *PlanApiService) SavePlanForDay(ctx context.Context, planDay dashapi.PlanDay) (dashapi.ImplResponse, error) {
plan := s.mapper.PlanDayApiToDs(planDay)
s.ds.WritePlanDay(plan)
return dashapi.Response(200, nil), nil
}
// SavePlanForMonth -
func (s *PlanApiService) SavePlanForMonth(ctx context.Context, planMonth dashapi.PlanMonth) (dashapi.ImplResponse, error) {
// TODO - update SavePlanForMonth with the required logic for this service method.
// Add api_plan_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 dashapi.Response(http.StatusNotImplemented, nil), errors.New("SavePlanForMonth method not implemented")
}
// SavePlanForWeek -
func (s *PlanApiService) SavePlanForWeek(ctx context.Context, planWeek dashapi.PlanWeek) (dashapi.ImplResponse, error) {
// TODO - update SavePlanForWeek with the required logic for this service method.
// Add api_plan_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 dashapi.Response(http.StatusNotImplemented, nil), errors.New("SavePlanForWeek method not implemented")
}