Skip to content

Commit

Permalink
feat: card_order (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
orca-zhang authored Aug 29, 2024
1 parent c67898a commit bb4e035
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
9 changes: 7 additions & 2 deletions pkg/ysk/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
"github.com/IceWhaleTech/CasaOS-MessageBus/codegen"
)

type CartType string
type YSKCardIcon string
type (
CartType string
YSKCardIcon string
)

const (
CardTypeTask CartType = "task"
Expand Down Expand Up @@ -46,6 +48,9 @@ type YSKCard struct {
CardType CartType `json:"cardType"`
RenderType RenderType `json:"renderType"`
Content YSKCardContent `json:"content"`

Updated int64 `json:"-" gorm:"autoUpdateTime"`
Created int64 `json:"-" gorm:"autoCreateTime"`
}

func (ysk YSKCard) WithId(id string) YSKCard {
Expand Down
4 changes: 3 additions & 1 deletion repository/repository_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type DatabaseRepository struct {

func (r *DatabaseRepository) GetYSKCardList() ([]ysk.YSKCard, error) {
var cardList []ysk.YSKCard
if err := r.persistDB.Find(&cardList).Error; err != nil {
if err := r.persistDB.Order("updated desc, id desc").Find(&cardList).Error; err != nil {
return nil, err
}
return cardList, nil
Expand All @@ -33,9 +33,11 @@ func (r *DatabaseRepository) UpsertYSKCard(card ysk.YSKCard) error {
UpdateAll: true,
}).Create(&card).Error
}

func (r *DatabaseRepository) DeleteYSKCard(id string) error {
return r.persistDB.Where("id LIKE ?", id+"%").Delete(&ysk.YSKCard{}).Error
}

func (r *DatabaseRepository) GetEventTypes() ([]model.EventType, error) {
var eventTypes []model.EventType

Expand Down
6 changes: 0 additions & 6 deletions service/ysk.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ func (s *YSKService) YskCardList(ctx context.Context) ([]ysk.YSKCard, error) {
if err != nil {
return []ysk.YSKCard{}, err
}
// reverse card list
// make the latest card be the first one
for i, j := 0, len(cardList)-1; i < j; i, j = i+1, j-1 {
cardList[i], cardList[j] = cardList[j], cardList[i]
}
return cardList, nil
}

Expand Down Expand Up @@ -115,5 +110,4 @@ func (s *YSKService) Start(init bool) {
}
}
}()

}
5 changes: 4 additions & 1 deletion service/ysk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ func TestInsertAndGetCardList(t *testing.T) {

for _, card := range cardList {
if card.Id == utils.ApplicationInstallProgress.Id {
utils.ApplicationInstallProgress.Created = card.Created
utils.ApplicationInstallProgress.Updated = card.Updated
assert.DeepEqual(t, card, utils.ApplicationInstallProgress)
} else if card.Id == utils.ZimaOSDataStationNotice.Id {
utils.ZimaOSDataStationNotice.Created = card.Created
utils.ZimaOSDataStationNotice.Updated = card.Updated
assert.DeepEqual(t, card, utils.ZimaOSDataStationNotice)
} else {
t.Errorf("unexpected card: %v", card)
Expand Down Expand Up @@ -78,5 +82,4 @@ func TestInsertAllTypeCardList(t *testing.T) {
cardList, err = yskService.YskCardList(context.Background())
assert.NilError(t, err)
assert.Equal(t, len(cardList), 2)

}

0 comments on commit bb4e035

Please sign in to comment.