Files
dash/backend/service/api_inbox_service.go
Martin Pander 8addda35ea V2
2023-12-09 19:34:45 +01:00

66 lines
1.8 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"
"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
}