diff --git a/migrations/20230725162810-add_title_to_stories_table.sql b/migrations/20230725162810-add_title_to_stories_table.sql new file mode 100644 index 0000000..a4aa216 --- /dev/null +++ b/migrations/20230725162810-add_title_to_stories_table.sql @@ -0,0 +1,9 @@ +-- +migrate Up + +ALTER TABLE stories +ADD COLUMN title TEXT; + +-- +migrate Down + +ALTER TABLE stories +DROP COLUMN title; diff --git a/model/stories.go b/model/stories.go index 08c5629..ad3faf4 100644 --- a/model/stories.go +++ b/model/stories.go @@ -8,6 +8,7 @@ import ( type Story struct { gorm.Model AuthorID uint + Title string Content string } diff --git a/params/stories/create.go b/params/stories/create.go index 45ebdf7..24e1591 100644 --- a/params/stories/create.go +++ b/params/stories/create.go @@ -4,6 +4,7 @@ import "github.com/source-academy/stories-backend/model" type Create struct { AuthorID uint `json:"authorId"` + Title string `json:"title"` Content string `json:"content"` } @@ -15,6 +16,7 @@ func (params *Create) Validate() error { func (params *Create) ToModel() *model.Story { return &model.Story{ AuthorID: params.AuthorID, + Title: params.Title, Content: params.Content, } } diff --git a/view/stories/list.go b/view/stories/list.go index a347741..545d6e6 100644 --- a/view/stories/list.go +++ b/view/stories/list.go @@ -4,6 +4,7 @@ import "github.com/source-academy/stories-backend/model" type ListView struct { AuthorID uint `json:"authorId"` + Title string `json:"title"` Content string `json:"content"` } @@ -12,6 +13,7 @@ func ListFrom(stories []model.Story) []ListView { for i, story := range stories { storiesListView[i] = ListView{ AuthorID: story.AuthorID, + Title: story.Title, Content: story.Content, } } diff --git a/view/stories/view.go b/view/stories/view.go index aa779c6..8a4b64b 100644 --- a/view/stories/view.go +++ b/view/stories/view.go @@ -5,6 +5,7 @@ import "github.com/source-academy/stories-backend/model" type View struct { ID uint `json:"storyId"` AuthorID uint `json:"authorId"` + Title string `json:"title"` Content string `json:"content"` } @@ -12,6 +13,7 @@ func SingleFrom(story model.Story) View { storyView := View{ ID: story.ID, AuthorID: story.AuthorID, + Title: story.Title, Content: story.Content, } return storyView