Skip to content

Commit

Permalink
fix: change type & url
Browse files Browse the repository at this point in the history
  • Loading branch information
TGRZiminiar committed Aug 24, 2024
1 parent 22cbcf9 commit e8e3fd5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 51 deletions.
4 changes: 2 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func GetProjectApi(limit int, offset int, authorizeKey string) (*Response, error

}

func GetAllProjects(authorizeKey string) ([]Datum, error) {
func GetAllProjects(authorizeKey string) ([]Project, error) {
var conditionBreak bool = false
var limit, offset int = 100, 0

var datas []Datum
var datas []Project

for !conditionBreak {
res, err := GetProjectApi(limit, offset, authorizeKey)
Expand Down
6 changes: 3 additions & 3 deletions cache-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (ca *CacheApi) HandleCacheApi(c *fiber.Ctx) error {

cacheData, exist := ca.Cache.Get(API_CACHE_KEY)
if exist {
if data, ok := cacheData.([]Datum); ok {
if data, ok := cacheData.([]Project); ok {
return c.Status(fiber.StatusOK).JSON(fiber.Map{
"msg": "ok",
"data": data,
Expand All @@ -53,11 +53,11 @@ func (ca *CacheApi) HandleCacheApi(c *fiber.Ctx) error {
})
}

func handleCache(c *cache.Cache, authorizeKey string) ([]Datum, error) {
func handleCache(c *cache.Cache, authorizeKey string) ([]Project, error) {
res, err := GetAllProjects(authorizeKey)
if err != nil {
slog.Error("failed to handle cache", "error", err)
return []Datum{}, err
return []Project{}, err
}
c.Set(API_CACHE_KEY, res, cache.NoExpiration)
return res, nil
Expand Down
102 changes: 56 additions & 46 deletions type.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
package main

type Response struct {
Meta Meta `json:"meta"`
Data []Datum `json:"data"`
Meta Metadata `json:"meta"`
Data []Project `json:"data"`
}

type Datum struct {
ID string `json:"id"`
Category Category `json:"category"`
Organization interface{} `json:"organization"`
Name string `json:"name"`
Description string `json:"description"`
ProfileAvatarURL string `json:"profileAvatarUrl"`
ProjectCoverImageURL string `json:"projectCoverImageUrl"`
SocialLinks SocialLinks `json:"socialLinks"`
Team []string `json:"team"`
Github []string `json:"github"`
Packages []string `json:"packages"`
Links []interface{} `json:"links"`
Contracts []Contract `json:"contracts"`
GrantsAndFunding GrantsAndFunding `json:"grantsAndFunding"`
type Metadata struct {
HasNext bool `json:"has_next"`
TotalReturned int64 `json:"total_returned"`
NextOffset int64 `json:"next_offset"`
}

type Project struct {
ID string `json:"id"`
Category Category `json:"category"`
Name string `json:"name"`
Description string `json:"description"`
ProfileAvatarURL string `json:"profileAvatarUrl"`
ProjectCoverImageURL string `json:"projectCoverImageUrl"`
SocialLinks SocialLinks `json:"socialLinks"`
Team []string `json:"team"`
Github []map[string]Github `json:"github"`
Packages []interface{} `json:"packages"`
Contracts []Contract `json:"contracts"`
GrantsAndFunding GrantsAndFunding `json:"grantsAndFunding"`
Organization *Organization `json:"organization"`
Links []string `json:"links"`
}

type Contract struct {
Expand All @@ -29,36 +35,54 @@ type Contract struct {
ChainID int64 `json:"chainId"`
}

type Github struct {
RepoRank int64 `json:"repo_rank"`
StarCount int64 `json:"star_count"`
StarredEvents int64 `json:"starred_events"`
StarredByTopDevs int64 `json:"starred_by_top_devs"`
ForkCount int64 `json:"fork_count"`
ForkedEvents int64 `json:"forked_events"`
ForkedByTopDevs int64 `json:"forked_by_top_devs"`
FulltimeDeveloperAverage6_Months float64 `json:"fulltime_developer_average_6_months"`
NewContributorCount6_Months int64 `json:"new_contributor_count_6_months"`
AgeOfProjectYears float64 `json:"age_of_project_years"`
}

type GrantsAndFunding struct {
VentureFunding []VentureFunding `json:"ventureFunding"`
Grants []Grant `json:"grants"`
Revenue []Revenue `json:"revenue"`
}

type Grant struct {
Grant string `json:"grant"`
Link *string `json:"link"`
Amount string `json:"amount"`
Date string `json:"date"`
Details string `json:"details"`
Grant string `json:"grant"`
Link string `json:"link"`
Amount string `json:"amount"`
Date string `json:"date"`
Details string `json:"details"`
}

type Revenue struct {
Amount Amount `json:"amount"`
Amount string `json:"amount"`
Details string `json:"details"`
}

type VentureFunding struct {
Amount Amount `json:"amount"`
Amount string `json:"amount"`
Year string `json:"year"`
Details string `json:"details"`
}

type Organization struct {
Name string `json:"name"`
ProfileAvatarURL string `json:"profileAvatarUrl"`
}

type SocialLinks struct {
Twitter *string `json:"twitter"`
Farcaster []string `json:"farcaster"`
Mirror *string `json:"mirror"`
Website []string `json:"website"`
Twitter string `json:"twitter"`
Farcaster []string `json:"farcaster"`
Mirror interface{} `json:"mirror"`
Website []string `json:"website"`
}

type Meta struct {
Expand All @@ -70,22 +94,8 @@ type Meta struct {
type Category string

const (
CeFi Category = "CeFi"
CrossChain Category = "Cross Chain"
DeFi Category = "DeFi"
Governance Category = "Governance"
Nft Category = "NFT"
Social Category = "Social"
Utility Category = "Utility"
)

type Amount string

const (
Above5M Amount = "above-5m"
The1M3M Amount = "1m-3m"
The250K500K Amount = "250k-500k"
The3M5M Amount = "3m-5m"
The500K1M Amount = "500k-1m"
Under250K Amount = "under-250k"
EthereumCoreContributions Category = "ETHEREUM_CORE_CONTRIBUTIONS"
OpStackReseachAndDevelopment Category = "OP_STACK_RESEACH_AND_DEVELOPMENT"
OpStackResearchAndDevelopment Category = "OP_STACK_RESEARCH_AND_DEVELOPMENT"
OpStackTooling Category = "OP_STACK_TOOLING"
)

0 comments on commit e8e3fd5

Please sign in to comment.