本文整理汇总了Golang中socialapi/request.Query.Type方法的典型用法代码示例。如果您正苦于以下问题:Golang Query.Type方法的具体用法?Golang Query.Type怎么用?Golang Query.Type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类socialapi/request.Query
的用法示例。
在下文中一共展示了Query.Type方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ByName
// ByName fetches the channel by name, type_constant and group_name, it doesnt
// have the best name, but evolved to this situation :/
func (c *Channel) ByName(q *request.Query) (Channel, error) {
var channel Channel
if q.GroupName == "" {
return channel, ErrGroupNameIsNotSet
}
if q.Type == "" {
q.Type = Channel_TYPE_TOPIC
}
query := &bongo.Query{
Selector: map[string]interface{}{
"group_name": q.GroupName,
"type_constant": q.Type,
"name": q.Name,
},
Pagination: *bongo.NewPagination(q.Limit, q.Skip),
}
query.AddScope(RemoveTrollContent(c, q.ShowExempt))
err := c.One(query)
if err != nil && err != bongo.RecordNotFound {
return channel, err
}
return *c, nil
}
示例2: BySlug
// BySlug fetchs channel message by its slug
// checks if message is in the channel or not
func (c *ChannelMessage) BySlug(query *request.Query) error {
if query.Slug == "" {
return ErrSlugIsNotSet
}
// fetch message itself
q := &bongo.Query{
Selector: map[string]interface{}{
"slug": query.Slug,
},
}
q.AddScope(RemoveTrollContent(
c, query.ShowExempt,
))
if err := c.One(q); err != nil {
return err
}
query.Type = Channel_TYPE_GROUP
res, err := c.isInChannel(query, "public")
if err != nil {
return err
}
if res {
return nil
}
query.Type = Channel_TYPE_ANNOUNCEMENT
res, err = c.isInChannel(query, "changelog")
if err != nil {
return err
}
if !res {
return bongo.RecordNotFound
}
return nil
}
示例3: ByParticipants
// ByParticipants fetches the channels by their respective participants
func (c *Channel) ByParticipants(participants []int64, q *request.Query) ([]Channel, error) {
if q.GroupName == "" {
return nil, ErrGroupNameIsNotSet
}
if len(participants) == 0 {
return nil, ErrChannelParticipantIsNotSet
}
if q.Type == "" {
q.Type = Channel_TYPE_PRIVATE_MESSAGE
}
var channelIds []int64
cp := NewChannelParticipant()
err := bongo.B.DB.
Model(cp).
Table(cp.BongoName()).
Joins(
`left join api.channel on
api.channel_participant.channel_id = api.channel.id`).
Where(
`api.channel_participant.account_id IN ( ? ) and
api.channel_participant.status_constant = ? and
api.channel.group_name = ? and
api.channel.deleted_at < '0001-01-02 00:00:00+00' and
api.channel.type_constant = ?`,
participants,
ChannelParticipant_STATUS_ACTIVE,
q.GroupName,
q.Type,
).
Group("channel_participant.channel_id, channel.created_at").
Having("COUNT (channel_participant.channel_id) = ?", len(participants)).
Order("channel.created_at").
Limit(q.Limit).
Offset(q.Skip).
Pluck("api.channel_participant.channel_id", &channelIds).Error
if err != nil {
return nil, err
}
return c.FetchByIds(channelIds)
}
示例4: getUserChannelsQuery
func getUserChannelsQuery(q *request.Query) *gorm.DB {
c := models.NewChannel()
if q.Type == "" {
q.Type = models.Channel_TYPE_PRIVATE_MESSAGE
}
return bongo.B.DB.
Model(c).
Table(c.BongoName()).
Select("api.channel_participant.channel_id").
Joins("left join api.channel_participant on api.channel_participant.channel_id = api.channel.id").
Where("api.channel_participant.account_id = ? and "+
"api.channel.group_name = ? and "+
"api.channel.type_constant = ? and "+
"api.channel_participant.status_constant = ?",
q.AccountId,
q.GroupName,
q.Type,
models.ChannelParticipant_STATUS_ACTIVE)
}
示例5: Search
func (c *Channel) Search(q *request.Query) ([]Channel, error) {
if q.GroupName == "" {
return nil, ErrGroupNameIsNotSet
}
if q.Type == "" {
q.Type = Channel_TYPE_TOPIC
}
var channels []Channel
bongoQuery := &bongo.Query{
Selector: map[string]interface{}{
"group_name": q.GroupName,
"type_constant": q.Type,
},
Pagination: *bongo.NewPagination(q.Limit, q.Skip),
}
bongoQuery.AddScope(RemoveTrollContent(c, q.ShowExempt))
query := bongo.B.BuildQuery(c, bongoQuery)
// use 'ilike' for case-insensitive search
query = query.Where("name ilike ?", "%"+q.Name+"%")
if err := bongo.CheckErr(
query.Find(&channels),
); err != nil {
return nil, err
}
if channels == nil {
return make([]Channel, 0), nil
}
return channels, nil
}