예제 #1
0
  @POST
  @UnitOfWork
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  @Path("/{name}")
  public Response createPerson(
      @PathParam("name") String name,
      @FormParam("outline") String outline,
      @FormParam("musics") String musics)
      throws URISyntaxException {
    List<PlayListDetail> list = playListDetailDAO.findByName(name);
    if (!list.isEmpty()) {
      Response.status(Response.Status.CONFLICT).build();
    }
    if (musics != null) {
      String[] musicIds = musics.split(",");
      int num = 1;
      for (String id : musicIds) {
        // TODO 存在チェック
        PlayListDetail d = new PlayListDetail();
        d.setMusic_id(Integer.getInteger(id));
        d.setPlaylist_name(name);
        d.setNumber(num);
        num++;
        playListDetailDAO.create(d);
      }
    }

    PlayList playList = new PlayList();
    playList.setName(name);
    playList.setOutline(outline);
    playListDAO.create(playList);

    return Response.status(Response.Status.NO_CONTENT).build();
  }
예제 #2
0
  @POST
  @UnitOfWork
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  @Path("/{name}/remove")
  public Response deleteMusic(@PathParam("name") String name, @FormParam("number") IntParam number)
      throws URISyntaxException {

    if (number == null || number.get() < 1) {
      Response.status(Response.Status.BAD_REQUEST).build();
    }
    final List<PlayList> playLists = playListDAO.findByName(name);
    if (!playLists.isEmpty()) {
      Response.status(Response.Status.NOT_FOUND).build();
    }

    List<PlayListDetail> list = playListDetailDAO.findByName(name);
    int num = 1;
    for (PlayListDetail d : list) {
      if (number.get().equals(d.getNumber())) {
        playListDetailDAO.deleteByPk(d.getPlaylist_name(), d.getNumber());
      } else {
        d.setNumber(num);
        playListDetailDAO.create(d);
        num++;
      }
    }

    return Response.status(Response.Status.NO_CONTENT).build();
  }
예제 #3
0
  @POST
  @UnitOfWork
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  @Path("/{name}/add")
  public Response addMusic(
      @PathParam("name") String name,
      @FormParam("music_id") IntParam musicId,
      @FormParam("number") IntParam number)
      throws URISyntaxException {

    if (musicId == null || number == null || number.get() < 1) {
      Response.status(Response.Status.BAD_REQUEST).build();
    }
    final List<PlayList> playLists = playListDAO.findByName(name);
    if (!playLists.isEmpty()) {
      Response.status(Response.Status.NOT_FOUND).build();
    }
    Optional<Music> m = musicDAO.findById(musicId.get());
    if (m.get() == null) {
      Response.status(Response.Status.BAD_REQUEST).build();
    }
    List<PlayListDetail> list = playListDetailDAO.findByName(name);
    int num = 1;
    for (PlayListDetail d : list) {
      if (number.get().equals(num)) {
        PlayListDetail nd = new PlayListDetail();
        nd.setMusic_id(musicId.get());
        nd.setPlaylist_name(name);
        nd.setNumber(num);
        playListDetailDAO.create(nd);
        num++;
      }
      d.setNumber(num);
      playListDetailDAO.create(d);
      num++;
    }

    return Response.status(Response.Status.NO_CONTENT).build();
  }
예제 #4
0
  @GET
  @UnitOfWork
  @Path("/{name}")
  public Response getMusic(@PathParam("name") String name) {
    final List<PlayList> playLists = playListDAO.findByName(name);
    if (playLists.isEmpty()) {
      return Response.status(Response.Status.NOT_FOUND).build();
    }

    //		for (PlayList playList : playLists) {
    //			List<PlayListDetail> list = playListDetailDAO.findByName(name);
    //			playList.setPlayListDetails(list);
    //		}
    List<PlayListDetail> list = playListDetailDAO.findByName(name);
    List<Music> musics = new ArrayList<>();
    for (PlayListDetail d : list) {
      if (d.getMusic_id() != null) {
        Optional<Music> m = musicDAO.findById(d.getMusic_id());
        musics.add(m.get());
      }
    }
    playLists.get(0).setMusics(musics);
    return Response.status(Response.Status.OK).entity(playLists).build();
  }