[-] Fixup PR 1309 (usermark)

This commit is contained in:
ejurgensen 2021-09-17 22:58:21 +02:00
parent 45c5f0b347
commit 6692411040
3 changed files with 18 additions and 19 deletions

View File

@ -791,7 +791,7 @@ curl -X PUT "http://localhost:3689/api/queue/items/2"
| GET | [/api/library/albums/{id}/tracks](#list-album-tracks) | Get list of tracks for an album |
| GET | [/api/library/tracks/{id}](#get-a-track) | Get a track |
| GET | [/api/library/tracks/{id}/playlists](#list-playlists-for-a-track) | Get list of playlists for a track |
| PUT | [/api/library/tracks/{id}](#update-track-properties) | Update a tracks properties (rating, play_count,usermark) |
| PUT | [/api/library/tracks/{id}](#update-track-properties) | Update track properties |
| GET | [/api/library/genres](#list-genres) | Get list of genres |
| GET | [/api/library/count](#get-count-of-tracks-artists-and-albums) | Get count of tracks, artists and albums |
| GET | [/api/library/files](#list-local-directories) | Get list of directories in the local library |

View File

@ -143,11 +143,11 @@ db_data_kind_label(enum data_kind data_kind);
/* Indicates user marked status on a track - values can be bitwise enumerated */
enum user_mark {
USER_MARK_NA = 0,
USER_MARK_DELETE = 1,
USER_MARK_REXCODE = 2,
USER_MARK_REVIEW = 4
enum usermark {
USERMARK_NA = 0,
USERMARK_DELETE = 1,
USERMARK_REXCODE = 2,
USERMARK_REVIEW = 4,
};

View File

@ -3305,7 +3305,6 @@ jsonapi_reply_library_tracks_put_byid(struct httpd_request *hreq)
if (ret < 0)
return HTTP_INTERNAL;
// Update play_count/skip_count
param = evhttp_find_header(hreq->query, "play_count");
if (param)
{
@ -3320,37 +3319,37 @@ jsonapi_reply_library_tracks_put_byid(struct httpd_request *hreq)
else
{
DPRINTF(E_WARN, L_WEB, "Ignoring invalid play_count value '%s' for track '%d'.\n", param, track_id);
return HTTP_BADREQUEST;
}
}
// Update rating
param = evhttp_find_header(hreq->query, "rating");
if (param)
{
ret = safe_atou32(param, &val);
if (ret < 0)
return HTTP_BADREQUEST;
if (val >= 0 && val <= DB_FILES_RATING_MAX)
ret = db_file_rating_update_byid(track_id, val);
else
DPRINTF(E_WARN, L_WEB, "Ignoring invalid rating value '%d' for track '%d'.\n", val, track_id);
if (ret < 0 || val > DB_FILES_RATING_MAX)
{
DPRINTF(E_WARN, L_WEB, "Invalid rating value '%s' for track '%d'.\n", param, track_id);
return HTTP_BADREQUEST;
}
ret = db_file_rating_update_byid(track_id, val);
if (ret < 0)
return HTTP_INTERNAL;
}
// Update usermark
// retreive via "/api/search?type=tracks&expression=usermark+=+1"
// Retreive marked tracks via "/api/search?type=tracks&expression=usermark+=+1"
param = evhttp_find_header(hreq->query, "usermark");
if (param)
{
ret = safe_atou32(param, &val);
if (ret < 0)
return HTTP_BADREQUEST;
{
DPRINTF(E_WARN, L_WEB, "Invalid usermark value '%s' for track '%d'.\n", param, track_id);
return HTTP_BADREQUEST;
}
ret = db_file_usermark_update_byid(track_id, val);
if (ret < 0)
return HTTP_INTERNAL;
}