[mb-commits] branch, mbs-5726, created. MBS-5726, implement /ws/2/discid for json webservice.

MusicBrainz Git Server <[email protected]> Tue, 15 Jan 2013 12:52:25 +0000
Newsgroups gmane.comp.audio.musicbrainz.cvs
Message-ID <E1Tv608-0004mn-W9@wiley>
The branch, mbs-5726 has been created
        at  a5936d6e245b632d4337f2a354dea1aec0adfe3a (commit)

- Log -----------------------------------------------------------------
commit a5936d6e245b632d4337f2a354dea1aec0adfe3a
Author: warp <[email protected]>
Date:   Tue Jan 15 13:41:03 2013 +0100

    MBS-5726, implement /ws/2/discid for json webservice.

diff --git a/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/CDTOC.pm b/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/CDTOC.pm
new file mode 100644
index 0000000..a804bc0
--- /dev/null
+++ b/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/CDTOC.pm
@@ -0,0 +1,46 @@
+package MusicBrainz::Server::WebService::Serializer::JSON::2::CDTOC;
+use Moose;
+use MusicBrainz::Server::WebService::Serializer::JSON::2::Utils qw( list_of number );
+
+extends 'MusicBrainz::Server::WebService::Serializer::JSON::2';
+
+sub serialize
+{
+    my ($self, $entity, $inc, $stash, $toplevel) = @_;
+    my %body;
+
+    $body{id} = $entity->discid;
+    $body{sectors} = number ($entity->leadout_offset);
+
+    if ($toplevel)
+    {
+        $body{releases} = list_of ($entity, $inc, $stash, "releases");
+    }
+
+    return \%body;
+};
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+1;
+
+# =head1 COPYRIGHT
+
+# Copyright (C) 2013 MetaBrainz Foundation
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+# =cut
+
diff --git a/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Medium.pm b/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Medium.pm
index b7f6ee3..24754c0 100644
--- a/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Medium.pm
+++ b/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Medium.pm
@@ -14,11 +14,14 @@ sub serialize
     $body{title} = $entity->name;
     $body{format} = $entity->format ? $entity->format->name : JSON::null;
 
-    $body{discids} = [ map +{
-        id => $_->cdtoc->discid,
-        sectors => number ($_->cdtoc->leadout_offset)
-    }, sort_by { $_->cdtoc->discid } $entity->all_cdtocs ]
-        if defined $inc && $inc->discids;
+    if (defined $inc && $inc->discids)
+    {
+        $body{discids} = [ ];
+        for my $disc (sort_by { $_->cdtoc->discid } $entity->all_cdtocs)
+        {
+            push $body{discids}, serialize_entity ($disc->cdtoc, $inc, $stash);
+        }
+    }
 
     $body{"track-count"} = $entity->tracklist->track_count;
 
diff --git a/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Utils.pm b/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Utils.pm
index ac75a70..4a26bc8 100644
--- a/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Utils.pm
+++ b/lib/MusicBrainz/Server/WebService/Serializer/JSON/2/Utils.pm
@@ -18,6 +18,7 @@ Readonly my %ENTITY_TO_SERIALIZER => (
     'MusicBrainz::Server::Entity::Artist' => 'MusicBrainz::Server::WebService::Serializer::JSON::2::Artist',
     'MusicBrainz::Server::Entity::ArtistCredit' => 'MusicBrainz::Server::WebService::Serializer::JSON::2::ArtistCredit',
     'MusicBrainz::Server::Entity::Collection' => 'MusicBrainz::Server::WebService::Serializer::JSON::2::Collection',
+    'MusicBrainz::Server::Entity::CDTOC' => 'MusicBrainz::Server::WebService::Serializer::JSON::2::CDTOC',
     'MusicBrainz::Server::Entity::Label' => 'MusicBrainz::Server::WebService::Serializer::JSON::2::Label',
     'MusicBrainz::Server::Entity::Medium' => 'MusicBrainz::Server::WebService::Serializer::JSON::2::Medium',
     'MusicBrainz::Server::Entity::Recording' => 'MusicBrainz::Server::WebService::Serializer::JSON::2::Recording',

-----------------------------------------------------------------------


hooks/post-receive
-- 
mb_server