Skip to content

Commit

Permalink
Merge branch 'main' into add-user-batch-creation
Browse files Browse the repository at this point in the history
  • Loading branch information
RichDom2185 authored Jul 25, 2023
2 parents aef2dd6 + 13b7de4 commit be4c757
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions migrations/20230725162810-add_title_to_stories_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- +migrate Up

ALTER TABLE stories
ADD COLUMN title TEXT;

-- +migrate Down

ALTER TABLE stories
DROP COLUMN title;
1 change: 1 addition & 0 deletions model/stories.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type Story struct {
gorm.Model
AuthorID uint
Title string
Content string
}

Expand Down
2 changes: 2 additions & 0 deletions params/stories/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand All @@ -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,
}
}
2 changes: 2 additions & 0 deletions view/stories/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand All @@ -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,
}
}
Expand Down
2 changes: 2 additions & 0 deletions view/stories/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ 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"`
}

func SingleFrom(story model.Story) View {
storyView := View{
ID: story.ID,
AuthorID: story.AuthorID,
Title: story.Title,
Content: story.Content,
}
return storyView
Expand Down

0 comments on commit be4c757

Please sign in to comment.