Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewPlaylistUpdateDTO #420

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions ClassTranscribeServer/Controllers/PlaylistsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,16 @@ public async Task<IActionResult> PutPlaylistOptions(string id, JObject options)
// PUT: api/Playlists/5
[HttpPut("{id}")]
[Authorize]
public async Task<IActionResult> PutPlaylist(string id, Playlist playlist)
public async Task<IActionResult> PutPlaylist(string id, PlaylistUpdateDTO playlist)
{
if (playlist == null || playlist.Id == null || id != playlist.Id || playlist.OfferingId == null)
{
return BadRequest();
return BadRequest("Validation checks");
}
var offering = await _context.Offerings.FindAsync(playlist.OfferingId);
if (offering == null)
{
return BadRequest();
return BadRequest("No such offering");
}
var authorizationResult = await _authorizationService.AuthorizeAsync(this.User, offering, Globals.POLICY_UPDATE_OFFERING);
if (!authorizationResult.Succeeded)
Expand All @@ -361,7 +361,7 @@ public async Task<IActionResult> PutPlaylist(string id, Playlist playlist)
var p = await _context.Playlists.FindAsync(playlist.Id);

p.Name = playlist.Name;
p.Options = playlist.Options;
p.setOptionsAsJson(playlist.Options);
p.PublishStatus = playlist.PublishStatus;

try
Expand Down Expand Up @@ -528,7 +528,13 @@ public class TranscriptionDTO
public String SourceLabel { get; set; } // where did this transcription originate?
public string Language { get; set; }
}

public class PlaylistUpdateDTO {
public string Id { get; set; }
public string OfferingId { get; set; }
public string Name { get; set; }
public JObject Options { get; set; }
public PublishStatus PublishStatus { get; set; }
}
public class PlaylistDTO
{
public string Id { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using ClassTranscribeServer;
using ClassTranscribeServer.Controllers;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -277,39 +278,45 @@ public async Task Put_Playlist_Success()
_context.Offerings.Add(new Offering { Id = offeringId });
_context.Playlists.Add(playlist);
_context.SaveChanges();

playlist.SourceType = SourceType.Kaltura;
playlist.Name = "bar";
playlist.Index = 13;

var result = await _controller.PutPlaylist(playlist.Id, playlist);
var update = new PlaylistUpdateDTO
{
Id = playlist.Id,
OfferingId = playlist.OfferingId,
Name = "bart",
Options = JObject.Parse("{\"a\":\"b\"}"),
PublishStatus = PublishStatus.NotPublished
};
var result = await _controller.PutPlaylist(playlist.Id, update);
Assert.IsType<NoContentResult>(result);

var updatedPlaylist = _context.Playlists.Find(playlist.Id);
Assert.Equal(playlist, updatedPlaylist);
Assert.Equal(update.Name, updatedPlaylist.Name);
Assert.Equal(update.PublishStatus, updatedPlaylist.PublishStatus);
Assert.Equal(update.Options, updatedPlaylist.getOptionsAsJson());
Assert.Equal(playlist.SourceType, updatedPlaylist.SourceType);
}

[Fact]
public async Task Put_Playlist_Fail()
{
var result = await _controller.PutPlaylist("none", new Playlist());
Assert.IsType<BadRequestResult>(result);
var result = await _controller.PutPlaylist("none", new PlaylistUpdateDTO());
Assert.IsType<BadRequestObjectResult>(result);

result = await _controller.PutPlaylist(null, new Playlist());
Assert.IsType<BadRequestResult>(result);
result = await _controller.PutPlaylist(null, new PlaylistUpdateDTO());
Assert.IsType<BadRequestObjectResult>(result);

result = await _controller.PutPlaylist("none", null);
Assert.IsType<BadRequestResult>(result);
Assert.IsType<BadRequestObjectResult>(result);

result = await _controller.PutPlaylist(null, null);
Assert.IsType<BadRequestResult>(result);
Assert.IsType<BadRequestObjectResult>(result);

var playlistId = "playlist";
_context.Playlists.Add(new Playlist { Id = playlistId, OfferingId = "none" });
_context.SaveChanges();

result = await _controller.PutPlaylist(playlistId, new Playlist { Id = playlistId, OfferingId = "hiya" });
Assert.IsType<BadRequestResult>(result);
result = await _controller.PutPlaylist(playlistId, new PlaylistUpdateDTO { Id = playlistId, OfferingId = "hiya" });
Assert.IsType<BadRequestObjectResult>(result);
}

[Fact]
Expand Down
Loading