-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add stories moderation #120
base: main
Are you sure you want to change the base?
Conversation
Running pre-commit hook... Go code is not formatted, commit blocked! The following files are not formatted: ./controller/stories/update.go ./internal/auth/middleware.go ./internal/permissions/users/permissions.go ./internal/permissions/users/role.go ./internal/router/router.go ./model/stories.go ./model/usergroups.go ./params/stories/moderate.go Run 'make format' to format your files and try again.
…y/stories-backend into stories-moderation fixed formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for working on this! I have some preliminary comments below:
const ( | ||
Draft StoryStatus = iota | ||
Pending | ||
Rejected | ||
Published | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This enum should not be part of the model
package and instead be a separate stories enum package.
func GetAllPublishedStories(db *gorm.DB, groupID *uint) ([]Story, error) { | ||
var stories []Story | ||
err := db. | ||
Where("status = ?", int(Published)). | ||
Where("group_id = ?", groupID). | ||
Preload(clause.Associations). | ||
// TODO: Abstract out the sorting logic | ||
Order("pin_order ASC NULLS LAST, title ASC, content ASC"). | ||
Find(&stories). | ||
Error | ||
if err != nil { | ||
return stories, database.HandleDBError(err, "story") | ||
} | ||
return stories, nil | ||
} | ||
|
||
func GetAllPendingStories(db *gorm.DB, groupID *uint) ([]Story, error) { | ||
var stories []Story | ||
err := db. | ||
Where("status = ?", int(Pending)). | ||
Where("group_id = ?", groupID). | ||
Preload(clause.Associations). | ||
// TODO: Abstract out the sorting logic | ||
Order("pin_order ASC NULLS LAST, title ASC, content ASC"). | ||
Find(&stories). | ||
Error | ||
if err != nil { | ||
return stories, database.HandleDBError(err, "story") | ||
} | ||
return stories, nil | ||
} | ||
|
||
func GetAllStoriesByStatus(db *gorm.DB, groupID *uint, status StoryStatus) ([]Story, error) { | ||
var stories []Story | ||
err := db. | ||
Where("status = ?", int(status)). | ||
Where("group_id = ?", groupID). | ||
Preload(clause.Associations). | ||
// TODO: Abstract out the sorting logic | ||
Order("pin_order ASC NULLS LAST, title ASC, content ASC"). | ||
Find(&stories). | ||
Error | ||
if err != nil { | ||
return stories, database.HandleDBError(err, "story") | ||
} | ||
return stories, nil | ||
} | ||
|
||
func GetAllAuthorStoriesByStatus(db *gorm.DB, groupID *uint, userID *int, status StoryStatus) ([]Story, error) { | ||
var stories []Story | ||
err := db. | ||
Where("status = ?", int(status)). | ||
Where("group_id = ?", groupID). | ||
Where("author_id = ?", userID). | ||
Preload(clause.Associations). | ||
// TODO: Abstract out the sorting logic | ||
Order("pin_order ASC NULLS LAST, title ASC, content ASC"). | ||
Find(&stories). | ||
Error | ||
if err != nil { | ||
return stories, database.HandleDBError(err, "story") | ||
} | ||
return stories, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extensive code duplication. This can be easily combined.
Content string `json:"content"` | ||
PinOrder *int `json:"pinOrder"` | ||
Status int `json:"status"` | ||
StatusMessage string `json:"statusMessage"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StatusMessage has type string
here, but in the model, it is of the type *string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which one is the correct one?
-- +migrate Up | ||
|
||
ALTER TABLE stories | ||
ADD COLUMN status INT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any constraints we want to add?
-- +migrate Up | ||
|
||
ALTER TABLE stories | ||
ADD COLUMN status_message TEXT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any constraints we want to add?
r.Get("/draft", handleAPIError(stories.HandleListDraft)) | ||
r.Get("/pending", handleAPIError(stories.HandleListPending)) | ||
r.Get("/published", handleAPIError(stories.HandleListPublished)) | ||
r.Get("/rejected", handleAPIError(stories.HandleListRejected)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filtering should be done via a query parameter, not separate routes.
source-academy/frontend#2928