29 lines
623 B
Go
29 lines
623 B
Go
package globalrules
|
|
|
|
import (
|
|
"context"
|
|
db_repo "enshi/db/go_queries"
|
|
"enshi/db_connection"
|
|
"enshi/middleware/getters"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func IsOwnerOfTheCommentRule(c *gin.Context) (bool, []error) {
|
|
commentId, err := getters.GetInt64Param(c, "comment-id")
|
|
if err != nil {
|
|
return false, []error{err}
|
|
}
|
|
|
|
contextUserId, err := getters.GetUserIdFromContext(c)
|
|
if err != nil {
|
|
return false, []error{err}
|
|
}
|
|
|
|
comment, err := db_repo.New(db_connection.Dbx).GetCommentById(context.Background(), commentId)
|
|
if err != nil {
|
|
return false, []error{err}
|
|
}
|
|
return contextUserId == comment.UserID, nil
|
|
}
|