Skip to content

Commit b1970b1

Browse files
committed
comment indexer
1 parent fb6abab commit b1970b1

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

indexer/index_comment.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package indexer
2+
3+
import (
4+
"encoding/json"
5+
6+
"github.com/AudiusProject/audiusd/pkg/core/gen/core_proto"
7+
"github.com/jackc/pgx/v5"
8+
)
9+
10+
func (ci *CoreIndexer) createComment(txInfo TxInfo, em *core_proto.ManageEntityLegacy) error {
11+
var metadata GenericMetadata
12+
if err := json.Unmarshal([]byte(em.Metadata), &metadata); err != nil {
13+
return err
14+
}
15+
16+
args := pgx.NamedArgs{
17+
"comment_id": metadata.Data["comment_id"],
18+
"user_id": em.UserId,
19+
"text": metadata.Data["body"],
20+
"entity_type": "track",
21+
"entity_id": metadata.Data["track_id"],
22+
23+
"txhash": txInfo.txhash,
24+
"blockhash": txInfo.blockhash,
25+
"blocknumber": txInfo.blocknumber,
26+
}
27+
28+
return ci.doInsert("comments", args)
29+
}

indexer/indexer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ func (ci *CoreIndexer) handleTx(signedTx *core_proto.SignedTransaction) error {
8282
case "UpdatePlaylist":
8383
err = ci.updatePlaylist(txInfo, em)
8484

85+
case "CreateComment":
86+
err = ci.createComment(txInfo, em)
87+
8588
case "FollowUser":
8689
err = ci.followUser(txInfo, em)
8790
case "UnfollowUser":

indexer/indexer_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func TestMain(m *testing.M) {
5252
alter table saves drop constraint saves_blocknumber_fkey;
5353
alter table notification_seen drop constraint notification_seen_blocknumber_fkey;
5454
alter table track_downloads drop constraint track_downloads_blocknumber_fkey;
55+
alter table comments drop constraint comments_blocknumber_fkey;
5556
`)
5657
checkErr(err)
5758

0 commit comments

Comments
 (0)