From e9d0a773176947026ae0561acce8c90075e66324 Mon Sep 17 00:00:00 2001 From: Ethan Date: Thu, 16 May 2024 17:02:19 +0800 Subject: [PATCH] fix: review comments --- dao/listing.go | 8 ++++---- monitor/gnfd_block_processor.go | 7 ++++++- restapi/configure_mind_marketplace.go | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/dao/listing.go b/dao/listing.go index cac5ccc..ff0ee30 100644 --- a/dao/listing.go +++ b/dao/listing.go @@ -29,9 +29,9 @@ func (dao *DbListingDao) Create(context context.Context, listing *database.Listi } func (dao *DbListingDao) GetByGroupId(context context.Context, groupId int64) (database.Listing, error) { - var item = database.Listing{} - if err := dao.db.Where("group_id = ?", groupId).Take(&item).Error; err != nil { - return item, err + var listing = database.Listing{} + if err := dao.db.Where("group_id = ?", groupId).Take(&listing).Error; err != nil { + return listing, err } - return item, nil + return listing, nil } diff --git a/monitor/gnfd_block_processor.go b/monitor/gnfd_block_processor.go index 2bdc340..54d4c76 100644 --- a/monitor/gnfd_block_processor.go +++ b/monitor/gnfd_block_processor.go @@ -233,13 +233,18 @@ func (p *GnfdBlockProcessor) handleEventCreateGroup(blockHeight uint64, event ab } listing, err := p.listingDao.GetByGroupId(context.Background(), int64(createGroup.GroupId.Uint64())) - if err == nil { + if err == nil && listing.Id > 0 { return fmt.Sprintf("insert into items (category_id, group_id, group_name, name, owner_address, status, description, url, listed_at, created_gnfd_height, price)"+ " values (%d, %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, %s)", categoryId, createGroup.GroupId.Uint64(), createGroup.GroupName, resourceName, createGroup.Owner, database.ItemListed, escape(extra.Desc), escape(extra.Url), block.Time.Unix(), blockHeight, listing.Price), nil } + if err != nil { + util.Logger.Errorf("processor: %s, fail to get listing err: %s", p.Name(), err) + return rawSql, err + } + return fmt.Sprintf("insert into items (category_id, group_id, group_name, name, owner_address, status, description, url, listed_at, created_gnfd_height)"+ " values (%d, %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d)", categoryId, createGroup.GroupId.Uint64(), createGroup.GroupName, resourceName, createGroup.Owner, diff --git a/restapi/configure_mind_marketplace.go b/restapi/configure_mind_marketplace.go index a5b3a70..d503e9e 100644 --- a/restapi/configure_mind_marketplace.go +++ b/restapi/configure_mind_marketplace.go @@ -51,7 +51,7 @@ func configureAPI(api *operations.MindMarketplaceAPI) http.Handler { go func() { http.Handle("/metrics", promhttp.Handler()) - util.Logger.Fatal(http.ListenAndServe(":9293", nil)) + util.Logger.Fatal(http.ListenAndServe(":9292", nil)) }() api.JSONConsumer = runtime.JSONConsumer()