✨ Able to get feed full content
This commit is contained in:
		
							
								
								
									
										41
									
								
								pkg/internal/server/api/feed_items_api.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								pkg/internal/server/api/feed_items_api.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| package api | ||||
|  | ||||
| import ( | ||||
| 	"git.solsynth.dev/hypernet/reader/pkg/internal/database" | ||||
| 	"git.solsynth.dev/hypernet/reader/pkg/internal/models" | ||||
| 	"github.com/gofiber/fiber/v2" | ||||
| ) | ||||
|  | ||||
| func listFeedItem(c *fiber.Ctx) error { | ||||
| 	take := c.QueryInt("take", 10) | ||||
| 	offset := c.QueryInt("offset", 0) | ||||
|  | ||||
| 	var count int64 | ||||
| 	if err := database.C.Model(&models.SubscriptionItem{}).Count(&count).Error; err != nil { | ||||
| 		return fiber.NewError(fiber.StatusBadRequest, err.Error()) | ||||
| 	} | ||||
|  | ||||
| 	var items []models.SubscriptionItem | ||||
| 	if err := database.C. | ||||
| 		Order("published_at DESC"). | ||||
| 		Omit("Content"). | ||||
| 		Limit(take).Offset(offset).Find(&items).Error; err != nil { | ||||
| 		return fiber.NewError(fiber.StatusBadRequest, err.Error()) | ||||
| 	} | ||||
|  | ||||
| 	return c.JSON(fiber.Map{ | ||||
| 		"count": count, | ||||
| 		"data":  items, | ||||
| 	}) | ||||
| } | ||||
|  | ||||
| func getFeedItem(c *fiber.Ctx) error { | ||||
| 	id, _ := c.ParamsInt("id", 0) | ||||
|  | ||||
| 	var item models.SubscriptionItem | ||||
| 	if err := database.C.Where("id = ?", id).First(&item).Error; err != nil { | ||||
| 		return fiber.NewError(fiber.StatusNotFound, err.Error()) | ||||
| 	} | ||||
|  | ||||
| 	return c.JSON(item) | ||||
| } | ||||
| @@ -17,6 +17,9 @@ func MapAPIs(app *fiber.App, baseURL string) { | ||||
|  | ||||
| 		subscription := api.Group("/subscriptions").Name("Subscriptions") | ||||
| 		{ | ||||
| 			subscription.Get("/", listFeedItem) | ||||
| 			subscription.Get("/:id", getFeedItem) | ||||
|  | ||||
| 			feed := subscription.Group("/feed").Name("Feed") | ||||
| 			{ | ||||
| 				feed.Get("/", listFeedSubscriptions) | ||||
|   | ||||
| @@ -10,6 +10,7 @@ func GetTodayFeedRandomly(limit int) ([]models.SubscriptionItem, error) { | ||||
| 	if err := database.C.Limit(limit). | ||||
| 		Where("DATE(created_at) = CURRENT_DATE"). // Created in today | ||||
| 		Order("RANDOM()"). | ||||
| 		Omit("Content"). | ||||
| 		Find(&articles).Error; err != nil { | ||||
| 		return articles, err | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user