Skip to content

Fix miscellaneous stories bugs #103

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

Merged
merged 3 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion controller/stories/stories.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ func HandleCreate(w http.ResponseWriter, r *http.Request) error {
}
}

storyModel := *params.ToModel()
// Get group id from context
groupID, err := usergroups.GetGroupIDFrom(r)
if err != nil {
logrus.Error(err)
return err
}

storyModel := *params.ToModel(groupID)

// Get DB instance
db, err := database.GetDBFrom(r)
Expand Down
2 changes: 1 addition & 1 deletion deployment/backups.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ NEW_BACKUP_FILENAME="pgdump_`date +%Y%m%d-%H%M%S`.sql"
BACKUP_FILE_PATH="$BACKUP_DIR/$NEW_BACKUP_FILENAME"

BACKUP_COMMAND="'pg_dumpall -c -h \$PG_HOST -U \$PG_USER'"
SQL_DUMP="$(docker compose -f "$COMPOSE_FILE_PATH" run --rm -it --entrypoint "bash -c $BACKUP_COMMAND" migrator)"
SQL_DUMP="$(sudo docker compose -f "$COMPOSE_FILE_PATH" run --rm -it --entrypoint "bash -c $BACKUP_COMMAND" migrator)"

if [[ -z "$LAST_BACKUP_FILENAME" ]]; then
echo "No previous backups found, creating new backup..."
Expand Down
5 changes: 4 additions & 1 deletion model/coursegroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ func GetGroupByCourseID(db *gorm.DB, courseID int) (Group, error) {
courseGroup := CourseGroup{
CourseID: uint(courseID),
}
err := db.Preload(clause.Associations).First(&courseGroup).Error
err := db.
Preload(clause.Associations).
Where(&courseGroup).
First(&courseGroup).Error
if err != nil {
return courseGroup.Group, database.HandleDBError(err, "courseGroup")
}
Expand Down
3 changes: 2 additions & 1 deletion params/stories/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ func (params *Create) Validate() error {
return nil
}

func (params *Create) ToModel() *model.Story {
func (params *Create) ToModel(associatedGroupID *uint) *model.Story {
return &model.Story{
AuthorID: params.AuthorID,
GroupID: associatedGroupID,
Title: params.Title,
Content: params.Content,
PinOrder: params.PinOrder,
Expand Down
2 changes: 1 addition & 1 deletion params/stories/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestToModel(t *testing.T) {
AuthorID: 1,
Content: "# Hi\n\nThis is a test story.",
}
model := params.ToModel()
model := params.ToModel(nil)
assert.Equal(t, params.AuthorID, model.AuthorID)
assert.Equal(t, params.Content, model.Content)
})
Expand Down