Skip to content

Commit

Permalink
Renamed categories to collections, as per pebble-dev#7
Browse files Browse the repository at this point in the history
  • Loading branch information
azertyfun committed Aug 10, 2017
1 parent 8c94e9f commit c6c5c64
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
14 changes: 7 additions & 7 deletions admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ func AdminRebuildDBHandler(ctx *handlerContext, w http.ResponseWriter, r *http.R

// Placeholder until we implement an actual collections system.
sqlStmt = `
create table categories (
create table collections (
id text not null primary key,
name text,
color text
);
delete from categories;
delete from collections;
`
_, err = db.Exec(sqlStmt)
if err != nil {
Expand All @@ -164,14 +164,14 @@ func AdminRebuildDBHandler(ctx *handlerContext, w http.ResponseWriter, r *http.R
defer stmt.Close()

authors := make(map[string]int)
categoriesNames := make(map[string]string)
categoriesColors := make(map[string]string)
collectionNames := make(map[string]string)
collectionColors := make(map[string]string)
lastAuthorId := 0
path, errc := walkFiles("PebbleAppStore/")
apps := make(map[string]RebbleApplication)
versions := make(map[string]([]RebbleVersion))
for item := range path {
app, v := parseApp(item, &authors, &lastAuthorId, &categoriesNames, &categoriesColors)
app, v := parseApp(item, &authors, &lastAuthorId, &collectionNames, &collectionColors)

if _, ok := apps[app.Id]; ok {
(*apps[app.Id].Assets.Screenshots) = append((*apps[app.Id].Assets.Screenshots), (*app.Assets.Screenshots)[0])
Expand Down Expand Up @@ -217,8 +217,8 @@ func AdminRebuildDBHandler(ctx *handlerContext, w http.ResponseWriter, r *http.R
}
}

for id, category := range categoriesNames {
_, err = tx.Exec("INSERT INTO categories(id, name, color) VALUES(?, ?, ?)", id, category, categoriesColors[id])
for id, collection := range collectionNames {
_, err = tx.Exec("INSERT INTO collections(id, name, color) VALUES(?, ?, ?)", id, collection, collectionColors[id])
if err != nil {
log.Fatal(err)
}
Expand Down
42 changes: 21 additions & 21 deletions application.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type RebbleApplication struct {

// RebbleTagList contains a list of tag. Used by getApi(id)
type RebbleTagList struct {
Tags []RebbleCategory `json:"tags"`
Tags []RebbleCollection `json:"tags"`
}

// RebbleChangelog contains a list of version changes for an app
Expand All @@ -52,14 +52,14 @@ type RebbleVersion struct {

// RebbleAppInfo contains information about the app (pbw url, versioning, links, etc.)
type RebbleAppInfo struct {
PbwUrl string `json:"pbwUrl"`
RebbleReady bool `json:"rebbleReady"`
Tags []RebbleCategory `json:"tags"`
Updated JSONTime `json:"updated"`
Version string `json:"version"`
SupportUrl string `json:"supportUrl"`
AuthorUrl string `json:"authorUrl"`
SourceUrl string `json:"sourceUrl"`
PbwUrl string `json:"pbwUrl"`
RebbleReady bool `json:"rebbleReady"`
Tags []RebbleCollection `json:"tags"`
Updated JSONTime `json:"updated"`
Version string `json:"version"`
SupportUrl string `json:"supportUrl"`
AuthorUrl string `json:"authorUrl"`
SourceUrl string `json:"sourceUrl"`
}

// RebbleAuthor describes the autor of a Rebble app (ID and name)
Expand All @@ -81,8 +81,8 @@ type RebbleScreenshotsPlatform struct {
Screenshots []string `json:"screenshots"`
}

// RebbleCategory describes the category (collection) of a Rebble application
type RebbleCategory struct {
// RebbleCollection describes the collection (category) of a Rebble application
type RebbleCollection struct {
Id string `json:"id"`
Name string `json:"name"`
Color string `json:"color"`
Expand Down Expand Up @@ -174,7 +174,7 @@ func (psi *PebbleScreenshotImages) UnmarshalJSON(b []byte) error {
return json.Unmarshal(b, (*([]PebbleScreenshotImage))(psi))
}

func parseApp(path string, authors *map[string]int, lastAuthorId *int, categoriesNames, categoriesColors *map[string]string) (*RebbleApplication, *[]RebbleVersion) {
func parseApp(path string, authors *map[string]int, lastAuthorId *int, collectionNames, collectionColors *map[string]string) (*RebbleApplication, *[]RebbleVersion) {
f, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal(err)
Expand All @@ -197,14 +197,14 @@ func parseApp(path string, authors *map[string]int, lastAuthorId *int, categorie
*lastAuthorId = *lastAuthorId + 1
}

// Create category if it doesn't exist
if _, ok := (*categoriesNames)[data.Apps[0].CategoryId]; !ok {
(*categoriesNames)[data.Apps[0].CategoryId] = data.Apps[0].CategoryName
(*categoriesColors)[data.Apps[0].CategoryId] = data.Apps[0].CategoryColor
// Create collection if it doesn't exist
if _, ok := (*collectionNames)[data.Apps[0].CategoryId]; !ok {
(*collectionNames)[data.Apps[0].CategoryId] = data.Apps[0].CategoryName
(*collectionColors)[data.Apps[0].CategoryId] = data.Apps[0].CategoryColor
}

app := RebbleApplication{}
app.AppInfo.Tags = make([]RebbleCategory, 1)
app.AppInfo.Tags = make([]RebbleCollection, 1)
screenshots := make(([]RebbleScreenshotsPlatform), 0)
app.Assets.Screenshots = &screenshots

Expand Down Expand Up @@ -368,12 +368,12 @@ func AppHandler(w http.ResponseWriter, r *http.Request) {
app.Published.Time = time.Unix(0, t_published)
app.AppInfo.Updated.Time = time.Unix(0, t_updated)
json.Unmarshal(tagIds_b, &tagIds)
app.AppInfo.Tags = make([]RebbleCategory, len(tagIds))
app.AppInfo.Tags = make([]RebbleCollection, len(tagIds))
json.Unmarshal(screenshots_b, &screenshots)
app.Assets.Screenshots = screenshots

for i, tagId := range tagIds {
rows, err := db.Query("SELECT id, name, color FROM categories WHERE id=?", tagId)
rows, err := db.Query("SELECT id, name, color FROM collections WHERE id=?", tagId)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -425,10 +425,10 @@ func TagsHandler(w http.ResponseWriter, r *http.Request) {
}
json.Unmarshal(tagIds_b, &tagIds)
tagList := RebbleTagList{}
tagList.Tags = make([]RebbleCategory, len(tagIds))
tagList.Tags = make([]RebbleCollection, len(tagIds))

for i, tagId := range tagIds {
rows, err := db.Query("SELECT id, name, color FROM categories WHERE id=?", tagId)
rows, err := db.Query("SELECT id, name, color FROM collections WHERE id=?", tagId)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit c6c5c64

Please sign in to comment.