You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1021 B
44 lines
1021 B
package comments
|
|
|
|
import (
|
|
"time"
|
|
|
|
"git.aiterp.net/rpdata/api/models"
|
|
"github.com/globalsign/mgo/bson"
|
|
)
|
|
|
|
// Edit edits a comment.
|
|
func Edit(comment models.Comment, source, characterName, characterID, subject *string, fictionalDate *time.Time) (models.Comment, error) {
|
|
changes := make(bson.M, 6)
|
|
|
|
comment.EditedDate = time.Now()
|
|
changes["editedDate"] = comment.EditedDate
|
|
|
|
if source != nil {
|
|
comment.Source = *source
|
|
changes["source"] = *source
|
|
}
|
|
if characterName != nil {
|
|
comment.CharacterName = *characterName
|
|
changes["characterName"] = *characterName
|
|
}
|
|
if characterID != nil {
|
|
comment.CharacterID = *characterID
|
|
changes["characterId"] = *characterID
|
|
}
|
|
if subject != nil {
|
|
comment.Subject = *subject
|
|
changes["subject"] = *subject
|
|
}
|
|
if fictionalDate != nil {
|
|
comment.FictionalDate = *fictionalDate
|
|
changes["fictionalDate"] = *fictionalDate
|
|
}
|
|
|
|
err := collection.UpdateId(comment.ID, bson.M{"$set": changes})
|
|
if err != nil {
|
|
return models.Comment{}, err
|
|
}
|
|
|
|
return comment, nil
|
|
}
|