🐛 Fix unable to list posts with realm id
This commit is contained in:
		@@ -39,7 +39,11 @@ func listPost(c *fiber.Ctx) error {
 | 
			
		||||
 | 
			
		||||
	tx := database.C
 | 
			
		||||
	if realmId > 0 {
 | 
			
		||||
		tx = services.FilterWithRealm(tx, uint(realmId))
 | 
			
		||||
		if realm, err := services.GetRealmWithExtID(uint(realmId)); err != nil {
 | 
			
		||||
			return fiber.NewError(fiber.StatusBadRequest, fmt.Sprintf("realm was not found: %v", err))
 | 
			
		||||
		} else {
 | 
			
		||||
			tx = services.FilterWithRealm(tx, realm.ID)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if len(c.Query("authorId")) > 0 {
 | 
			
		||||
 
 | 
			
		||||
@@ -55,6 +55,7 @@ func GetPostWithAlias(alias string, ignoreLimitation ...bool) (models.Post, erro
 | 
			
		||||
	var item models.Post
 | 
			
		||||
	if err := tx.
 | 
			
		||||
		Where("alias = ?", alias).
 | 
			
		||||
		Preload("Realm").
 | 
			
		||||
		Preload("Author").
 | 
			
		||||
		Preload("ReplyTo").
 | 
			
		||||
		Preload("ReplyTo.Author").
 | 
			
		||||
@@ -76,6 +77,7 @@ func GetPost(id uint, ignoreLimitation ...bool) (models.Post, error) {
 | 
			
		||||
	var item models.Post
 | 
			
		||||
	if err := tx.
 | 
			
		||||
		Where("id = ?", id).
 | 
			
		||||
		Preload("Realm").
 | 
			
		||||
		Preload("Author").
 | 
			
		||||
		Preload("ReplyTo").
 | 
			
		||||
		Preload("ReplyTo.Author").
 | 
			
		||||
@@ -151,6 +153,7 @@ func ListPost(tx *gorm.DB, take int, offset int, noReact ...bool) ([]*models.Pos
 | 
			
		||||
	if err := tx.
 | 
			
		||||
		Limit(take).Offset(offset).
 | 
			
		||||
		Order("created_at DESC").
 | 
			
		||||
		Preload("Realm").
 | 
			
		||||
		Preload("Author").
 | 
			
		||||
		Preload("ReplyTo").
 | 
			
		||||
		Preload("ReplyTo.Author").
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,21 @@ import (
 | 
			
		||||
	"reflect"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func GetRealmWithExtID(id uint) (models.Realm, error) {
 | 
			
		||||
	var realm models.Realm
 | 
			
		||||
	pc, err := gap.H.DiscoverServiceGRPC("Hydrogen.Passport")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return realm, err
 | 
			
		||||
	}
 | 
			
		||||
	response, err := proto.NewRealmsClient(pc).GetRealm(context.Background(), &proto.RealmLookupRequest{
 | 
			
		||||
		Id: lo.ToPtr(uint64(id)),
 | 
			
		||||
	})
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return realm, err
 | 
			
		||||
	}
 | 
			
		||||
	return LinkRealm(response)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetRealmWithAlias(alias string) (models.Realm, error) {
 | 
			
		||||
	var realm models.Realm
 | 
			
		||||
	pc, err := gap.H.DiscoverServiceGRPC("Hydrogen.Passport")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user