Skip to content

Commit

Permalink
refine unknown category
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing committed Nov 6, 2023
1 parent 55635c8 commit 606a998
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions dao/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ItemDao interface {
Update(context context.Context, collection *database.Item) error
Get(context context.Context, id int64, includeAll bool) (database.Item, error)
GetByGroupId(context context.Context, groupId int64, includeAll bool) (database.Item, error)
Search(context context.Context, address, keyword string, includeAll bool, sort string, offset, limit int) (int64, []*database.Item, error)
Search(context context.Context, categoryId int64, address, keyword string, includeAll bool, sort string, offset, limit int) (int64, []*database.Item, error)
}

type dbItemDao struct {
Expand Down Expand Up @@ -97,10 +97,15 @@ func (dao *dbItemDao) GetByGroupId(context context.Context, groupId int64, inclu
return item, nil
}

func (dao *dbItemDao) Search(context context.Context, address, keyword string, includeAll bool, sort string, offset, limit int) (total int64, items []*database.Item, err error) {
func (dao *dbItemDao) Search(context context.Context, categoryId int64, address, keyword string, includeAll bool, sort string, offset, limit int) (total int64, items []*database.Item, err error) {
rawSql := " where 1 = 1 "
parameters := make([]interface{}, 0)

if categoryId > 0 {
rawSql = rawSql + ` and category_id = ?`
parameters = append(parameters, categoryId)
}

if len(address) > 0 {
rawSql = rawSql + ` and owner_address = ?`
parameters = append(parameters, address)
Expand Down
2 changes: 1 addition & 1 deletion database/data.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
insert into categories(id, name) values (0, 'Uncategorized');
insert into categories(id, name) values (100, 'Uncategorized');
insert into categories(id, name) values (1, 'AI Model');
insert into categories(id, name) values (2, 'Code Resource');
insert into categories(id, name) values (3, 'Digital Media');
Expand Down
2 changes: 1 addition & 1 deletion monitor/gnfd_block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

// unknownCategoryId defines the id of unknown category in database
const unknownCategoryId = int64(0)
const unknownCategoryId = int64(100)

type GnfdBlockProcessor struct {
client *GnfdCompositeClients
Expand Down
2 changes: 1 addition & 1 deletion service/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (s *ItemService) Search(context context.Context, request *models.SearchItem
return 0, nil, TooBigLimitErr
}

total, items, err := s.itemDao.Search(context, address, keyword, false, sort, offset, limit)
total, items, err := s.itemDao.Search(context, request.Filter.CategoryID, address, keyword, false, sort, offset, limit)
if err != nil {
return 0, nil, fmt.Errorf("fail to search item")
}
Expand Down

0 comments on commit 606a998

Please sign in to comment.