Draft
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
Member
7 tasks
RichDom2185
requested changes
Apr 15, 2024
Comment on lines
+12
to
+17
| const ( | ||
| Draft StoryStatus = iota | ||
| Pending | ||
| Rejected | ||
| Published | ||
| ) |
Member
There was a problem hiding this comment.
This enum should not be part of the model package and instead be a separate stories enum package.
Comment on lines
+50
to
+113
| 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 | ||
| } |
Member
There was a problem hiding this comment.
Extensive code duplication. This can be easily combined.
| Content string `json:"content"` | ||
| PinOrder *int `json:"pinOrder"` | ||
| Status int `json:"status"` | ||
| StatusMessage string `json:"statusMessage"` |
Member
There was a problem hiding this comment.
StatusMessage has type string here, but in the model, it is of the type *string.
Member
There was a problem hiding this comment.
Which one is the correct one?
| -- +migrate Up | ||
|
|
||
| ALTER TABLE stories | ||
| ADD COLUMN status INT; |
Member
There was a problem hiding this comment.
Are there any constraints we want to add?
| -- +migrate Up | ||
|
|
||
| ALTER TABLE stories | ||
| ADD COLUMN status_message TEXT; |
Member
There was a problem hiding this comment.
Are there any constraints we want to add?
Comment on lines
+58
to
+61
| r.Get("/draft", handleAPIError(stories.HandleListDraft)) | ||
| r.Get("/pending", handleAPIError(stories.HandleListPending)) | ||
| r.Get("/published", handleAPIError(stories.HandleListPublished)) | ||
| r.Get("/rejected", handleAPIError(stories.HandleListRejected)) |
Member
There was a problem hiding this comment.
The filtering should be done via a query parameter, not separate routes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

source-academy/frontend#2928