Skip to content

Commit cda5d00

Browse files
committed
code refactored
1 parent 678739d commit cda5d00

1 file changed

Lines changed: 6 additions & 16 deletions

File tree

MockMe.API/Controllers/FileController.cs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using Microsoft.AspNetCore.StaticFiles;
44
using Microsoft.Extensions.Logging;
55
using MockMe.Model;
6-
using System;
76
using System.Collections.Generic;
87
using System.ComponentModel.DataAnnotations;
98
using System.IO;
@@ -24,16 +23,6 @@ public FileController(ILogger<FileController> logger)
2423
_logger = logger;
2524
}
2625

27-
[HttpGet("{id:int}/{templateId:int}")]
28-
[ProducesResponseType(typeof(TemplateFormResult), StatusCodes.Status200OK)]
29-
[ProducesResponseType(StatusCodes.Status400BadRequest)]
30-
public async Task<TemplateFormResult> FileView(int id, int templateId)
31-
{
32-
_logger.LogDebug("Viewing templateId={templateId} for file={id}", templateId, id);
33-
await Task.Delay(1000);
34-
return new TemplateFormResult { TemplateId = templateId, FileId = id };
35-
}
36-
3726
[HttpPost("{id:int}/upload")]
3827
[ProducesResponseType(StatusCodes.Status201Created)]
3928
[ProducesResponseType(StatusCodes.Status400BadRequest)]
@@ -51,9 +40,8 @@ public async Task<ActionResult<TemplateFormResult>> FileUpload(int id, [FromForm
5140

5241
await using (var stream = new FileStream(filePath, FileMode.Create))
5342
{
54-
_logger.LogDebug("Saving {FileName}", form.TemplateFile.FileName);
5543
await form.TemplateFile.CopyToAsync(stream);
56-
_logger.LogDebug("File saved {filePath}.", filePath);
44+
_logger.LogDebug("File uploaded to {filePath}.", filePath);
5745
}
5846
var result = new TemplateFormResult
5947
{
@@ -62,7 +50,7 @@ public async Task<ActionResult<TemplateFormResult>> FileUpload(int id, [FromForm
6250
FileName = form.TemplateFile.FileName,
6351
FileSize = form.TemplateFile.Length
6452
};
65-
return CreatedAtAction(nameof(FileView), new { id, form.TemplateId }, result);
53+
return CreatedAtAction(nameof(FileUpload), new { id, form.TemplateId }, result);
6654
}
6755

6856
[HttpPost("{id:int}/uploads")]
@@ -82,7 +70,7 @@ public async Task<ActionResult<List<TemplateFormResult>>> FilesUpload(int id, [R
8270

8371
await using var stream = new FileStream(filePath, FileMode.Create);
8472
await file.CopyToAsync(stream);
85-
_logger.LogDebug("Uploaded {file.FileName} and saved in {filePath}.", file.FileName, filePath);
73+
_logger.LogDebug("File uploaded to {filePath}.", filePath);
8674

8775
result.Add(new TemplateFormResult {
8876
FileId = -1,
@@ -91,10 +79,12 @@ public async Task<ActionResult<List<TemplateFormResult>>> FilesUpload(int id, [R
9179
FileSize = file.Length
9280
});
9381
}
94-
return CreatedAtAction(nameof(FileView), new { id, templateId = id }, result);
82+
return CreatedAtAction(nameof(FilesUpload), new { id, templateId = id }, result);
9583
}
9684

9785
[HttpGet("{filename}")]
86+
[ProducesResponseType(StatusCodes.Status200OK)]
87+
[ProducesResponseType(StatusCodes.Status204NoContent)]
9888
public async Task<ActionResult> FileDownload(string filename)
9989
{
10090
// validation and get the file

0 commit comments

Comments
 (0)