Example #1
0
func (f ItemFacade) UpdateItemImpressionView(itemID uint64) error {
	itemImpressionService := services.NewItemImpressionService(f.ctx)
	itemImp, err := itemImpressionService.GetItemImpressionByID(itemID)
	if err != nil {
		return err
	}
	itemImp.View = itemImp.View + 1
	return itemImpressionService.UpdateItemImpressionByID(itemImp)
}
Example #2
0
func (f ItemFacade) FindItemImpressionMap(itemIDs []uint64) (map[uint64]models.ItemImpression, error) {
	itemImpressionService := services.NewItemImpressionService(f.ctx)
	impressions, err := itemImpressionService.FindItemImpressionByIDs(itemIDs)
	if err != nil {
		return nil, err
	}
	res := make(map[uint64]models.ItemImpression, len(impressions))
	for _, impression := range impressions {
		res[impression.ItemID] = impression
	}
	return res, nil
}
Example #3
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
}