Ejemplo n.º 1
0
func (c *APIMeController) LoginMe() {
	//// Apply Request Parameters
	param := parameters.NewLoginMeRequest()
	if ok := c.API().Preprocess(&param); !ok {
		return
	}

	//// Call a facade
	meFacade := facades.NewMeFacade(c.GetContext())
	me, err := meFacade.LoginMe(param.Name, param.AvatarURL, param.Location)
	if err != nil {
		c.API().InternalServerError(map[string]interface{}{
			"status":  "NG",
			"func":    "LoginMe::MeFacade",
			"message": err,
		})
		return
	}

	// Render result
	c.API().OK(map[string]interface{}{
		"status":   "OK",
		"instance": me,
	})
}
Ejemplo n.º 2
0
func (c *APIItemController) GetItemFavoriteList() {
	//// Apply Request Parameters
	param := parameters.NewGetItemFavoriteListRequest()
	if ok := c.API().Preprocess(&param); !ok {
		return
	}

	meFacade := facades.NewMeFacade(c.GetContext())
	me, err := meFacade.GetMe(param.GetAccessToken())
	if err != nil {
		c.API().InternalServerError(map[string]interface{}{
			"status":  "NG",
			"func":    "GetMe::MeFacade",
			"message": err,
		})
		return
	}

	//// Call a facade
	itemFacade := facades.NewItemFacade(c.GetContext())
	items, err := itemFacade.FindFavoriteItem(me.ID, param.Limit)
	if err != nil {
		c.API().InternalServerError(map[string]interface{}{
			"status":  "NG",
			"func":    "FindFavoriteItem::ItemFacade",
			"message": err,
		})
		return
	}

	itemResponseList, err := c.ConvertItems(items)
	if err != nil {
		c.API().InternalServerError(map[string]interface{}{
			"status":  "NG",
			"func":    "ConvertItems::ItemController",
			"message": err,
		})
		return
	}

	// Render result
	c.API().OK(map[string]interface{}{
		"status":    "OK",
		"instances": itemResponseList,
	})
}
Ejemplo n.º 3
0
func (c *APIItemController) CreateItemFavorite(id string) {
	//// Apply Request Parameters
	param := parameters.NewCreateItemFavoriteRequest()
	if ok := c.API().Preprocess(&param); !ok {
		return
	}

	// Parse string id to uint64
	uint64ID := c.ParseUint64(id)
	if uint64ID <= 0 {
		return
	}

	meFacade := facades.NewMeFacade(c.GetContext())
	me, err := meFacade.GetMe(param.GetAccessToken())
	if err != nil {
		c.API().InternalServerError(map[string]interface{}{
			"status":  "NG",
			"func":    "GetMe::MeFacade",
			"message": err,
		})
		return
	}

	//// Call a facade
	itemFacade := facades.NewItemFacade(c.GetContext())
	item, err := itemFacade.CreateFavoriteItem(me.ID, uint64ID)
	if err != nil {
		c.API().InternalServerError(map[string]interface{}{
			"status":  "NG",
			"func":    "CreateFavoriteItem::ItemFacade",
			"message": err,
		})
		return
	}

	go c.scoring(me.ID, item.ID)

	// Render result
	c.API().OK(map[string]interface{}{
		"status":   "OK",
		"instance": item,
	})
}
Ejemplo n.º 4
0
func (c *APITagController) GetTagList() {
	//// Apply Request Parameters
	param := parameters.NewGetTagListRequest()
	if ok := c.API().Preprocess(&param); !ok {
		return
	}

	tags, err := func() ([]models.Tag, error) {
		//// Call a facade
		tagFacade := facades.NewTagFacade(c.GetContext())
		meFacade := facades.NewMeFacade(c.GetContext())
		me, _ := meFacade.GetMe(param.GetAccessToken())
		if me != nil {
			const scoreCountThreshold = 3
			tags, _ := tagFacade.FindTagByScore(me.ID, param.Limit)
			counter := 0
			for _, tag := range tags {
				if tag.Score > 5 {
					counter++
				}
			}
			if scoreCountThreshold >= counter {
				return tags, nil
			}
		}
		return tagFacade.FindPopularTag(param.Limit)
	}()
	if err != nil {
		c.API().InternalServerError(map[string]interface{}{
			"status":  "NG",
			"func":    "FindPopularTag::TagFacade",
			"message": err,
		})
		return
	}
	// Render result
	c.API().OK(map[string]interface{}{
		"status":    "OK",
		"instances": tags,
	})
}