WIP: Sync now saves the data
This commit is contained in:
parent
b11464121c
commit
41bf858523
@ -16,8 +16,28 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SynchronizePiwigoCategories(piwigoApi piwigo.PiwigoCategoryApi, datastore datastore.CategoryProvider) error {
|
func SynchronizePiwigoCategories(piwigoApi piwigo.PiwigoCategoryApi, db datastore.CategoryProvider) error {
|
||||||
return errors.New("N/A")
|
|
||||||
|
categories, err := piwigoApi.GetAllCategories()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, pwgcat := range categories {
|
||||||
|
cat := datastore.CategoryData{
|
||||||
|
PiwigoId: pwgcat.Id,
|
||||||
|
PiwigoParentId: pwgcat.ParentId,
|
||||||
|
Name: pwgcat.Name,
|
||||||
|
Key: pwgcat.Key,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = db.SaveCategory(cat)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAllCategoriesFromServer(piwigoApi piwigo.PiwigoCategoryApi) (map[string]*piwigo.PiwigoCategory, error) {
|
func GetAllCategoriesFromServer(piwigoApi piwigo.PiwigoCategoryApi) (map[string]*piwigo.PiwigoCategory, error) {
|
||||||
|
@ -20,15 +20,18 @@ func Test_SynchronizePiwigoCategories_adds_new_categories(t *testing.T) {
|
|||||||
defer mockCtrl.Finish()
|
defer mockCtrl.Finish()
|
||||||
|
|
||||||
piwigoCategory := createTestPiwigoCategory(1)
|
piwigoCategory := createTestPiwigoCategory(1)
|
||||||
piwigoCategories := []piwigo.PiwigoCategory{piwigoCategory}
|
|
||||||
|
piwigoCategories := make(map[string]*piwigo.PiwigoCategory)
|
||||||
|
piwigoCategories[piwigoCategory.Key] = &piwigoCategory
|
||||||
|
numberOfCategories := len(piwigoCategories)
|
||||||
|
|
||||||
category := createTestCategoryData(1)
|
category := createTestCategoryData(1)
|
||||||
|
|
||||||
dbmock := NewMockCategoryProvider(mockCtrl)
|
dbmock := NewMockCategoryProvider(mockCtrl)
|
||||||
dbmock.EXPECT().SaveCategory(category).Times(1)
|
dbmock.EXPECT().SaveCategory(category).Times(numberOfCategories)
|
||||||
|
|
||||||
piwigoMock := NewMockPiwigoCategoryApi(mockCtrl)
|
piwigoMock := NewMockPiwigoCategoryApi(mockCtrl)
|
||||||
piwigoMock.EXPECT().GetAllCategories().Return(piwigoCategories).Times(1)
|
piwigoMock.EXPECT().GetAllCategories().Return(piwigoCategories, nil).Times(len(piwigoCategories))
|
||||||
|
|
||||||
err := SynchronizePiwigoCategories(piwigoMock, dbmock)
|
err := SynchronizePiwigoCategories(piwigoMock, dbmock)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -48,7 +51,7 @@ func createTestPiwigoCategory(piwigoId int) piwigo.PiwigoCategory {
|
|||||||
|
|
||||||
func createTestCategoryData(piwigoId int) datastore.CategoryData {
|
func createTestCategoryData(piwigoId int) datastore.CategoryData {
|
||||||
cat := datastore.CategoryData{
|
cat := datastore.CategoryData{
|
||||||
CategoryId: 1,
|
CategoryId: 0,
|
||||||
PiwigoId: piwigoId,
|
PiwigoId: piwigoId,
|
||||||
PiwigoParentId: 0,
|
PiwigoParentId: 0,
|
||||||
Name: "2019",
|
Name: "2019",
|
||||||
|
Loading…
Reference in New Issue
Block a user