Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added: optional manager filter for same contracts endpoint #501

Merged
merged 1 commit into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cmd/api/handlers/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
// @ID get-contract-same
// @Param network path string true "Network"
// @Param address path string true "KT address" minlength(36) maxlength(36)
// @Param manager query string false "Manager"
// @Param offset query integer false "Offset"
// @Param size query integer false "Requested count" mininum(1)
// @Accept json
Expand All @@ -28,8 +29,8 @@ func (ctx *Context) GetSameContracts(c *gin.Context) {
return
}

var pageReq pageableRequest
if err := c.BindQuery(&pageReq); ctx.handleError(c, err, http.StatusBadRequest) {
var query sameContractRequest
if err := c.BindQuery(&query); ctx.handleError(c, err, http.StatusBadRequest) {
return
}

Expand All @@ -39,7 +40,7 @@ func (ctx *Context) GetSameContracts(c *gin.Context) {
return
}

sameContracts, err := ctx.Contracts.GetSameContracts(contract, pageReq.Size, pageReq.Offset)
sameContracts, err := ctx.Contracts.GetSameContracts(contract, query.Manager, query.Size, query.Offset)
if err != nil {
if ctx.Storage.IsRecordNotFound(err) {
c.JSON(http.StatusOK, []interface{}{})
Expand Down
5 changes: 5 additions & 0 deletions cmd/api/handlers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ func (s subRequest) getMask() uint {
return b
}

type sameContractRequest struct {
pageableRequest
Manager string `form:"manager,omitempty"`
}

type voteRequest struct {
SourceAddress string `json:"src" binding:"required,address"`
SourceNetwork string `json:"src_network" binding:"required,network"`
Expand Down
16 changes: 12 additions & 4 deletions internal/elastic/contract/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func getArrayFilter(fieldName string, arr ...string) core.Item {
}

// GetSameContracts -
func (storage *Storage) GetSameContracts(c contract.Contract, size, offset int64) (pcr contract.SameResponse, err error) {
func (storage *Storage) GetSameContracts(c contract.Contract, manager string, size, offset int64) (pcr contract.SameResponse, err error) {
if c.Fingerprint == nil {
return pcr, errors.Errorf("Invalid contract data")
}
Expand All @@ -298,11 +298,19 @@ func (storage *Storage) GetSameContracts(c contract.Contract, size, offset int64
size = core.MaxQuerySize - offset
}

var filter core.Item
if manager == "" {
filter = core.Filter(core.MatchPhrase("hash", c.Hash))
} else {
filter = core.Filter(
core.MatchPhrase("hash", c.Hash),
core.MatchPhrase("manager", manager),
)
}

q := core.NewQuery().Query(
core.Bool(
core.Filter(
core.MatchPhrase("hash", c.Hash),
),
filter,
core.MustNot(
core.MatchPhrase("address", c.Address),
),
Expand Down
16 changes: 8 additions & 8 deletions internal/models/contract/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package contract

// Repository -
type Repository interface {
Get(map[string]interface{}) (Contract, error)
GetMany(map[string]interface{}) ([]Contract, error)
Get(by map[string]interface{}) (Contract, error)
GetMany(by map[string]interface{}) ([]Contract, error)
GetRandom() (Contract, error)
GetAddressesByNetworkAndLevel(string, int64) ([]string, error)
GetIDsByAddresses([]string, string) ([]string, error)
IsFA(string, string) (bool, error)
UpdateMigrationsCount(string, string) error
GetAddressesByNetworkAndLevel(network string, maxLevel int64) ([]string, error)
GetIDsByAddresses(addresses []string, network string) ([]string, error)
IsFA(network, address string) (bool, error)
UpdateMigrationsCount(address, network string) error
GetByAddresses(addresses []Address) ([]Contract, error)
GetTokens(string, string, int64, int64) ([]Contract, int64, error)
GetTokens(network, tokenInterface string, offset, size int64) ([]Contract, int64, error)
GetProjectsLastContract(contract *Contract) ([]Contract, error)
GetSameContracts(Contract, int64, int64) (SameResponse, error)
GetSameContracts(contact Contract, manager string, size, offset int64) (SameResponse, error)
GetSimilarContracts(Contract, int64, int64) ([]Similar, int, error)
GetDiffTasks() ([]DiffTask, error)
UpdateField(where []Contract, fields ...string) error
Expand Down
68 changes: 34 additions & 34 deletions internal/models/mock/contract/mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/reindexer/contract/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (storage *Storage) GetProjectsLastContract(c *contract.Contract) ([]contrac
}

// GetSameContracts -
func (storage *Storage) GetSameContracts(c contract.Contract, size, offset int64) (pcr contract.SameResponse, err error) {
func (storage *Storage) GetSameContracts(c contract.Contract, manager string, size, offset int64) (pcr contract.SameResponse, err error) {
if c.Fingerprint == nil {
return pcr, errors.Errorf("Invalid contract data")
}
Expand Down