Skip to content

Commit

Permalink
feat: Add stack exchange table.
Browse files Browse the repository at this point in the history
  • Loading branch information
fourjuaneight committed Jun 6, 2023
1 parent c5eb8fd commit 52811ea
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
40 changes: 40 additions & 0 deletions collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,46 @@ func githubCollection() *models.Collection {
return collection
}

func stackExchangeCollection() *models.Collection {
collection := &models.Collection{
Name: "stack_exchange",
Type: models.CollectionTypeBase,
ListRule: nil,
ViewRule: types.Pointer("@request.auth.id != ''"),
CreateRule: types.Pointer(""),
UpdateRule: types.Pointer("@request.auth.id != ''"),
DeleteRule: nil,
Schema: schema.NewSchema(
&schema.SchemaField{
Name: "title",
Type: schema.FieldTypeText,
Required: false,
Unique: false,
},
&schema.SchemaField{
Name: "question",
Type: schema.FieldTypeText,
Required: true,
Unique: false,
},
&schema.SchemaField{
Name: "answer",
Type: schema.FieldTypeText,
Required: false,
Unique: false,
},
&schema.SchemaField{
Name: "tags",
Type: schema.FieldTypeJson,
Required: false,
Unique: false,
},
),
}

return collection
}

func metaCollection() *models.Collection {
collection := &models.Collection{
Name: "meta",
Expand Down
16 changes: 15 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func main() {
mtgCollection(),
recordsCollection(),
githubCollection(),
stackExchangeCollection(),
metaCollection(),
}

Expand Down Expand Up @@ -100,13 +101,26 @@ func main() {

repo, repoErr := helpers.GetRepoInfo(url)
if repoErr != nil {
return fmt.Errorf("[OnRecordAfterCreateRequest][archiveErr]: %w", repoErr)
return fmt.Errorf("[OnRecordAfterCreateRequest][repoErr]: %w", repoErr)
}

record.Set("name", repo.Name)
record.Set("owner", repo.Owner)
record.Set("description", repo.Description)
record.Set("language", repo.Language)
case "stack_exchange":
// query repository info
question := record.SchemaData()["question"].(string)

questionInfo, questionInfoErr := helpers.GetQuestionInfo(question)
if questionInfoErr != nil {
return fmt.Errorf("[OnRecordAfterCreateRequest][questionInfoErr]: %w", questionInfoErr)
}

record.Set("title", questionInfo.Title)
record.Set("question", questionInfo.Question)
record.Set("answers", questionInfo.Answer)
record.Set("tags", questionInfo.Tags)
default:
}

Expand Down

0 comments on commit 52811ea

Please sign in to comment.