#6 Initial work on implementing playlists

This commit is contained in:
Isaac Parenteau
2019-10-08 22:25:44 -05:00
parent fd21f39f67
commit af037f7eb7
4 changed files with 180 additions and 30 deletions

View File

@ -0,0 +1,48 @@
/**
*
* Project: Eight Track, File: GuildSongRepository.java
*
* Copyright 2019-2019 Locusworks LLC.
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
* any means and imposes fines up to $25,000 for violation. No part of this material
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
* modified, duplicated, adapted or translated into another program language in any
* form or by any means, electronic, mechanical, photocopying, recording, or
* otherwise, without the prior written permission from Locusworks. Locusworks
* affirms that Eight-Track(R) software and data is subject to United States
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
*
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS.
*/
package net.locusworks.discord.eighttrack.database.repos;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylist;
public interface GuildPlaylistRepository extends CrudRepository<GuildPlaylist, Long> {
GuildPlaylist findByGuildAndUserIdAndPlaylist(DiscordGuild guild, Long userId, String playlist);
@Query("SELECT gpl FROM GuildPlaylist gpl WHERE gpl.guild.guildId = ?1 AND gpl.userId = ?2 AND gpl.playlist = ?3 ")
GuildPlaylist findByGuildAndUserIdAndPlaylist(Long guild, Long userId, String playlist);
GuildPlaylist findByGuildAndUserId(DiscordGuild guild, Long userId);
@Query("SELECT gpl FROM GuildPlaylist gpl WHERE gpl.guild.guildId = ?1 AND gpl.userId = ?2 AND gpl.playlist = ?3 ")
GuildPlaylist findByGuildAndUserId(Long guild, Long userId);
}

View File

@ -0,0 +1,42 @@
/**
*
* Project: Eight Track, File: GuildSongRepository.java
*
* Copyright 2019-2019 Locusworks LLC.
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
* any means and imposes fines up to $25,000 for violation. No part of this material
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
* modified, duplicated, adapted or translated into another program language in any
* form or by any means, electronic, mechanical, photocopying, recording, or
* otherwise, without the prior written permission from Locusworks. Locusworks
* affirms that Eight-Track(R) software and data is subject to United States
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
*
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
* ENHANCEMENTS, OR MODIFICATIONS.
*/
package net.locusworks.discord.eighttrack.database.repos;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylist;
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylistSong;
public interface GuildPlaylistSongRepository extends CrudRepository<GuildPlaylistSong, Long> {
List<GuildPlaylistSong> findByGuildPlaylist(GuildPlaylist gpl);
}

View File

@ -58,6 +58,7 @@ import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
import net.dv8tion.jda.api.managers.AudioManager; import net.dv8tion.jda.api.managers.AudioManager;
import net.locusworks.crypto.utils.HashUtils; import net.locusworks.crypto.utils.HashUtils;
import net.locusworks.discord.eighttrack.database.entities.DiscordGuild; import net.locusworks.discord.eighttrack.database.entities.DiscordGuild;
import net.locusworks.discord.eighttrack.database.entities.GuildPlaylist;
import net.locusworks.discord.eighttrack.database.entities.GuildSong; import net.locusworks.discord.eighttrack.database.entities.GuildSong;
import net.locusworks.discord.eighttrack.database.entities.Song; import net.locusworks.discord.eighttrack.database.entities.Song;
import net.locusworks.discord.eighttrack.scheduler.TrackScheduler; import net.locusworks.discord.eighttrack.scheduler.TrackScheduler;
@ -437,7 +438,44 @@ public class GuildMusicHandler {
} }
private void addPlayList(GuildMessageReceivedEvent event, List<String> commands) { private void addPlayList(GuildMessageReceivedEvent event, List<String> commands) {
// TODO Auto-generated method stub if (commands == null || commands.isEmpty()) {
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " you have to provide the playlist to create a new playlist (no spaces in name) and optionally a list of uuids for songs to add").queue();
return;
}
Long guildId = event.getGuild().getIdLong();
DiscordGuild guild = guildSongRepoService.getGuildRepo().findByGuildId(guildId);
if (guild == null) {
event.getChannel().sendMessage("Unable to find guild in local database. Please contact administrator").queue();
return;
}
String playlist = commands.remove(0);
long userId = event.getMember().getIdLong();
GuildPlaylist gpl = guildSongRepoService.getGuildPlaylistRepo().findByGuildAndUserIdAndPlaylist(guild, userId, playlist);
boolean newList = false;
if (gpl != null && commands.isEmpty()) {
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " a playlist with the name " + playlist + " already exist for you.").queue();
return;
} else {
newList = true;
gpl = new GuildPlaylist();
gpl.setDateAdded(new Date());
gpl.setGuild(guild);
gpl.setPlaylist(playlist);
gpl.setUserId(userId);
guildSongRepoService.getGuildPlaylistRepo().save(gpl);
}
if (commands.isEmpty() && newList) {
event.getChannel().sendMessage(event.getAuthor().getAsMention() + " playlist " + playlist + " successfully created.").queue();
return;
}
} }
} }

View File

@ -30,6 +30,8 @@ package net.locusworks.discord.eighttrack.services;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import net.locusworks.discord.eighttrack.database.repos.GuildPlaylistRepository;
import net.locusworks.discord.eighttrack.database.repos.GuildPlaylistSongRepository;
import net.locusworks.discord.eighttrack.database.repos.GuildRepository; import net.locusworks.discord.eighttrack.database.repos.GuildRepository;
import net.locusworks.discord.eighttrack.database.repos.GuildSongRepository; import net.locusworks.discord.eighttrack.database.repos.GuildSongRepository;
import net.locusworks.discord.eighttrack.database.repos.SongRepository; import net.locusworks.discord.eighttrack.database.repos.SongRepository;
@ -43,6 +45,12 @@ public class GuildSongRepoService {
@Autowired @Autowired
private GuildSongRepository guildSongRepo; private GuildSongRepository guildSongRepo;
@Autowired
private GuildPlaylistRepository guildPlaylistRepo;
@Autowired
private GuildPlaylistSongRepository guildPlaylistSongRepo;
@Autowired @Autowired
private SongRepository songRepo; private SongRepository songRepo;
@ -60,6 +68,20 @@ public class GuildSongRepoService {
return guildSongRepo; return guildSongRepo;
} }
/**
* @return the guildPlaylistRepo
*/
public final GuildPlaylistRepository getGuildPlaylistRepo() {
return guildPlaylistRepo;
}
/**
* @return the guildPlaylistSongRepo
*/
public final GuildPlaylistSongRepository getGuildPlaylistSongRepo() {
return guildPlaylistSongRepo;
}
/** /**
* @return the songRepo * @return the songRepo
*/ */