Created
April 27, 2018 17:01
-
-
Save jlwaugh/eb73bffdca4a968bebe3d563c944d46d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.2; | |
contract Playlists { | |
struct Playlist { | |
address creator; | |
string title; | |
string description; | |
address[] contentList; | |
} | |
mapping (address => Playlist) playlists; | |
event Create(address _creator, string _title, string _description, address[] _contentList, address _playlist); | |
event Edit(address _creator, string _title, string _description, address _playlist); | |
event Add(address _content, address _playlist); | |
event Remove(address _content, address _playlist); | |
function create(address _creator, string _title, string _description, address[] _contentList, address _playlist) public { | |
playlists[_playlist] = Playlist({creator:_creator, title:_title, description:_description, contentList:_contentList}); | |
emit Create (_creator, _title, _description, _contentList, _playlist); | |
} | |
function edit(address _creator, string _title, string _description, address _playlist) public { | |
Playlist storage playlist = playlists[_playlist]; | |
playlist.creator = _creator; | |
playlist.title = _title; | |
playlist.description = _description; | |
playlists[_playlist] = playlist; | |
emit Edit(_creator, _title, _description, _playlist); | |
} | |
function add(address _content, address _playlist) public{ | |
Playlist storage playlist = playlists[_playlist]; | |
playlist.contentList.push(_content); | |
playlists[_playlist] = playlist; | |
emit Add(_content, _playlist); | |
} | |
function remove(address _content, address _playlist) public{ | |
Playlist storage playlist = playlists[_playlist]; | |
for (uint x = 0; x<playlist.contentList.length; x++) { | |
if (playlist.contentList[x] == _content){ | |
for (uint i = x; i<playlist.contentList.length-1; i++){ | |
playlist.contentList[i] = playlist.contentList[i+1]; | |
} | |
playlist.contentList.length--; | |
} | |
} | |
playlists[_playlist] = playlist; | |
emit Remove(_content, _playlist); | |
} | |
function get (address _playlist) public constant returns (address, string, string, address[]){ | |
return ( | |
playlists[_playlist].creator, | |
playlists[_playlist].title, | |
playlists[_playlist].description, | |
playlists[_playlist].contentList | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment