generated from ISUCT/Tprogramming_42_2020
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from ISUCT/KeyListBackend
Key list backend ready
- Loading branch information
Showing
16 changed files
with
313 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace Application.DTO.Request | ||
{ | ||
using Application.Interfaces; | ||
using Domain.Models; | ||
|
||
public class KeyCreateRequestDto : IDtoMapper<Key> | ||
{ | ||
public string Classroom { get; set; } | ||
|
||
public string QR { get; set; } | ||
|
||
public Key ToModel() | ||
{ | ||
return new Key() | ||
{ | ||
Classroom = this.Classroom, | ||
QR = this.QR, | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace Application.ViewModels | ||
{ | ||
using Domain.Models; | ||
|
||
public class KeyDto | ||
{ | ||
public KeyDto(Key key) | ||
{ | ||
this.Id = key.Id; | ||
this.Classroom = key.Classroom; | ||
this.QR = key.QR; | ||
} | ||
|
||
public KeyDto() | ||
{ | ||
} | ||
|
||
public int Id { get; set; } | ||
|
||
public string Classroom { get; set; } | ||
|
||
public string QR { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Application.Interfaces | ||
{ | ||
using System.Collections.Generic; | ||
using Application.DTO.Request; | ||
using Application.ViewModels; | ||
|
||
public interface IKeyService | ||
{ | ||
List<KeyDto> GetKeys(); | ||
|
||
KeyDto InsertKey(KeyCreateRequestDto key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace Application.Services | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Application.DTO.Request; | ||
using Application.Interfaces; | ||
using Application.ViewModels; | ||
using Domain.Repository; | ||
|
||
public class KeyService : IKeyService | ||
{ | ||
private IKeyRepository _keyRepository; | ||
|
||
public KeyService(IKeyRepository keyRepository) | ||
{ | ||
_keyRepository = keyRepository; | ||
} | ||
|
||
public List<KeyDto> GetKeys() | ||
{ | ||
return _keyRepository.GetKeys().Select(x => new KeyDto(x)).ToList(); | ||
} | ||
|
||
public KeyDto InsertKey(KeyCreateRequestDto key) | ||
{ | ||
var createdKey = new KeyDto(_keyRepository.InsertKey(key.ToModel())); | ||
return createdKey; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Domain.Models | ||
{ | ||
public class Key | ||
{ | ||
public int Id { get; set; } | ||
|
||
public string Classroom { get; set; } | ||
|
||
public string QR { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Domain.Repository | ||
{ | ||
using System.Linq; | ||
using Domain.Models; | ||
|
||
public interface IKeyRepository | ||
{ | ||
IQueryable<Key> GetKeys(); | ||
|
||
Key InsertKey(Key key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
server/Infrastructure/Migrations/20210625151739_AddedKeys.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
server/Infrastructure/Migrations/20210625151739_AddedKeys.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace Infrastructure.Migrations | ||
{ | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
public partial class AddedKeys : Migration | ||
{ | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropForeignKey( | ||
name: "FK_Keys_Teachers_TeacherId", | ||
table: "Keys"); | ||
|
||
migrationBuilder.DropIndex( | ||
name: "IX_Keys_TeacherId", | ||
table: "Keys"); | ||
|
||
migrationBuilder.DropColumn( | ||
name: "TeacherId", | ||
table: "Keys"); | ||
} | ||
|
||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.AddColumn<int>( | ||
name: "TeacherId", | ||
table: "Keys", | ||
type: "integer", | ||
nullable: true); | ||
|
||
migrationBuilder.CreateIndex( | ||
name: "IX_Keys_TeacherId", | ||
table: "Keys", | ||
column: "TeacherId"); | ||
|
||
migrationBuilder.AddForeignKey( | ||
name: "FK_Keys_Teachers_TeacherId", | ||
table: "Keys", | ||
column: "TeacherId", | ||
principalTable: "Teachers", | ||
principalColumn: "Id", | ||
onDelete: ReferentialAction.Restrict); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace CleanArchitecture.Infra.Data.Repositories | ||
{ | ||
using System.Linq; | ||
using Domain.Models; | ||
using Domain.Repository; | ||
using Infrastructure.EF; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
public class KeyRepository : IKeyRepository | ||
{ | ||
private DatabaseContext context; | ||
|
||
public KeyRepository(DatabaseContext context) | ||
{ | ||
this.context = context; | ||
} | ||
|
||
public Key InsertKey(Key key) | ||
{ | ||
var entity = context.Add(key); | ||
context.SaveChanges(); | ||
return entity.Entity; | ||
} | ||
|
||
IQueryable<Key> IKeyRepository.GetKeys() | ||
{ | ||
return context.Keys.AsNoTracking(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace WebApi.Controllers | ||
{ | ||
using System.Collections.Generic; | ||
using Application.DTO.Request; | ||
using Application.Interfaces; | ||
using Application.ViewModels; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
|
||
[ApiController] | ||
[Route("api/[controller]")] | ||
public class KeysController : ControllerBase | ||
{ | ||
private readonly ILogger<KeysController> _logger; | ||
private IKeyService _keyService; | ||
|
||
public KeysController(ILogger<KeysController> logger, IKeyService keyService) | ||
{ | ||
_logger = logger; | ||
_keyService = keyService; | ||
} | ||
|
||
[HttpGet] | ||
public ActionResult<List<KeyDto>> Get() | ||
{ | ||
return this.Ok(_keyService.GetKeys()); | ||
} | ||
|
||
[HttpPost] | ||
public ActionResult<KeyDto> Insert([FromBody] KeyCreateRequestDto key) | ||
{ | ||
return this.Ok(_keyService.InsertKey(key)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters