-
Notifications
You must be signed in to change notification settings - Fork 0
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 #27 from FaithBeam/mapperly
Mapperly
- Loading branch information
Showing
41 changed files
with
881 additions
and
1,835 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,77 @@ | ||
using System; | ||
using Riok.Mapperly.Abstractions; | ||
using YMouseButtonControl.Core.ViewModels.Models; | ||
using YMouseButtonControl.DataAccess.Models; | ||
|
||
namespace YMouseButtonControl.Core.Mappings; | ||
|
||
[Mapper] | ||
public static partial class ButtonMappingMapper | ||
{ | ||
[MapDerivedType<DisabledMapping, DisabledMappingVm>] | ||
[MapDerivedType<NothingMapping, NothingMappingVm>] | ||
[MapDerivedType<SimulatedKeystroke, SimulatedKeystrokeVm>] | ||
[MapDerivedType<RightClick, RightClickVm>] | ||
public static partial BaseButtonMappingVm Map(ButtonMapping? buttonMapping); | ||
|
||
[MapDerivedType<DisabledMappingVm, DisabledMapping>] | ||
[MapDerivedType<NothingMappingVm, NothingMapping>] | ||
[MapDerivedType<SimulatedKeystrokeVm, SimulatedKeystroke>] | ||
[MapDerivedType<RightClickVm, RightClick>] | ||
public static partial ButtonMapping Map(BaseButtonMappingVm buttonMapping); | ||
|
||
[MapDerivedType<DisabledMappingVm, DisabledMapping>] | ||
[MapDerivedType<NothingMappingVm, NothingMapping>] | ||
[MapDerivedType<SimulatedKeystrokeVm, SimulatedKeystroke>] | ||
[MapDerivedType<RightClickVm, RightClick>] | ||
public static partial void Map(BaseButtonMappingVm src, ButtonMapping dst); | ||
|
||
public static BaseSimulatedKeystrokeTypeVm MapSimulatedKeystrokeType( | ||
SimulatedKeystrokeType simulatedKeystrokeType | ||
) => | ||
simulatedKeystrokeType switch | ||
{ | ||
SimulatedKeystrokeType.AsMousePressedAndReleasedActionType => | ||
new AsMousePressedAndReleasedActionTypeVm(), | ||
SimulatedKeystrokeType.DuringMouseActionType => new DuringMouseActionTypeVm(), | ||
SimulatedKeystrokeType.InAnotherThreadPressedActionType => | ||
new InAnotherThreadPressedActionTypeVm(), | ||
SimulatedKeystrokeType.InAnotherThreadReleasedActionType => | ||
new InAnotherThreadReleasedActionTypeVm(), | ||
SimulatedKeystrokeType.MouseButtonPressedActionType => | ||
new MouseButtonPressedActionTypeVm(), | ||
SimulatedKeystrokeType.MouseButtonReleasedActionType => | ||
new MouseButtonReleasedActionTypeVm(), | ||
SimulatedKeystrokeType.RepeatedlyWhileButtonDownActionType => | ||
new RepeatedlyWhileButtonDownActionTypeVm(), | ||
SimulatedKeystrokeType.StickyHoldActionType => new StickyHoldActionTypeVm(), | ||
SimulatedKeystrokeType.StickyRepeatActionType => new StickyRepeatActionTypeVm(), | ||
_ => throw new ArgumentOutOfRangeException( | ||
nameof(simulatedKeystrokeType), | ||
simulatedKeystrokeType, | ||
null | ||
), | ||
}; | ||
|
||
public static SimulatedKeystrokeType? MapSimulatedKeystrokeTypeVm( | ||
BaseSimulatedKeystrokeTypeVm? baseSimulatedKeystrokeVm | ||
) => | ||
baseSimulatedKeystrokeVm switch | ||
{ | ||
null => null, | ||
AsMousePressedAndReleasedActionTypeVm => | ||
SimulatedKeystrokeType.AsMousePressedAndReleasedActionType, | ||
DuringMouseActionTypeVm => SimulatedKeystrokeType.DuringMouseActionType, | ||
InAnotherThreadPressedActionTypeVm => | ||
SimulatedKeystrokeType.InAnotherThreadPressedActionType, | ||
InAnotherThreadReleasedActionTypeVm => | ||
SimulatedKeystrokeType.InAnotherThreadReleasedActionType, | ||
MouseButtonPressedActionTypeVm => SimulatedKeystrokeType.MouseButtonPressedActionType, | ||
MouseButtonReleasedActionTypeVm => SimulatedKeystrokeType.MouseButtonReleasedActionType, | ||
RepeatedlyWhileButtonDownActionTypeVm => | ||
SimulatedKeystrokeType.RepeatedlyWhileButtonDownActionType, | ||
StickyHoldActionTypeVm => SimulatedKeystrokeType.StickyHoldActionType, | ||
StickyRepeatActionTypeVm => SimulatedKeystrokeType.StickyRepeatActionType, | ||
_ => throw new ArgumentOutOfRangeException(), | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
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,25 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Riok.Mapperly.Abstractions; | ||
using YMouseButtonControl.Core.ViewModels.Models; | ||
using YMouseButtonControl.DataAccess.Models; | ||
|
||
namespace YMouseButtonControl.Core.Mappings; | ||
|
||
[Mapper] | ||
public static partial class ProfileMapper | ||
{ | ||
public static partial ProfileVm Map(Profile? profile); | ||
|
||
public static partial Profile Map(ProfileVm vm); | ||
|
||
public static partial void Map(ProfileVm src, Profile dst); | ||
|
||
private static List<BaseButtonMappingVm> MapButtonMapping( | ||
ICollection<ButtonMapping> buttonMappings | ||
) => buttonMappings.Select(ButtonMappingMapper.Map).ToList(); | ||
|
||
private static ICollection<ButtonMapping> MapButtonMappingVms( | ||
List<BaseButtonMappingVm> buttonMappings | ||
) => buttonMappings.Select(ButtonMappingMapper.Map).ToList(); | ||
} |
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 @@ | ||
using Riok.Mapperly.Abstractions; | ||
using YMouseButtonControl.Core.ViewModels.Models; | ||
using YMouseButtonControl.DataAccess.Models; | ||
|
||
namespace YMouseButtonControl.Core.Mappings; | ||
|
||
[Mapper] | ||
public static partial class SettingMapper | ||
{ | ||
[MapDerivedType<SettingString, SettingStringVm>] | ||
[MapDerivedType<SettingBool, SettingBoolVm>] | ||
[MapDerivedType<SettingInt, SettingIntVm>] | ||
public static partial BaseSettingVm Map(Setting? setting); | ||
|
||
[MapDerivedType<SettingStringVm, SettingString>] | ||
[MapDerivedType<SettingBoolVm, SettingBool>] | ||
[MapDerivedType<SettingIntVm, SettingInt>] | ||
public static partial Setting Map(BaseSettingVm baseSettingVm); | ||
|
||
[MapDerivedType<SettingStringVm, SettingString>] | ||
[MapDerivedType<SettingBoolVm, SettingBool>] | ||
[MapDerivedType<SettingIntVm, SettingInt>] | ||
public static partial void Map(BaseSettingVm src, Setting dst); | ||
} |
99 changes: 99 additions & 0 deletions
99
YMouseButtonControl.Core/Repositories/ButtonMappingRepository.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,99 @@ | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Dapper; | ||
using YMouseButtonControl.Core.Mappings; | ||
using YMouseButtonControl.Core.ViewModels.Models; | ||
using YMouseButtonControl.DataAccess.Context; | ||
using YMouseButtonControl.DataAccess.Models; | ||
using YMouseButtonControl.DataAccess.Queries; | ||
|
||
namespace YMouseButtonControl.Core.Repositories; | ||
|
||
public class ButtonMappingRepository(YMouseButtonControlDbContext ctx, ButtonMappingQueries queries) | ||
: IRepository<ButtonMapping, BaseButtonMappingVm> | ||
{ | ||
private readonly YMouseButtonControlDbContext _ctx = ctx; | ||
private const string TblName = "ButtonMappings"; | ||
|
||
public int Add(BaseButtonMappingVm vm) | ||
{ | ||
using var conn = _ctx.CreateConnection(); | ||
var ent = ButtonMappingMapper.Map(vm); | ||
ent.ButtonMappingType = ent switch | ||
{ | ||
DisabledMapping => ButtonMappingType.Disabled, | ||
NothingMapping => ButtonMappingType.Nothing, | ||
SimulatedKeystroke => ButtonMappingType.SimulatedKeystroke, | ||
RightClick => ButtonMappingType.RightClick, | ||
_ => throw new System.NotImplementedException(), | ||
}; | ||
return conn.Execute(queries.Add(), ent); | ||
} | ||
|
||
public async Task<int> AddAsync(BaseButtonMappingVm vm) | ||
{ | ||
using var conn = _ctx.CreateConnection(); | ||
return await conn.ExecuteAsync(queries.Add(), vm); | ||
} | ||
|
||
public BaseButtonMappingVm? GetById(int id) | ||
{ | ||
using var conn = _ctx.CreateConnection(); | ||
return ButtonMappingMapper.Map( | ||
conn.QueryFirstOrDefault<ButtonMapping>(queries.GetById(TblName), id) | ||
); | ||
} | ||
|
||
public async Task<BaseButtonMappingVm?> GetByIdAsync(int id) | ||
{ | ||
using var conn = _ctx.CreateConnection(); | ||
return ButtonMappingMapper.Map( | ||
await conn.QueryFirstOrDefaultAsync<ButtonMapping>(queries.GetById(TblName), id) | ||
); | ||
} | ||
|
||
public IEnumerable<BaseButtonMappingVm> GetAll() | ||
{ | ||
using var conn = _ctx.CreateConnection(); | ||
return conn.Query<ButtonMapping>(queries.GetAll(TblName)).Select(ButtonMappingMapper.Map); | ||
} | ||
|
||
public async Task<IEnumerable<BaseButtonMappingVm>> GetAllAsync() | ||
{ | ||
using var conn = _ctx.CreateConnection(); | ||
return (await conn.QueryAsync<ButtonMapping>(queries.GetAll(TblName))).Select( | ||
ButtonMappingMapper.Map | ||
); | ||
} | ||
|
||
public int Update(BaseButtonMappingVm vm) | ||
{ | ||
using var conn = _ctx.CreateConnection(); | ||
return conn.Execute(queries.Update(), vm); | ||
} | ||
|
||
public async Task<int> UpdateAsync(BaseButtonMappingVm vm) | ||
{ | ||
using var conn = _ctx.CreateConnection(); | ||
return await conn.ExecuteAsync(queries.Update(), vm); | ||
} | ||
|
||
public int Delete(BaseButtonMappingVm vm) | ||
{ | ||
using var conn = _ctx.CreateConnection(); | ||
return conn.Execute(queries.DeleteById(TblName), vm.Id); | ||
} | ||
|
||
public Task<int> DeleteAsync(BaseButtonMappingVm vm) | ||
{ | ||
using var conn = _ctx.CreateConnection(); | ||
return conn.ExecuteAsync(queries.DeleteById(TblName), vm.Id); | ||
} | ||
|
||
public BaseButtonMappingVm? GetByName(string name) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} |
Oops, something went wrong.