✨ Create post with realm
This commit is contained in:
		| @@ -1,6 +1,7 @@ | ||||
| package api | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| 	"time" | ||||
|  | ||||
| @@ -41,6 +42,7 @@ func createArticle(c *fiber.Ctx) error { | ||||
| 		InvisibleUsers []uint            `json:"invisible_users_list"` | ||||
| 		Visibility     *int8             `json:"visibility"` | ||||
| 		IsDraft        bool              `json:"is_draft"` | ||||
| 		Realm          *uint             `json:"realm"` | ||||
| 	} | ||||
|  | ||||
| 	if err := exts.BindAndValidate(c, &data); err != nil { | ||||
| @@ -83,6 +85,13 @@ func createArticle(c *fiber.Ctx) error { | ||||
| 		item.PublishedAt = lo.ToPtr(time.Now()) | ||||
| 	} | ||||
|  | ||||
| 	if data.Realm != nil { | ||||
| 		if _, err := authkit.GetRealmMember(gap.Nx, *data.Realm, user.ID); err != nil { | ||||
| 			return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("you are not a member of realm #%d", *data.Realm)) | ||||
| 		} | ||||
| 		item.RealmID = data.Realm | ||||
| 	} | ||||
|  | ||||
| 	if data.Visibility != nil { | ||||
| 		item.Visibility = *data.Visibility | ||||
| 	} else { | ||||
|   | ||||
| @@ -43,6 +43,7 @@ func createQuestion(c *fiber.Ctx) error { | ||||
| 		InvisibleUsers []uint            `json:"invisible_users_list"` | ||||
| 		Visibility     *int8             `json:"visibility"` | ||||
| 		IsDraft        bool              `json:"is_draft"` | ||||
| 		Realm          *uint             `json:"realm"` | ||||
| 		Reward         float64           `json:"reward"` | ||||
| 	} | ||||
|  | ||||
| @@ -109,6 +110,13 @@ func createQuestion(c *fiber.Ctx) error { | ||||
| 		item.PublishedAt = lo.ToPtr(time.Now()) | ||||
| 	} | ||||
|  | ||||
| 	if data.Realm != nil { | ||||
| 		if _, err := authkit.GetRealmMember(gap.Nx, *data.Realm, user.ID); err != nil { | ||||
| 			return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("you are not a member of realm #%d", *data.Realm)) | ||||
| 		} | ||||
| 		item.RealmID = data.Realm | ||||
| 	} | ||||
|  | ||||
| 	if data.Visibility != nil { | ||||
| 		item.Visibility = *data.Visibility | ||||
| 	} else { | ||||
|   | ||||
| @@ -45,6 +45,7 @@ func createStory(c *fiber.Ctx) error { | ||||
| 		ReplyTo        *uint             `json:"reply_to"` | ||||
| 		RepostTo       *uint             `json:"repost_to"` | ||||
| 		Poll           *uint             `json:"poll"` | ||||
| 		Realm          *uint             `json:"realm"` | ||||
| 	} | ||||
|  | ||||
| 	if err := exts.BindAndValidate(c, &data); err != nil { | ||||
| @@ -96,6 +97,13 @@ func createStory(c *fiber.Ctx) error { | ||||
| 		item.Visibility = models.PostVisibilityAll | ||||
| 	} | ||||
|  | ||||
| 	if data.Realm != nil { | ||||
| 		if _, err := authkit.GetRealmMember(gap.Nx, *data.Realm, user.ID); err != nil { | ||||
| 			return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("you are not a member of realm #%d", *data.Realm)) | ||||
| 		} | ||||
| 		item.RealmID = data.Realm | ||||
| 	} | ||||
|  | ||||
| 	if data.ReplyTo != nil { | ||||
| 		var replyTo models.Post | ||||
| 		if err := database.C.Where("id = ?", data.ReplyTo).First(&replyTo).Error; err != nil { | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package api | ||||
|  | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"strconv" | ||||
| 	"time" | ||||
|  | ||||
| @@ -41,6 +42,7 @@ func createVideo(c *fiber.Ctx) error { | ||||
| 		InvisibleUsers []uint            `json:"invisible_users_list"` | ||||
| 		Visibility     *int8             `json:"visibility"` | ||||
| 		IsDraft        bool              `json:"is_draft"` | ||||
| 		Realm          *uint             `json:"realm"` | ||||
| 	} | ||||
|  | ||||
| 	if err := exts.BindAndValidate(c, &data); err != nil { | ||||
| @@ -84,6 +86,13 @@ func createVideo(c *fiber.Ctx) error { | ||||
| 		item.PublishedAt = lo.ToPtr(time.Now()) | ||||
| 	} | ||||
|  | ||||
| 	if data.Realm != nil { | ||||
| 		if _, err := authkit.GetRealmMember(gap.Nx, *data.Realm, user.ID); err != nil { | ||||
| 			return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("you are not a member of realm #%d", *data.Realm)) | ||||
| 		} | ||||
| 		item.RealmID = data.Realm | ||||
| 	} | ||||
|  | ||||
| 	if data.Visibility != nil { | ||||
| 		item.Visibility = *data.Visibility | ||||
| 	} else { | ||||
|   | ||||
| @@ -32,8 +32,8 @@ type Post struct { | ||||
| 	Type        string            `json:"type"` | ||||
| 	Body        datatypes.JSONMap `json:"body" gorm:"index:,type:gin"` | ||||
| 	Language    string            `json:"language"` | ||||
| 	Alias       *string           `json:"alias"` | ||||
| 	AliasPrefix *string           `json:"alias_prefix"` | ||||
| 	Alias       *string           `json:"alias" gorm:"index"` | ||||
| 	AliasPrefix *string           `json:"alias_prefix" gorm:"index"` | ||||
| 	Tags        []Tag             `json:"tags" gorm:"many2many:post_tags"` | ||||
| 	Categories  []Category        `json:"categories" gorm:"many2many:post_categories"` | ||||
| 	Reactions   []Reaction        `json:"reactions"` | ||||
|   | ||||
		Reference in New Issue
	
	Block a user