Skip to content

Commit

Permalink
Added extension header
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLazarescu committed Mar 14, 2024
1 parent b9ab10e commit 3b5e593
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Application/Interfaces/Services/IBookService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ public interface IBookService
Task<Stream> GetBookCover(string email, Guid guid);
Task DeleteBookCover(string email, Guid guid);
Task<string> GetFormatForBook(string email, Guid guid);
Task<string> GetExtensionForBook(string email, Guid guid);
}
13 changes: 13 additions & 0 deletions src/Application/Services/BookService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,19 @@ public async Task<string> GetFormatForBook(string email, Guid guid)
return book.Format;
}

public async Task<string> GetExtensionForBook(string email, Guid guid)
{
var user = await _userRepository.GetAsync(email, trackChanges: true);
var book = user.Books.SingleOrDefault(book => book.BookId == guid);
if (book == null)
{
const string message = "No book with this id exists";
throw new CommonErrorException(404, message, 4);
}

return book.Extension;
}

public async Task ChangeBookCover(string email, Guid guid, MultipartReader reader)
{
var user = await _userRepository.GetAsync(email, trackChanges: true);
Expand Down
7 changes: 6 additions & 1 deletion src/Presentation/Controllers/BookController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ public async Task<ActionResult> GetBookBinaryData(Guid guid)
var email = HttpContext.User.Identity!.Name;
var stream = await _bookService.GetBookBinaryData(email,
guid);

// This is added for legacy purposes. Previously the client depended on getting the format, but newer
// clients use the extension. We keep it to keep the old clients working.
Response.Headers.Add("Format",
await _bookService.GetFormatForBook(email, guid));

Response.Headers.Add("Extension",
await _bookService.GetExtensionForBook(email, guid));

return File(stream, "application/octet-stream");
}
catch (CommonErrorException e)
Expand Down

0 comments on commit 3b5e593

Please sign in to comment.