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

@ -0,0 +1,65 @@
/*
* 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"
"net/http"
dashapi "github.com/moustachioed/dash/backend/dashapi"
"github.com/moustachioed/dash/backend/mapping"
)
// 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 {
ds DataStore
mapper mapping.Mapper
}
// NewInboxApiService creates a default api service
func NewInboxApiService(ds DataStore, mapper mapping.Mapper) dashapi.InboxApiServicer {
return &InboxApiService{
ds: ds,
mapper: mapper,
}
}
// AddInboxItem -
func (s *InboxApiService) AddInboxItem(ctx context.Context, inboxItem dashapi.InboxItem) (dashapi.ImplResponse, error) {
item := s.mapper.InboxApiToDs(inboxItem)
s.ds.WriteInboxItem(item)
return dashapi.Response(http.StatusOK, nil), nil
}
// DeleteInboxItem -
func (s *InboxApiService) DeleteInboxItem(ctx context.Context, item int32) (dashapi.ImplResponse, error) {
s.ds.DeleteInboxItem(item)
return dashapi.Response(http.StatusOK, nil), nil
}
// GetInboxItems -
func (s *InboxApiService) GetInboxItems(ctx context.Context) (dashapi.ImplResponse, error) {
items, err := s.ds.GetInboxItems()
if err != nil {
return dashapi.Response(http.StatusInternalServerError, nil), errors.New("Could not get inbox items")
}
apiItems := make([]dashapi.InboxItem, len(items))
for i, item := range items {
apiItems[i] = s.mapper.InboxDsToApi(item).(dashapi.InboxItem)
}
return dashapi.Response(http.StatusOK, apiItems), nil
}

View File

@ -45,8 +45,8 @@ func (s *PlanApiService) GetPlanDayForDate(ctx context.Context, date string) (da
}
dbEntry, _ := s.ds.GetPlanDayForDate(d)
planDay := s.mapper.PlanDayDsToApi(dbEntry)
return dashapi.Response(200, planDay), nil
plan := s.mapper.PlanDayDsToApi(dbEntry)
return dashapi.Response(200, plan), nil
}
// GetPlanMonthForDate -
@ -62,13 +62,14 @@ func (s *PlanApiService) GetPlanMonthForDate(ctx context.Context, date string) (
// 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.
d, err := s.mapper.StringToDate(date)
if err != nil {
log.Fatal(err)
}
//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")
dbEntry, _ := s.ds.GetPlanWeekForDate(d)
plan := s.mapper.PlanWeekDsToApi(dbEntry)
return dashapi.Response(200, plan), nil
}
// SavePlanForDay -
@ -92,11 +93,8 @@ func (s *PlanApiService) SavePlanForMonth(ctx context.Context, planMonth dashapi
// 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.
plan := s.mapper.PlanWeekApiToDs(planWeek)
s.ds.WritePlanWeek(plan)
//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")
return dashapi.Response(200, nil), nil
}

View File

@ -0,0 +1,79 @@
/*
* 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"
"net/http"
dashapi "github.com/moustachioed/dash/backend/dashapi"
"github.com/moustachioed/dash/backend/mapping"
)
// 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 {
ds DataStore
mapper mapping.Mapper
}
// NewTrackingApiService creates a default api service
func NewTrackingApiService(ds DataStore, mapper mapping.Mapper) dashapi.TrackingApiServicer {
return &TrackingApiService{
ds: ds,
mapper: mapper,
}
}
// GetTrackingCategories -
func (s *TrackingApiService) GetTrackingCategories(ctx context.Context) (dashapi.ImplResponse, error) {
dbcategories, err := s.ds.GetTrackingCategories()
if err != nil {
return dashapi.Response(http.StatusInternalServerError, nil), err
}
categories := s.mapper.TrackingCategoriesDbToApi(dbcategories).(dashapi.TrackingCategories)
return dashapi.Response(http.StatusOK, categories), nil
}
// GetTrackingEntryForDate -
func (s *TrackingApiService) GetTrackingEntryForDate(ctx context.Context, date string) (dashapi.ImplResponse, error) {
d, err := s.mapper.StringToDate(date)
if err != nil {
return dashapi.Response(http.StatusInternalServerError, nil), err
}
dbentry, err := s.ds.GetTrackingItemsForDate(d)
if err != nil {
return dashapi.Response(http.StatusInternalServerError, nil), err
}
entry := s.mapper.TrackingEntryDbToApi(dbentry).(dashapi.TrackingEntry)
if entry.Date == "" {
entry.Date = date
entry.Items = []dashapi.TrackingItem{}
}
return dashapi.Response(http.StatusOK, entry), nil
}
// WriteTrackingEntry -
func (s *TrackingApiService) WriteTrackingEntry(ctx context.Context, trackingEntry dashapi.TrackingEntry) (dashapi.ImplResponse, error) {
entry := s.mapper.TrackingEntryApiToDb(trackingEntry)
err := s.ds.WriteTrackingItems(entry)
if err != nil {
return dashapi.Response(http.StatusInternalServerError, nil), err
}
return dashapi.Response(http.StatusOK, nil), nil
}

View File

@ -16,4 +16,12 @@ type DataStore interface {
WritePlanMonth(interface{}) error
GetPlanMonthForDate(time.Time) (interface{}, error)
WriteTrackingItems(interface{}) error
GetTrackingItemsForDate(time.Time) (interface{}, error)
GetTrackingCategories() (interface{}, error)
WriteInboxItem(interface{}) error
DeleteInboxItem(int32) error
GetInboxItems() ([]interface{}, error)
}