-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add category, account apis; monitor price update events (#2)
- Loading branch information
1 parent
ba6b0d5
commit 9c51b37
Showing
46 changed files
with
2,943 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package dao | ||
|
||
import ( | ||
"context" | ||
"gorm.io/gorm" | ||
|
||
"github.com/bnb-chain/mind-marketplace-backend/database" | ||
) | ||
|
||
type CategoryDao interface { | ||
Create(context context.Context, category *database.Category) error | ||
Get(context context.Context, name string) (database.Category, error) | ||
GetAll(context context.Context) ([]database.Category, error) | ||
} | ||
|
||
type dbCategoryDao struct { | ||
db *gorm.DB | ||
} | ||
|
||
func NewDbCategoryDao(db *gorm.DB) CategoryDao { | ||
return &dbCategoryDao{ | ||
db: db, | ||
} | ||
} | ||
|
||
func (dao *dbCategoryDao) Create(context context.Context, category *database.Category) error { | ||
if err := dao.db.Omit("Items").Create(category).Error; err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (dao *dbCategoryDao) Get(context context.Context, name string) (database.Category, error) { | ||
var category = database.Category{} | ||
if err := dao.db.Raw("select from categories where lower(name) = ?", name).Take(&category).Error; err != nil { | ||
return category, err | ||
} | ||
return category, nil | ||
} | ||
|
||
func (dao *dbCategoryDao) GetAll(context context.Context) ([]database.Category, error) { | ||
var categories []database.Category | ||
if err := dao.db.Omit("Items").Find(&categories).Error; err != nil { | ||
return categories, err | ||
} | ||
return categories, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package database | ||
|
||
type Category struct { | ||
Id int64 `json:"id" gorm:"primaryKey;not null;autoIncrement:false"` | ||
Name string `json:"name" gorm:"not null;size:32"` | ||
|
||
Items []*Item `json:"items" gorm:"foreignKey:CategoryId"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
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'); | ||
insert into categories(id, name) values (4, 'Literary Creation'); | ||
insert into categories(id, name) values (5, 'Scientific Data'); | ||
insert into categories(id, name) values (6, 'Game'); | ||
insert into categories(id, name) values (7, 'AIGC'); | ||
insert into categories(id, name) values (8, 'Education'); | ||
insert into categories(id, name) values (9, 'Finance'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.