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

Feat/official thing models #15

Merged
merged 4 commits into from
Nov 22, 2023
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
6 changes: 4 additions & 2 deletions internal/commands/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/Masterminds/semver/v3"
"github.com/web-of-things-open-source/tm-catalog-cli/internal"
"github.com/web-of-things-open-source/tm-catalog-cli/internal/model"
"github.com/web-of-things-open-source/tm-catalog-cli/internal/remotes"
)
Expand Down Expand Up @@ -65,8 +66,9 @@ func FetchThingByName(fn *FetchName, remote remotes.Remote) ([]byte, error) {
}
}

// TODO: how to know if it is official?
tmid, err := model.ParseTMID(id, false)
official := internal.Prep(tocThing.Author.Name) == internal.Prep(tocThing.Manufacturer.Name)
hadjian marked this conversation as resolved.
Show resolved Hide resolved

tmid, err := model.ParseTMID(id, official)
thing, err = remote.Fetch(tmid)
if err != nil {
msg := fmt.Sprintf("No thing model found for %s", fn)
Expand Down
14 changes: 8 additions & 6 deletions internal/toc/toc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"
"time"

"github.com/web-of-things-open-source/tm-catalog-cli/internal"
"github.com/web-of-things-open-source/tm-catalog-cli/internal/model"
)

Expand Down Expand Up @@ -106,20 +107,21 @@ func saveToc(rootPath string, tocBytes []byte) error {
}

func insert(table model.Toc, ctm model.CatalogThingModel) error {
// TODO: if author and manufacturer are equal, it is offical, right?
tmid, err := model.ParseTMID(ctm.ID, false)
official := internal.Prep(ctm.Manufacturer.Name) == internal.Prep(ctm.Author.Name)
hadjian marked this conversation as resolved.
Show resolved Hide resolved
tmid, err := model.ParseTMID(ctm.ID, official)
if err != nil {
return err
}
name := filepath.Dir(ctm.Path)
tocEntry, ok := table.Contents[name]
// TODO: provide copy method for CatalogThingModel in TocThing
if !ok {
tocEntry.Manufacturer = ctm.Manufacturer
tocEntry.Mpn = ctm.Mpn
tocEntry.Author = ctm.Author
tocEntry.Manufacturer.Name = tmid.Manufacturer
tocEntry.Mpn = tmid.Mpn
tocEntry.Author.Name = tmid.Author
}
tv := model.TocVersion{ExtendedFields: ctm.ExtendedFields, TimeStamp: tmid.Version.Timestamp, Version: ctm.Version}
version := model.Version{Model: tmid.Version.Base.String()}
tv := model.TocVersion{ExtendedFields: ctm.ExtendedFields, TimeStamp: tmid.Version.Timestamp, Version: version}
tocEntry.Versions = append(tocEntry.Versions, tv)
table.Contents[name] = tocEntry
return nil
Expand Down
Loading