From 606a99821752ddacc2e7b1349a5fe8d3f4519a2e Mon Sep 17 00:00:00 2001 From: forcodedancing Date: Mon, 6 Nov 2023 15:46:03 +0800 Subject: [PATCH] refine unknown category --- dao/item.go | 9 +++++++-- database/data.sql | 2 +- monitor/gnfd_block_processor.go | 2 +- service/item.go | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dao/item.go b/dao/item.go index 9f69d10..51971e2 100644 --- a/dao/item.go +++ b/dao/item.go @@ -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 { @@ -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) diff --git a/database/data.sql b/database/data.sql index 44258a0..675b124 100644 --- a/database/data.sql +++ b/database/data.sql @@ -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'); diff --git a/monitor/gnfd_block_processor.go b/monitor/gnfd_block_processor.go index 9f1cbff..c837c98 100644 --- a/monitor/gnfd_block_processor.go +++ b/monitor/gnfd_block_processor.go @@ -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 diff --git a/service/item.go b/service/item.go index d0992d7..a4b2b6a 100644 --- a/service/item.go +++ b/service/item.go @@ -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") }