Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions api/swagger/swagger-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,13 @@ paths:
required: true
schema:
type: string
requestBody:
required: false
x-codegen-request-body-name: metadata
content:
application/json:
schema:
$ref: "#/components/schemas/favorite_request_body"
responses:
"200":
description: Playlist favorited successfully
Expand Down Expand Up @@ -2922,6 +2929,13 @@ paths:
required: true
schema:
type: string
requestBody:
required: false
x-codegen-request-body-name: metadata
content:
application/json:
schema:
$ref: "#/components/schemas/favorite_request_body"
responses:
"200":
description: Track favorited successfully
Expand Down Expand Up @@ -10532,6 +10546,13 @@ components:
type: integer
description: ID of the entity (track) being commented on
example: 12345
favorite_request_body:
type: object
description: Optional metadata for favorite/save operations
properties:
is_save_of_repost:
type: boolean
description: Set to true when favoriting a reposted item (used for notifications)
pin_comment_request_body:
type: object
required:
Expand Down
16 changes: 15 additions & 1 deletion api/v1_playlist_favorites.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"encoding/json"
"strconv"
"time"

Expand All @@ -13,6 +14,10 @@ import (
"go.uber.org/zap"
)

type favoriteRequestBody struct {
IsSaveOfRepost *bool `json:"is_save_of_repost"`
}

func (app *ApiServer) v1PlaylistFavorites(c *fiber.Ctx) error {
sql := `
SELECT user_id
Expand Down Expand Up @@ -50,6 +55,15 @@ func (app *ApiServer) postV1PlaylistFavorite(c *fiber.Ctx) error {
return err
}

metadata := ""
if body := c.Body(); len(body) > 0 {
var reqBody favoriteRequestBody
if err := json.Unmarshal(body, &reqBody); err == nil && reqBody.IsSaveOfRepost != nil {
metadataBytes, _ := json.Marshal(map[string]bool{"is_save_of_repost": *reqBody.IsSaveOfRepost})
metadata = string(metadataBytes)
}
}

nonce := time.Now().UnixNano()

manageEntityTx := &corev1.ManageEntityLegacy{
Expand All @@ -59,7 +73,7 @@ func (app *ApiServer) postV1PlaylistFavorite(c *fiber.Ctx) error {
Action: indexer.Action_Save,
EntityType: indexer.Entity_Playlist,
Nonce: strconv.FormatInt(nonce, 10),
Metadata: "",
Metadata: metadata,
}

response, err := app.sendTransactionWithSigner(manageEntityTx, signer.PrivateKey)
Expand Down
14 changes: 13 additions & 1 deletion api/v1_track_favorites.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"encoding/json"
"strconv"
"time"

Expand Down Expand Up @@ -50,6 +51,17 @@ func (app *ApiServer) postV1TrackFavorite(c *fiber.Ctx) error {
return err
}

metadata := ""
if body := c.Body(); len(body) > 0 {
var reqBody struct {
IsSaveOfRepost *bool `json:"is_save_of_repost"`
}
if err := json.Unmarshal(body, &reqBody); err == nil && reqBody.IsSaveOfRepost != nil {
metadataBytes, _ := json.Marshal(map[string]bool{"is_save_of_repost": *reqBody.IsSaveOfRepost})
metadata = string(metadataBytes)
}
}

nonce := time.Now().UnixNano()

manageEntityTx := &corev1.ManageEntityLegacy{
Expand All @@ -59,7 +71,7 @@ func (app *ApiServer) postV1TrackFavorite(c *fiber.Ctx) error {
Action: indexer.Action_Save,
EntityType: indexer.Entity_Track,
Nonce: strconv.FormatInt(nonce, 10),
Metadata: "",
Metadata: metadata,
}

response, err := app.sendTransactionWithSigner(manageEntityTx, signer.PrivateKey)
Expand Down