Browse Source

rpdata-as2storyimport: Changed to use new models.

1.0
Gisle Aune 6 years ago
parent
commit
efa98b80cc
  1. 26
      cmd/rpdata-as2storyimport/main.go

26
cmd/rpdata-as2storyimport/main.go

@ -8,7 +8,9 @@ import (
"time" "time"
"git.aiterp.net/rpdata/api/internal/store" "git.aiterp.net/rpdata/api/internal/store"
"git.aiterp.net/rpdata/api/model/story"
"git.aiterp.net/rpdata/api/models"
"git.aiterp.net/rpdata/api/models/chapters"
"git.aiterp.net/rpdata/api/models/stories"
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
) )
@ -71,14 +73,20 @@ func main() {
log.Fatalln(err) log.Fatalln(err)
} }
tags := make([]story.Tag, 0, 8)
tags := make([]models.Tag, 0, 8)
for _, tagResult := range tagResults { for _, tagResult := range tagResults {
if tagResult.PageID == result.ID { if tagResult.PageID == result.ID {
tags = append(tags, story.Tag{Kind: tagResult.Type, Name: tagResult.Name})
tags = append(tags, models.Tag{Kind: models.TagKind(tagResult.Type), Name: tagResult.Name})
} }
} }
story, err := story.New(result.Name, result.Author[5:], result.Category, false, false, tags, publishDate, fictionalDate)
category := models.StoryCategory(result.Category)
if category.IsValid() {
log.Println(result.Name, "does not have a valid category:", result.Category)
continue
}
story, err := stories.Add(result.Name, result.Author[5:], category, true, false, tags, publishDate, fictionalDate)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
@ -96,19 +104,11 @@ func main() {
} }
} }
chapter, err := story.AddChapter(title, result.Author[5:], result.Source, publishDate, fictionalDate)
chapter, err := chapters.Add(story, title, result.Author[5:], result.Source, publishDate, &fictionalDate)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
if !result.Unlisted {
listed := true
err := story.Edit(nil, nil, &listed, nil, nil)
if err != nil {
log.Fatalln(err)
}
}
fmt.Println(result.ID, "->", story.ID, chapter.ID) fmt.Println(result.ID, "->", story.ID, chapter.ID)
} }
} }

Loading…
Cancel
Save