示例#1
0
func (f ItemFacade) FindItemTagIDsMap(itemIDs []uint64) (map[uint64][]uint64, error) {
	itemTagService := services.NewItemTagService(f.ctx)
	itemTags, err := itemTagService.FindItemTagByIDs(itemIDs)
	if err != nil {
		return nil, err
	}
	res := make(map[uint64][]uint64, len(itemTags))
	for _, itemTag := range itemTags {
		res[itemTag.ItemID] = append(res[itemTag.ItemID], itemTag.TagID)
	}
	return res, nil
}
示例#2
0
func (f ItemFacade) CreateItem(userID uint64, githubURL string) (item *models.Item, err error) {

	item = models.NewItem(userID, githubURL)

	// Get github info
	var github *models.Github
	githubService := services.NewGithubService()
	if github, err = githubService.GetGithub(githubURL); err != nil {
		return nil, err
	}

	{
		// Item
		itemService := services.NewItemService(f.ctx)
		item.Author = github.Author
		item.Name = github.Name
		item.Description = github.Description
		if item, err = itemService.CreateItem(item); err != nil {
			log.New("CreateItem::ItemService").Error()
			return nil, err
		}
	}

	{
		// Star
		itemImpressionService := services.NewItemImpressionService(f.ctx)
		if _, err = itemImpressionService.CreateItemImpression(item.ID, uint(github.Star)); err != nil {
			log.New("CreateItemImpression::ItemImpressionService").Error()
			return nil, err
		}
	}

	{
		// Tag
		var tags []models.Tag
		tagService := services.NewTagService(f.ctx)
		if tags, err = tagService.FindTagByNames(github.Languages); err != nil {
			log.New("FindTagByNames::TagService").Error()
			return nil, err
		}

		itemTagService := services.NewItemTagService(f.ctx)
		for _, tag := range tags {
			if _, err = itemTagService.CreateItemTag(item.ID, tag.ID); err != nil {
				log.New("CreateItemTag::ItemTagService").Error()
				return nil, err
			}
		}
	}

	return
}
示例#3
0
func (f ItemFacade) FindLatestItemByTagID(tagID uint64, limit int) ([]models.Item, error) {
	itemTagService := services.NewItemTagService(f.ctx)
	itemTags, err := itemTagService.FindLatestItemTagByCollection(tagID, limit)
	if err != nil {
		return nil, err
	}
	itemIDs := make([]uint64, len(itemTags))
	for i, itemTag := range itemTags {
		itemIDs[i] = itemTag.ItemID
	}
	itemService := services.NewItemService(f.ctx)
	return itemService.FindItemByIDs(itemIDs)
}