Skip to content

Commit

Permalink
Format all code according to editorconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
vectorNull committed Jun 6, 2024
1 parent fbd9985 commit 25b4110
Show file tree
Hide file tree
Showing 24 changed files with 183 additions and 146 deletions.
33 changes: 33 additions & 0 deletions api/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Indentation override for all JS under lib directory
[lib/**.js]
indent_style = space
indent_size = 2

# Matches the exact files either package.json or .travis.yml
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2
3 changes: 1 addition & 2 deletions api/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ public async Task<IActionResult> Register([FromBody] RegisterDto registerDto)
}
catch (Exception ex)
{

return StatusCode(500, ex);
}
}
}
}
}
14 changes: 7 additions & 7 deletions api/Controllers/CommentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public async Task<IActionResult> GetCommentbyId([FromRoute] int id)
{
return NotFound();
}
return Ok(commentModel.ToCommentDto());

return Ok(commentModel.ToCommentDto());
}

[HttpPost("{stockId:int}")]
public async Task<IActionResult> CreateComment([FromRoute] int stockId, [FromBody] CreateCommentRequestDto commentDto)
{
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
Expand All @@ -70,7 +70,7 @@ public async Task<IActionResult> CreateComment([FromRoute] int stockId, [FromBod
{
return BadRequest("Stock does not exist.");
}

var commentModel = commentDto.FromCreatedDtoToComment(stockId);

await _commentRepo.CreateAsync(commentModel);
Expand Down Expand Up @@ -106,7 +106,7 @@ public async Task<IActionResult> DeleteComment([FromRoute] int id)
// {
// return BadRequest(ModelState);
// }

var comment = await _commentRepo.DeleteAsync(id);

if (comment is null)
Expand All @@ -116,6 +116,6 @@ public async Task<IActionResult> DeleteComment([FromRoute] int id)

return NoContent();
}

}
}
}
200 changes: 100 additions & 100 deletions api/Controllers/StockController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,105 +8,105 @@

namespace api.Controllers
{
[Route("api/v1/stock")]
[ApiController]
public class StockController : ControllerBase
{
private readonly IStockRepo _stockRepo;
private readonly AppDbContext _context;

public StockController(AppDbContext context, IStockRepo stockRepo)
[Route("api/v1/stock")]
[ApiController]
public class StockController : ControllerBase
{
_context = context;
_stockRepo = stockRepo;
private readonly IStockRepo _stockRepo;
private readonly AppDbContext _context;

public StockController(AppDbContext context, IStockRepo stockRepo)
{
_context = context;
_stockRepo = stockRepo;
}

[Time]
[HttpGet]
public async Task<IActionResult> GetAll([FromQuery] QueryObject query)
{

//! Uncomment if ever passing dto to method. Validation performed in class.
// if (!ModelState.IsValid)
// {
// return BadRequest(ModelState);
// }

var stocks = await _stockRepo.GetAllAsync(query);
var stockDTOs = stocks.Select(s => s.ToStockDto());

return Ok(stockDTOs);
}

[HttpGet("{id:int}")]
public async Task<IActionResult> GetById([FromRoute] int id)
{
//! Uncomment if ever passing dto to method. Validation performed in class.
// if (!ModelState.IsValid)
// {
// return BadRequest(ModelState);
// }

var stockModel = await _stockRepo.GetByIdAsync(id);

if (stockModel == null)
{
return NotFound();
}

return Ok(stockModel.ToStockDto());
}

[HttpPost]
public async Task<IActionResult> Create([FromBody] CreateStockRequestDto stockDto)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}

var stockModel = stockDto.ToStockFromCreateDto();
await _stockRepo.CreateAsync(stockModel);
return CreatedAtAction(nameof(GetById), new { id = stockModel.Id }, stockModel.ToStockDto());
}

[HttpPut]
[Route("{id:int}")]
public async Task<IActionResult> Update([FromRoute] int id, [FromBody] UpdateStockRequestDto stockDto)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}

var stockModel = await _stockRepo.UpdateAsync(id, stockDto);

if (stockModel is null)
{
return NotFound();
}

return Ok(stockModel.ToStockDto());
}

[HttpDelete]
[Route("{id:int}")]
public async Task<IActionResult> Delete([FromRoute] int id)
{
//! Uncomment if ever passing dto to method. Validation performed in class.
// if (!ModelState.IsValid)
// {
// return BadRequest(ModelState);
// }

var stockModel = await _stockRepo.DeleteAsync(id);

if (stockModel == null)
{
return NotFound();
}

return NoContent();
}
}

[Time]
[HttpGet]
public async Task<IActionResult> GetAll([FromQuery] QueryObject query)
{

//! Uncomment if ever passing dto to method. Validation performed in class.
// if (!ModelState.IsValid)
// {
// return BadRequest(ModelState);
// }

var stocks = await _stockRepo.GetAllAsync(query);
var stockDTOs = stocks.Select(s => s.ToStockDto());

return Ok(stockDTOs);
}

[HttpGet("{id:int}")]
public async Task<IActionResult> GetById([FromRoute] int id)
{
//! Uncomment if ever passing dto to method. Validation performed in class.
// if (!ModelState.IsValid)
// {
// return BadRequest(ModelState);
// }

var stockModel = await _stockRepo.GetByIdAsync(id);

if (stockModel == null)
{
return NotFound();
}

return Ok(stockModel.ToStockDto());
}

[HttpPost]
public async Task<IActionResult> Create([FromBody] CreateStockRequestDto stockDto)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}

var stockModel = stockDto.ToStockFromCreateDto();
await _stockRepo.CreateAsync(stockModel);
return CreatedAtAction(nameof(GetById), new { id = stockModel.Id }, stockModel.ToStockDto());
}

[HttpPut]
[Route("{id:int}")]
public async Task<IActionResult> Update([FromRoute] int id, [FromBody] UpdateStockRequestDto stockDto)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}

var stockModel = await _stockRepo.UpdateAsync(id, stockDto);

if (stockModel is null)
{
return NotFound();
}

return Ok(stockModel.ToStockDto());
}

[HttpDelete]
[Route("{id:int}")]
public async Task<IActionResult> Delete([FromRoute] int id)
{
//! Uncomment if ever passing dto to method. Validation performed in class.
// if (!ModelState.IsValid)
// {
// return BadRequest(ModelState);
// }

var stockModel = await _stockRepo.DeleteAsync(id);

if (stockModel == null)
{
return NotFound();
}

return NoContent();
}
}
}
}
4 changes: 2 additions & 2 deletions api/DTOs/Account/RegisterDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class RegisterDto
[Required]
[EmailAddress]
public string? Email { get; set; }

[Required]
public string? Password { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion api/DTOs/Comment/CommentDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ public class CommentDto
public DateTime CreatedOn { get; set; }
public int? StockId { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion api/DTOs/Comment/CreateCommentRequestDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public class CreateCommentRequestDto
[MinLength(5, ErrorMessage = "Content must be 5 characters.")]
public string Content { get; set; } = string.Empty;
}
}
}
2 changes: 1 addition & 1 deletion api/DTOs/Comment/UpdateCommentRequestDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public class UpdateCommentRequestDto
[MinLength(5, ErrorMessage = "Content must be 5 characters.")]
public string Content { get; set; } = string.Empty;
}
}
}
2 changes: 1 addition & 1 deletion api/DTOs/Stock/CreateStockRequestDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public class CreateStockRequestDto
[Range(1, 500000000000)]
public long MarketCap { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion api/DTOs/Stock/StockDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public class StockDto
public long MarketCap { get; set; }
public List<CommentDto>? Comments { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion api/DTOs/Stock/UpdateStockRequestDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public class UpdateStockRequestDto
[Range(1, 500000000000)]
public long MarketCap { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion api/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ protected override void OnModelCreating(ModelBuilder builder)
builder.Entity<IdentityRole>().HasData(roles);
}
}
}
}
4 changes: 2 additions & 2 deletions api/Helpers/QueryObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class QueryObject
public string? SortBy { get; set; } = null;
public bool IsDescending { get; set; } = false;
public int PageNumber { get; set; } = 1;
public int PageSize { get; set; } = 20;
public int PageSize { get; set; } = 20;
}
}
}
2 changes: 1 addition & 1 deletion api/Interfaces/ICommentRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ public interface ICommentRepo
Task<Comment?> UpdateAsync(int id, UpdateCommentRequestDto commentDto);
Task<Comment?> DeleteAsync(int id);
}
}
}
2 changes: 1 addition & 1 deletion api/Interfaces/IStockRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public interface IStockRepo
Task<Stock?> DeleteAsync(int id);
Task<bool> StockExists(int id);
}
}
}
2 changes: 1 addition & 1 deletion api/Mappers/CommentMappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ public static Comment FromUpdateDtoToComment(this UpdateCommentRequestDto commen
};
}
}
}
}
2 changes: 1 addition & 1 deletion api/Mappers/StockMappers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ public static Stock ToStockFromCreateDto(this CreateStockRequestDto stockDto)
};
}
}
}
}
Loading

0 comments on commit 25b4110

Please sign in to comment.