V2
This commit is contained in:
@ -206,20 +206,172 @@ func (mapper MapperImpl) PlanDayDsToApi(dm interface{}) interface{} {
|
||||
}
|
||||
}
|
||||
|
||||
func (mapper MapperImpl) PlanWeekApiToDs(api interface{}) (db interface{}) {
|
||||
return new(interface{})
|
||||
func (mapper MapperImpl) PlanWeekApiToDs(am interface{}) (dm interface{}) {
|
||||
apimodel := am.(api.PlanWeek)
|
||||
date, err := mapper.StringToDate(apimodel.Date)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Could not parse date `%s`", apimodel.Date)
|
||||
}
|
||||
|
||||
items, err := json.Marshal(apimodel.Items)
|
||||
if err != nil {
|
||||
items = nil
|
||||
}
|
||||
|
||||
return db.PlanWeek{
|
||||
Date: datatypes.Date(date),
|
||||
Items: items,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapper MapperImpl) PlanWeekDsToApi(api interface{}) (db interface{}) {
|
||||
return new(interface{})
|
||||
func (mapper MapperImpl) PlanWeekDsToApi(dm interface{}) (am interface{}) {
|
||||
dbmodel := dm.(db.PlanWeek)
|
||||
|
||||
dateValue, err := dbmodel.Date.Value()
|
||||
var date string
|
||||
if err != nil {
|
||||
date = ""
|
||||
} else {
|
||||
date = mapper.DateToString(dateValue.(time.Time))
|
||||
}
|
||||
|
||||
var items []api.PlanWeekItem
|
||||
err = json.Unmarshal(dbmodel.Items, &items)
|
||||
if err != nil {
|
||||
items = nil
|
||||
}
|
||||
|
||||
return api.PlanWeek{
|
||||
Date: date,
|
||||
Items: items,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapper MapperImpl) PlanMonthApiToDs(api interface{}) (db interface{}) {
|
||||
return new(interface{})
|
||||
// write a function that takes a month and returns a plan month
|
||||
func (mapper MapperImpl) PlanMonthApiToDs(am interface{}) (dm interface{}) {
|
||||
apimodel := am.(api.PlanMonth)
|
||||
date, err := mapper.StringToDate(apimodel.Date)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Could not parse date `%s`", apimodel.Date)
|
||||
}
|
||||
|
||||
items, err := json.Marshal(apimodel.Items)
|
||||
if err != nil {
|
||||
items = nil
|
||||
}
|
||||
|
||||
return db.PlanMonth{
|
||||
Date: datatypes.Date(date),
|
||||
Items: items,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapper MapperImpl) PlanMonthDsToApi(api interface{}) (db interface{}) {
|
||||
return new(interface{})
|
||||
// write a function that takes a plan month and returns a month
|
||||
func (mapper MapperImpl) PlanMonthDsToApi(dm interface{}) (am interface{}) {
|
||||
dbmodel := dm.(db.PlanMonth)
|
||||
|
||||
dateValue, err := dbmodel.Date.Value()
|
||||
var date string
|
||||
if err != nil {
|
||||
date = ""
|
||||
} else {
|
||||
date = mapper.DateToString(dateValue.(time.Time))
|
||||
}
|
||||
|
||||
var items []string
|
||||
err = json.Unmarshal(dbmodel.Items, &items)
|
||||
if err != nil {
|
||||
items = nil
|
||||
}
|
||||
|
||||
return api.PlanMonth{
|
||||
Date: date,
|
||||
Items: items,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapper MapperImpl) TrackingCategoriesDbToApi(dm interface{}) (am interface{}) {
|
||||
dbmodel := dm.([]db.TrackingCategory)
|
||||
|
||||
var categories []api.TrackingCategory
|
||||
for _, category := range dbmodel {
|
||||
var items []string
|
||||
err := json.Unmarshal(category.Items, &items)
|
||||
if err != nil {
|
||||
items = nil
|
||||
}
|
||||
|
||||
categories = append(categories, api.TrackingCategory{
|
||||
Name: category.Name,
|
||||
Type: category.Type,
|
||||
Items: items,
|
||||
})
|
||||
}
|
||||
|
||||
return api.TrackingCategories{
|
||||
Categories: categories,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapper MapperImpl) TrackingEntryDbToApi(dm interface{}) (am interface{}) {
|
||||
dbmodel := dm.([]db.TrackingItem)
|
||||
|
||||
var items []api.TrackingItem
|
||||
|
||||
for _, item := range dbmodel {
|
||||
items = append(items, api.TrackingItem{
|
||||
Date: mapper.DateToString(item.Date),
|
||||
Type: item.Type,
|
||||
Value: item.Value,
|
||||
})
|
||||
}
|
||||
|
||||
if len(items) == 0 {
|
||||
return api.TrackingEntry{}
|
||||
} else {
|
||||
return api.TrackingEntry{
|
||||
Date: mapper.DateToString(dbmodel[0].Date),
|
||||
Items: items,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (mapper MapperImpl) TrackingEntryApiToDb(am interface{}) (dm interface{}) {
|
||||
apimodel := am.(api.TrackingEntry)
|
||||
|
||||
date, err := mapper.StringToDate(apimodel.Date)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Could not parse date `%s`", apimodel.Date)
|
||||
}
|
||||
|
||||
var items []db.TrackingItem
|
||||
for _, item := range apimodel.Items {
|
||||
items = append(items, db.TrackingItem{
|
||||
Date: date,
|
||||
Type: item.Type,
|
||||
Value: item.Value,
|
||||
})
|
||||
}
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
func (mapper MapperImpl) InboxApiToDs(am interface{}) (dm interface{}) {
|
||||
apimodel := am.(api.InboxItem)
|
||||
|
||||
return db.Inbox{
|
||||
Id: apimodel.Id,
|
||||
Item: apimodel.Item,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapper MapperImpl) InboxDsToApi(dm interface{}) (am interface{}) {
|
||||
dbmodel := dm.(db.Inbox)
|
||||
|
||||
return api.InboxItem{
|
||||
Id: dbmodel.Id,
|
||||
Item: dbmodel.Item,
|
||||
}
|
||||
}
|
||||
|
||||
func (mapper MapperImpl) StringToDate(dateString string) (time.Time, error) {
|
||||
|
||||
Reference in New Issue
Block a user