Forum Discussion

omygoodness's avatar
8 years ago

My kudoed posts REST

I am looking for api call that will replace query:

SELECT * FROM kudos WHERE user.id = '3'

What I need is same rest call that is used at default lithium page:

kudos/userpage/user-id/3/tab/messages-kudoed-by-user

  • Hi omygoodness,

     

    The query you need is 

    SELECT * FROM messages WHERE author.id = '3' AND kudos.sum(weight) >0

    It will give you all messages authored by user which have recieved kudos

  • When I was waiting for help on community I came up with query:

    SELECT * FROM messages WHERE kudos.sum(weight) > 0 AND author.id='${viewed_user_id}' ORDER BY kudos.sum(weight) DESC

    Anyway. jferrandis Thank you for answer.

3 Replies

  • Hi omygoodness,

     

    The query you need is 

    SELECT * FROM messages WHERE author.id = '3' AND kudos.sum(weight) >0

    It will give you all messages authored by user which have recieved kudos

  • omygoodness's avatar
    omygoodness
    Mentor
    8 years ago

    When I was waiting for help on community I came up with query:

    SELECT * FROM messages WHERE kudos.sum(weight) > 0 AND author.id='${viewed_user_id}' ORDER BY kudos.sum(weight) DESC

    Anyway. jferrandis Thank you for answer.

  • jferrandis's avatar
    jferrandis
    Expert
    8 years ago

    I edited my former message with the correct query.

     

    An addition, to handle a "message i kudoed" custom component, you will have to make 2 queries

     

    Get the message the user has kudoed

    SELECT * FROM kudos WHERE user.id='3'

    Then, you will have to parse it to get message details

    <#if myQueryResult.data.status == "success" && myQueryResult.data.size gt 0 >
    <#list myQueryResult.data.items as message>
    <#assign messageDetailQuery = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE id=${message.message.id}'"?url) />
    <#if messageDetailQuery.data.status == "success" && messageDetailQuery.data.size gt 0 >
    ... make you own ui ...
    </#if>
    </#list>