Implement rough architecture
This commit is contained in:
37
backend/mapping/mapperImpl.go
Normal file
37
backend/mapping/mapperImpl.go
Normal file
@ -0,0 +1,37 @@
|
||||
package mapping
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
|
||||
api "github.com/moustachioed/dash/backend/dashapi"
|
||||
db "github.com/moustachioed/dash/backend/database/models"
|
||||
)
|
||||
|
||||
type MapperImpl struct{}
|
||||
|
||||
func NewMapperImpl() Mapper {
|
||||
return MapperImpl{}
|
||||
}
|
||||
|
||||
func (mapper MapperImpl) JournalApiToDb(apimodel api.JournalEntry) db.Journal {
|
||||
date, err := time.Parse("2006-01-02", apimodel.Date)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Could not parse date `%s`", apimodel.Date)
|
||||
}
|
||||
|
||||
dbmodel := db.Journal{
|
||||
Date: datatypes.Date(date),
|
||||
// Thankful: datatypes.JSON([]byte(api.Thankful)),
|
||||
}
|
||||
|
||||
return dbmodel
|
||||
}
|
||||
|
||||
func (mapper MapperImpl) JournalDbToApi(db.Journal) api.JournalEntry {
|
||||
apimodel := api.JournalEntry{}
|
||||
|
||||
return apimodel
|
||||
}
|
||||
Reference in New Issue
Block a user