-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement device entity and his repository and use case
- Loading branch information
Showing
17 changed files
with
195 additions
and
19 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,16 @@ | ||
using AutoMapper; | ||
using Gateways.Api.Models; | ||
using Gateways.Business.Contracts.Entities; | ||
using Gateways.Business.Contracts.UseCases; | ||
using Gateways.Common.Controllers; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Gateways.Api.Controllers; | ||
|
||
public class DevicesController : CrudApiControllerBase<Device, DeviceGetModel, DeviceGetDetailsModel, DevicePostModel, DevicePutModel, int> | ||
{ | ||
public DevicesController(IDeviceUseCase useCase, IMapper mapper) | ||
: base(useCase, mapper, q => q.Include(d => d.Gateway)) | ||
{ | ||
} | ||
} |
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,16 @@ | ||
using AutoMapper; | ||
using Gateways.Api.Models; | ||
using Gateways.Business.Contracts.Entities; | ||
|
||
namespace Gateways.Api.MapperProfiles; | ||
|
||
public class DeviceProfile : Profile | ||
{ | ||
public DeviceProfile() | ||
{ | ||
CreateMap<Device, DeviceGetModel>(); | ||
CreateMap<Device, DeviceGetDetailsModel>(); | ||
CreateMap<DevicePostModel, Device>(); | ||
CreateMap<DevicePutModel, Device>(); | ||
} | ||
} |
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,37 @@ | ||
using Gateways.Business.Contracts.Enums; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Gateways.Api.Models; | ||
|
||
public class DeviceBaseModel | ||
{ | ||
[Required] | ||
public string Vendor { get; set; } = default!; | ||
[Required] | ||
public DateTime DateCreated { get; set; } = DateTime.UtcNow; | ||
[Required] | ||
public DeviceStatus Status { get; set; } = DeviceStatus.Offline; | ||
|
||
[Required] | ||
public string GatewayId { get; set; } = default!; | ||
} | ||
|
||
public class DeviceGetModel : DeviceBaseModel | ||
{ | ||
public int Id { get; set; } = default!; | ||
} | ||
|
||
public class DeviceGetDetailsModel : DeviceGetModel | ||
{ | ||
public GatewayGetModel Gateway { get; set; } = default!; | ||
} | ||
|
||
public class DevicePostModel : DeviceBaseModel | ||
{ | ||
|
||
} | ||
|
||
public class DevicePutModel : DeviceBaseModel | ||
{ | ||
|
||
} |
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
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,18 @@ | ||
using Gateways.Business.Contracts.Enums; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Gateways.Business.Contracts.Entities; | ||
|
||
public class Device : Entity<int> | ||
{ | ||
[Required] | ||
public string Vendor { get; set; } = default!; | ||
[Required] | ||
public DateTime DateCreated { get; set; } = DateTime.UtcNow; | ||
[Required] | ||
public DeviceStatus Status { get; set; } = DeviceStatus.Offline; | ||
|
||
[Required] | ||
public string GatewayId { get; set; } = default!; | ||
public Gateway Gateway { get; set; } = default!; | ||
} |
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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
namespace Gateways.Business.Contracts.Entities; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Gateways.Business.Contracts.Entities; | ||
|
||
public class Gateway : Entity | ||
{ | ||
[Required] | ||
public string Name { get; set; } = default!; | ||
[Required] | ||
public string IPv4 { get; set; } = default!; | ||
public IEnumerable<Device> Devices { get; set; } = new List<Device>(); | ||
} |
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,7 @@ | ||
namespace Gateways.Business.Contracts.Enums; | ||
|
||
public enum DeviceStatus | ||
{ | ||
Offline, | ||
Online, | ||
} |
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,7 @@ | ||
using Gateways.Business.Contracts.Entities; | ||
|
||
namespace Gateways.Business.Contracts.UseCases; | ||
|
||
public interface IDeviceUseCase : IUseCase<Device> | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
Gateways.Business.Implementations/Repositories/IDeviceRepository.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,8 @@ | ||
using Gateways.Business.Contracts; | ||
using Gateways.Business.Contracts.Entities; | ||
|
||
namespace Gateways.Business.Implementations.Repositories; | ||
|
||
public interface IDeviceRepository : IRepository<Device> | ||
{ | ||
} |
12 changes: 12 additions & 0 deletions
12
Gateways.Business.Implementations/UseCases/DeviceUseCase.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,12 @@ | ||
using Gateways.Business.Contracts.Entities; | ||
using Gateways.Business.Contracts.UseCases; | ||
using Gateways.Business.Implementations.Repositories; | ||
|
||
namespace Gateways.Business.Implementations.UseCases; | ||
|
||
public class DeviceUseCase : BaseUseCase<Device>, IDeviceUseCase | ||
{ | ||
public DeviceUseCase(IDeviceRepository repository) : base(repository) | ||
{ | ||
} | ||
} |
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
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
13 changes: 13 additions & 0 deletions
13
Gateways.Data.Implementations/Repositories/DeviceRepository.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,13 @@ | ||
using Gateways.Business.Contracts; | ||
using Gateways.Business.Contracts.Entities; | ||
using Gateways.Business.Implementations.Repositories; | ||
|
||
namespace Gateways.Data.Implementations.Repositories | ||
{ | ||
public class DeviceRepository : BaseRepository<Device, int>, IDeviceRepository | ||
{ | ||
public DeviceRepository(IObjectContext context) : base(context) | ||
{ | ||
} | ||
} | ||
} |