Skip to content

Commit

Permalink
- Update docker files.
Browse files Browse the repository at this point in the history
- Add response types for APIs.
- Fix test errors when running on Linux.
  • Loading branch information
NhatTanVu committed Jan 24, 2021
1 parent 459b7e4 commit d04ecf4
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 67 deletions.
41 changes: 0 additions & 41 deletions MyAlbum.Docker/build.sh

This file was deleted.

4 changes: 2 additions & 2 deletions MyAlbum.Docker/db/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM mcr.microsoft.com/mssql/server:2019-latest
COPY sql /app
COPY entrypoint.sh /app
WORKDIR /app
COPY ./MyAlbum.WebSPA/sql .
COPY ./MyAlbum.Docker/db/entrypoint.sh .
EXPOSE 1433/tcp
CMD /bin/bash ./entrypoint.sh
8 changes: 6 additions & 2 deletions MyAlbum.Docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
version: "3.9"
services:
web:
build: ./web
build:
context: ..
dockerfile: ./MyAlbum.Docker/web/Dockerfile
ports:
- "80:80"
- "443:443"
Expand All @@ -15,7 +17,9 @@ services:
container_name: "my-album-web"
image: "my-album-web:latest"
db:
build: ./db
build:
context: ..
dockerfile: ./MyAlbum.Docker/db/Dockerfile
environment:
SA_PASSWORD: "IamTan86"
ACCEPT_EULA: "Y"
Expand Down
49 changes: 43 additions & 6 deletions MyAlbum.Docker/web/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,45 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 as publish
WORKDIR /src
# update
RUN apt-get update
# install curl
RUN apt-get install curl
# get install script and pass it to execute:
RUN curl -sL https://deb.nodesource.com/setup_15.x | bash
# and install node
RUN apt-get install nodejs
# confirm that it was successful
RUN node -v
# npm installs automatically
RUN npm -v
# copy project files
COPY ./MyAlbum.WebSPA .
RUN dotnet restore
RUN dotnet publish MyAlbum.WebSPA.csproj -c Release -o /app
# cleanup unused publish files
RUN rm -rf "/app/runtimes/linux-x86"
RUN rm -rf "/app/runtimes/osx-x64"
RUN rm -rf "/app/runtimes/win"
RUN rm -rf "/app/runtimes/win-arm64"
RUN rm -rf "/app/runtimes/win-x64"
RUN rm -rf "/app/runtimes/win-x86"
RUN rm -rf "/app/cs"
RUN rm -rf "/app/de"
RUN rm -rf "/app/es"
RUN rm -rf "/app/fr"
RUN rm -rf "/app/it"
RUN rm -rf "/app/ja"
RUN rm -rf "/app/ko"
RUN rm -rf "/app/pl"
RUN rm -rf "/app/pt-BR"
RUN rm -rf "/app/ru"
RUN rm -rf "/app/tr"
RUN rm -rf "/app/zh-Hans"
RUN rm -rf "/app/zh-Hant"

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 as final
WORKDIR /app
RUN apt-get update && apt-get install -y libgdiplus
RUN apt-get update && apt-get install -y libgomp1
COPY publish /app
COPY entrypoint.sh /app
WORKDIR /app
#EXPOSE 80/tcp 443/tcp
CMD /bin/bash ./entrypoint.sh
COPY --from=publish /app /app
ENTRYPOINT [ "dotnet", "MyAlbum.WebSPA.dll" ]
7 changes: 0 additions & 7 deletions MyAlbum.Docker/web/entrypoint.sh

This file was deleted.

6 changes: 3 additions & 3 deletions MyAlbum.Tests/Core/FileSystemPhotoStorage/CopyPhoto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class FileSystemPhotoStorage_Test3
public void CopyPhoto()
{
// Arrange
string originalFilePath = @".\car.jpg";
string originalFilePath = Path.Combine(".", "car.jpg");
string fileName = Guid.NewGuid().ToString();
string uploadsFolderPath = @".\uploads";
string outputFolderPath = @".\output";
string uploadsFolderPath = Path.Combine(".", "uploads");
string outputFolderPath = Path.Combine(".", "output");
if (!Directory.Exists(uploadsFolderPath))
{
Directory.CreateDirectory(uploadsFolderPath);
Expand Down
6 changes: 3 additions & 3 deletions MyAlbum.Tests/Core/FileSystemPhotoStorage/DeletePhoto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public class FileSystemPhotoStorage_Test2
public void DeletePhoto()
{
// Arrange
string originalFilePath = @".\car.jpg";
string originalFilePath = Path.Combine(".","car.jpg");
string fileName = Guid.NewGuid().ToString();
string uploadsFolderPath = @".\uploads";
string outputFolderPath = @".\output";
string uploadsFolderPath = Path.Combine(".","uploads");
string outputFolderPath = Path.Combine(".","output");
if (!Directory.Exists(uploadsFolderPath))
{
Directory.CreateDirectory(uploadsFolderPath);
Expand Down
4 changes: 2 additions & 2 deletions MyAlbum.Tests/Core/FileSystemPhotoStorage/StorePhoto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ private IFormFile GetFormFile(string filePath)
public async Task StorePhoto()
{
// Arrange
string originalFilePath = @".\car.jpg";
string uploadsFolderPath = @".\uploads";
string originalFilePath = Path.Combine(".", "car.jpg");
string uploadsFolderPath = Path.Combine(".", "uploads");
if (!Directory.Exists(uploadsFolderPath))
{
Directory.CreateDirectory(uploadsFolderPath);
Expand Down
15 changes: 15 additions & 0 deletions MyAlbum.WebSPA/Controllers/AlbumsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public AlbumsController(IMapper mapper, IAlbumRepository albumRepository, IUserR
/// Get an album by ID
/// </summary>
[HttpGet("{id}")]
[ProducesResponseType((int)System.Net.HttpStatusCode.NotFound)]
[ProducesResponseType(typeof(AlbumResource), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAlbum([FromRoute] int id)
{
var album = await albumRepository.GetAsync(id);
Expand All @@ -53,6 +55,7 @@ public async Task<IActionResult> GetAlbum([FromRoute] int id)
/// Get a list of albums by filter
/// </summary>
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<AlbumResource>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IEnumerable<AlbumResource>> GetAlbums([FromQuery] AlbumQueryResource filterResource)
{
var filter = this.mapper.Map<AlbumQueryResource, AlbumQuery>(filterResource);
Expand All @@ -73,6 +76,9 @@ public async Task<IEnumerable<AlbumResource>> GetAlbums([FromQuery] AlbumQueryRe
/// </summary>
[HttpPost]
[Authorize]
[ProducesResponseType((int)System.Net.HttpStatusCode.Unauthorized)]
[ProducesResponseType((int)System.Net.HttpStatusCode.NoContent)]
[ProducesResponseType(typeof(AlbumResource), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> CreateAlbum([FromForm] AlbumResource albumResource)
{
if (string.IsNullOrEmpty(albumResource.Name))
Expand All @@ -98,6 +104,11 @@ public async Task<IActionResult> CreateAlbum([FromForm] AlbumResource albumResou
/// </summary>
[HttpPost("{id}")]
[Authorize]
[ProducesResponseType((int)System.Net.HttpStatusCode.Unauthorized)]
[ProducesResponseType((int)System.Net.HttpStatusCode.Forbidden)]
[ProducesResponseType((int)System.Net.HttpStatusCode.BadRequest)]
[ProducesResponseType((int)System.Net.HttpStatusCode.NotFound)]
[ProducesResponseType(typeof(AlbumResource), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> UpdateAlbum([FromRoute] int id, [FromForm] AlbumResource albumResource)
{
Album album = await albumRepository.GetAsync(id);
Expand Down Expand Up @@ -125,6 +136,10 @@ public async Task<IActionResult> UpdateAlbum([FromRoute] int id, [FromForm] Albu
/// </summary>
[HttpDelete("{id}")]
[Authorize()]
[ProducesResponseType((int)System.Net.HttpStatusCode.Unauthorized)]
[ProducesResponseType((int)System.Net.HttpStatusCode.Forbidden)]
[ProducesResponseType((int)System.Net.HttpStatusCode.NotFound)]
[ProducesResponseType((int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> DeleteAlbum([FromRoute] int id)
{
Album album = await albumRepository.GetAsync(id);
Expand Down
13 changes: 13 additions & 0 deletions MyAlbum.WebSPA/Controllers/CommentsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public CommentsController(IMapper mapper, IHubContext<CommentHub> commentHub,
/// Get all replies for a comment by ID
/// </summary>
[HttpGet("{id}")]
[ProducesResponseType(typeof(IEnumerable<CommentResource>), (int)System.Net.HttpStatusCode.OK)]
public IEnumerable<CommentResource> GetReplies([FromRoute] int id)
{
IEnumerable<Comment> replies = this.commentRepository.GetReplies(id);
Expand All @@ -53,6 +54,9 @@ public IEnumerable<CommentResource> GetReplies([FromRoute] int id)
/// </summary>
[HttpPost]
[Authorize]
[ProducesResponseType((int)System.Net.HttpStatusCode.Unauthorized)]
[ProducesResponseType((int)System.Net.HttpStatusCode.NoContent)]
[ProducesResponseType(typeof(CommentResource), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> CreateComment([FromBody] CommentResource commentResource)
{
Photo photo = await this.photoRepository.GetAsync(commentResource.PhotoId);
Expand Down Expand Up @@ -82,6 +86,11 @@ public async Task<IActionResult> CreateComment([FromBody] CommentResource commen
/// </summary>
[HttpPost("{id}")]
[Authorize()]
[ProducesResponseType((int)System.Net.HttpStatusCode.Unauthorized)]
[ProducesResponseType((int)System.Net.HttpStatusCode.Forbidden)]
[ProducesResponseType((int)System.Net.HttpStatusCode.BadRequest)]
[ProducesResponseType((int)System.Net.HttpStatusCode.NotFound)]
[ProducesResponseType(typeof(CommentResource), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> UpdateComment([FromRoute] int id, [FromForm] CommentResource commentResource)
{
Comment comment = await commentRepository.GetAsync(id);
Expand Down Expand Up @@ -109,6 +118,10 @@ public async Task<IActionResult> UpdateComment([FromRoute] int id, [FromForm] Co
/// </summary>
[HttpDelete("{id}")]
[Authorize()]
[ProducesResponseType((int)System.Net.HttpStatusCode.Unauthorized)]
[ProducesResponseType((int)System.Net.HttpStatusCode.Forbidden)]
[ProducesResponseType((int)System.Net.HttpStatusCode.NotFound)]
[ProducesResponseType((int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> DeleteComment([FromRoute] int id)
{
Comment comment = await commentRepository.GetAsync(id);
Expand Down
5 changes: 4 additions & 1 deletion MyAlbum.WebSPA/Controllers/OidcConfigurationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace MyAlbum.WebSPA.Controllers
{
[ApiExplorerSettings(GroupName = "_JWT")]
[ApiExplorerSettings(GroupName = "-JWT-")]
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage()]
public class OidcConfigurationController : Controller
{
Expand Down Expand Up @@ -70,6 +70,8 @@ private string GenerateJSONWebToken(string userName, int expireMinutes = 20)
}

[HttpPost("api/JWT/Generate")]
[ProducesResponseType((int)System.Net.HttpStatusCode.Unauthorized)]
[ProducesResponseType((int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GenerateToken([FromForm] string UserName, [FromForm] string Password)
{
if (string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(Password))
Expand All @@ -88,6 +90,7 @@ public async Task<IActionResult> GenerateToken([FromForm] string UserName, [From
}

[HttpPost("api/JWT/Read")]
[ProducesResponseType((int)System.Net.HttpStatusCode.OK)]
public IActionResult ReadToken([FromForm] string Token)
{
if (string.IsNullOrEmpty(Token))
Expand Down
16 changes: 16 additions & 0 deletions MyAlbum.WebSPA/Controllers/PhotosController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public string OutputFolderPath
/// Get a photo by ID
/// </summary>
[HttpGet("{id}")]
[ProducesResponseType((int)System.Net.HttpStatusCode.NotFound)]
[ProducesResponseType(typeof(PhotoResource), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetPhoto([FromRoute] int id)
{
var photo = await photoRepository.GetAsync(id);
Expand All @@ -110,6 +112,7 @@ public async Task<IActionResult> GetPhoto([FromRoute] int id)
/// Get a list of photos by filter
/// </summary>
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<PhotoResource>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IEnumerable<PhotoResource>> GetPhotos([FromQuery] PhotoQueryResource filterResource)
{
var filter = mapper.Map<PhotoQueryResource, PhotoQuery>(filterResource);
Expand All @@ -134,6 +137,10 @@ public async Task<IEnumerable<PhotoResource>> GetPhotos([FromQuery] PhotoQueryRe
[HttpPost]
[Authorize]
[RequestFormLimits(MultipartBodyLengthLimit = 1048576)]
[ProducesResponseType((int)System.Net.HttpStatusCode.Unauthorized)]
[ProducesResponseType((int)System.Net.HttpStatusCode.NoContent)]
[ProducesResponseType((int)System.Net.HttpStatusCode.BadRequest)]
[ProducesResponseType(typeof(PhotoResource), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> CreatePhoto([FromForm] PhotoResource photoResource)
{
if (photoResource != null && photoResource.FileToUpload != null)
Expand Down Expand Up @@ -189,6 +196,11 @@ public async Task<IActionResult> CreatePhoto([FromForm] PhotoResource photoResou
[HttpPost("{id}")]
[Authorize()]
[RequestFormLimits(MultipartBodyLengthLimit = 1048576)]
[ProducesResponseType((int)System.Net.HttpStatusCode.Unauthorized)]
[ProducesResponseType((int)System.Net.HttpStatusCode.Forbidden)]
[ProducesResponseType((int)System.Net.HttpStatusCode.BadRequest)]
[ProducesResponseType((int)System.Net.HttpStatusCode.NotFound)]
[ProducesResponseType(typeof(PhotoResource), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> UpdatePhoto([FromRoute] int id, [FromForm] PhotoResource photoResource)
{
Photo photo = await photoRepository.GetAsync(id);
Expand Down Expand Up @@ -260,6 +272,10 @@ public async Task<IActionResult> UpdatePhoto([FromRoute] int id, [FromForm] Phot
/// </summary>
[HttpDelete("{id}")]
[Authorize()]
[ProducesResponseType((int)System.Net.HttpStatusCode.Unauthorized)]
[ProducesResponseType((int)System.Net.HttpStatusCode.Forbidden)]
[ProducesResponseType((int)System.Net.HttpStatusCode.NotFound)]
[ProducesResponseType((int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> DeletePhoto([FromRoute] int id)
{
Photo photo = await photoRepository.GetAsync(id);
Expand Down

0 comments on commit d04ecf4

Please sign in to comment.