Skip to content

Commit

Permalink
Update Error Messages and Constants (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnhQuoc2906 committed Oct 24, 2023
1 parent 3bd852c commit 8447b19
Show file tree
Hide file tree
Showing 30 changed files with 284 additions and 141 deletions.
16 changes: 12 additions & 4 deletions Api/Controllers/ActivitiesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.AspNetCore.Mvc;
using RepositoryLayer.Repositories;
using ServiceLayer.Business;
using System.ComponentModel.DataAnnotations.Schema;
using WebApiLayer.UserFeatures.Requests;

namespace WebApiLayer.Controllers;
Expand All @@ -13,10 +14,15 @@ public class ActivitiesController : BaseController
{
private readonly IActivityServices _activityServices;
private readonly IGenericRepository<ActivityEntity> _activityRepo;
public ActivitiesController(IActivityServices activityServices, IGenericRepository<ActivityEntity> activityRepo)
private readonly IGenericRepository<ActivityTypeEntity> _activityTypeRepo;
private readonly IGenericRepository<TransactionEntity> _transactionRepo;
public ActivitiesController(IActivityServices activityServices, IGenericRepository<ActivityEntity> activityRepo
, IGenericRepository<ActivityTypeEntity> activityTypeRepo, IGenericRepository<TransactionEntity> transactionRepo)
{
_activityServices = activityServices;
_activityRepo = activityRepo;
_activityTypeRepo = activityTypeRepo;
_transactionRepo = transactionRepo;
}
[HttpGet]
public async Task<IActionResult> GetActivitíes()
Expand All @@ -33,6 +39,8 @@ public async Task<IActionResult> GetActivity(Guid id)
[HttpPost]
public async Task<IActionResult> CreateActivity([FromBody] CreateActivityRequest act)
{
await _activityTypeRepo.FoundOrThrowAsync(act.ActivityTypeId, Constants.ENTITY.ACTIVITY_TYPE + Constants.ERROR.NOT_EXIST_ERROR);
await _transactionRepo.FoundOrThrowAsync(act.TransactionId, Constants.ENTITY.TRANSACTION + Constants.ERROR.NOT_EXIST_ERROR);
var newAct = new ActivityEntity();
Mapper.Map(act, newAct);
await _activityServices.Create(newAct);
Expand All @@ -42,7 +50,7 @@ public async Task<IActionResult> CreateActivity([FromBody] CreateActivityRequest
[HttpPut("{id}")]
public async Task<IActionResult> UpdateActivity(Guid id, [FromBody] UpdateActivityRequest act)
{
var updateAct = await _activityRepo.FoundOrThrowAsync(id, "Activity not exist.");
var updateAct = await _activityRepo.FoundOrThrowAsync(id, Constants.ENTITY.ACTIVITY + Constants.ERROR.NOT_EXIST_ERROR);
Mapper.Map(act, updateAct);
await _activityServices.Update(updateAct);
return Ok(updateAct);
Expand All @@ -51,8 +59,8 @@ public async Task<IActionResult> UpdateActivity(Guid id, [FromBody] UpdateActivi
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteActivity(Guid id)
{
await _activityRepo.FoundOrThrowAsync(id, "Activity not exist.");
await _activityRepo.FoundOrThrowAsync(id, Constants.ENTITY.ACTIVITY + Constants.ERROR.NOT_EXIST_ERROR);
await _activityServices.Delete(id);
return NoContent();
}
}
}
20 changes: 14 additions & 6 deletions Api/Controllers/ActivityTypesController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using DomainLayer.Constants;
using AutoWrapper.Filters;
using DomainLayer.Constants;
using DomainLayer.Entities;
using DomainLayer.Exceptions;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -13,10 +14,15 @@ public class ActivityTypesController : BaseController
{
private readonly IActivityTypeServices _activityTypeServices;
private readonly IGenericRepository<ActivityTypeEntity> _activityTypeRepo;
public ActivityTypesController(IActivityTypeServices activityTypeServices, IGenericRepository<ActivityTypeEntity> activityTypeRepo)
private readonly IGenericRepository<GameEntity> _gameRepo;
private readonly IGenericRepository<CharacterEntity> _characterRepo;
public ActivityTypesController(IActivityTypeServices activityTypeServices, IGenericRepository<ActivityTypeEntity> activityTypeRepo
, IGenericRepository<GameEntity> gameRepo, IGenericRepository<CharacterEntity> characterRepo)
{
_activityTypeServices = activityTypeServices;
_activityTypeRepo = activityTypeRepo;
_gameRepo = gameRepo;
_characterRepo = characterRepo;
}
[HttpGet]
public async Task<IActionResult> GetActivityTypes()
Expand All @@ -33,16 +39,18 @@ public async Task<IActionResult> GetActivityType(Guid id)
[HttpPost]
public async Task<IActionResult> CreateActivityType([FromBody] CreateActivityTypeRequest activityType)
{
await _gameRepo.FoundOrThrowAsync(activityType.GameId, Constants.ENTITY.GAME + Constants.ERROR.NOT_EXIST_ERROR);
await _characterRepo.FoundOrThrowAsync(activityType.CharacterId, Constants.ENTITY.CHARACTER + Constants.ERROR.NOT_EXIST_ERROR);
var newActivityType = new ActivityTypeEntity();
Mapper.Map(activityType, newActivityType);
await _activityTypeServices.Create(newActivityType);
return CreatedAtAction("GetActivityType", new { id = newActivityType.Id }, newActivityType);
return CreatedAtAction(nameof(GetActivityType), new { id = newActivityType.Id }, newActivityType);
}

[HttpPut("{id}")]
public async Task<IActionResult> UpdateActivityType(Guid id, [FromBody] UpdateActivityTypeRequest activityType)
{
var updateActivityType = await _activityTypeRepo.FoundOrThrowAsync(id, "Activity type not exist.");
var updateActivityType = await _activityTypeRepo.FoundOrThrowAsync(id, Constants.ENTITY.ACTIVITY_TYPE + Constants.ERROR.NOT_EXIST_ERROR);
Mapper.Map(activityType, updateActivityType);
await _activityTypeServices.Update(updateActivityType);
return Ok(updateActivityType);
Expand All @@ -51,8 +59,8 @@ public async Task<IActionResult> UpdateActivityType(Guid id, [FromBody] UpdateAc
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteActivityType(Guid id)
{
await _activityTypeRepo.FoundOrThrowAsync(id, "Activity type not exist.");
await _activityTypeRepo.FoundOrThrowAsync(id, Constants.ENTITY.ACTIVITY_TYPE + Constants.ERROR.NOT_EXIST_ERROR);
await _activityTypeServices.Delete(id);
return NoContent();
}
}
}
15 changes: 11 additions & 4 deletions Api/Controllers/AssetAttributesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ public class AssetAttributesController : BaseController
{
private readonly IAssetAttributeServices _assetAttServices;
private readonly IGenericRepository<AssetAttributeEntity> _assetAttRepo;
public AssetAttributesController(IAssetAttributeServices assetAttServices, IGenericRepository<AssetAttributeEntity> assetAttRepo)
private readonly IGenericRepository<AssetEntity> _assetRepo;
private readonly IGenericRepository<AttributeGroupEntity> _attGrpRepo;
public AssetAttributesController(IAssetAttributeServices assetAttServices, IGenericRepository<AssetAttributeEntity> assetAttRepo
, IGenericRepository<AssetEntity> assetRepo, IGenericRepository<AttributeGroupEntity> attGrpRepo)
{
_assetAttServices = assetAttServices;
_assetAttRepo = assetAttRepo;
_assetRepo = assetRepo;
_attGrpRepo = attGrpRepo;
}

[HttpGet]
Expand All @@ -33,6 +38,8 @@ public async Task<IActionResult> GetAssetAttribute(Guid id)
[HttpPost]
public async Task<IActionResult> CreateAssetAttribute([FromBody] CreateAssetAttributeRequest assetAtt)
{
await _assetRepo.FoundOrThrowAsync(assetAtt.AssetId, Constants.ENTITY.ASSET + Constants.ERROR.NOT_EXIST_ERROR);
await _attGrpRepo.FoundOrThrowAsync(assetAtt.AttributeGroupId, Constants.ENTITY.ATTRIBUTE_GROUP + Constants.ERROR.NOT_EXIST_ERROR);
var newAssAtt = new AssetAttributeEntity();
Mapper.Map(assetAtt, newAssAtt);
await _assetAttServices.Create(newAssAtt);
Expand All @@ -42,7 +49,7 @@ public async Task<IActionResult> CreateAssetAttribute([FromBody] CreateAssetAttr
[HttpPut("{id}")]
public async Task<IActionResult> UpdateAssetAttribute(Guid id, [FromBody] UpdateAssetAttributeRequest assetAtt)
{
var updateAssAtt = await _assetAttRepo.FoundOrThrowAsync(id, "Asset attribute not exist.");
var updateAssAtt = await _assetAttRepo.FoundOrThrowAsync(id, Constants.ENTITY.ASSET_ATTRIBUTE + Constants.ERROR.NOT_EXIST_ERROR);
Mapper.Map(assetAtt, updateAssAtt);
await _assetAttServices.Update(updateAssAtt);
return Ok(updateAssAtt);
Expand All @@ -51,8 +58,8 @@ public async Task<IActionResult> UpdateAssetAttribute(Guid id, [FromBody] Update
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteAssetAttribute(Guid id)
{
await _assetAttRepo.FoundOrThrowAsync(id, "Asset attribute not exist.");
await _assetAttRepo.FoundOrThrowAsync(id, Constants.ENTITY.ASSET_ATTRIBUTE + Constants.ERROR.NOT_EXIST_ERROR);
await _assetAttServices.Delete(id);
return NoContent();
}
}
}
13 changes: 8 additions & 5 deletions Api/Controllers/AssetTypesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ public class AssetTypesController : BaseController
{
private readonly IAssetTypeServices _assetTypeServices;
private readonly IGenericRepository<AssetTypeEntity> _assetTypeRepo;
public AssetTypesController(IAssetTypeServices assetTypeServices, IGenericRepository<AssetTypeEntity> assetTypeRepo)
private readonly IGenericRepository<GameEntity> _gameRepo;
public AssetTypesController(IAssetTypeServices assetTypeServices, IGenericRepository<AssetTypeEntity> assetTypeRepo, IGenericRepository<GameEntity> gameRepo)
{
_assetTypeServices = assetTypeServices;
_assetTypeRepo = assetTypeRepo;
_gameRepo = gameRepo;
}

[HttpGet]
Expand All @@ -35,16 +37,17 @@ public async Task<IActionResult> GetAssetType(Guid id)
[HttpPost]
public async Task<IActionResult> CreateAssetType([FromBody] CreateAssetTypeRequest assetType)
{
await _gameRepo.FoundOrThrowAsync(assetType.GameId, Constants.ENTITY.GAME + Constants.ERROR.NOT_EXIST_ERROR);
var cAssetType = new AssetTypeEntity();
Mapper.Map(assetType, cAssetType);
await _assetTypeServices.Create(cAssetType);
return CreatedAtAction("GetAssetType", new {id = cAssetType.Id}, cAssetType);
return CreatedAtAction(nameof(GetAssetType), new { id = cAssetType.Id }, cAssetType);
}

[HttpPut("{id}")]
public async Task<IActionResult> UpdateAssetType(Guid id, [FromBody] UpdateAssetTypeRequest assetType)
{
var uAssetType = await _assetTypeRepo.FoundOrThrowAsync(id, "Asset Type not exist.");
var uAssetType = await _assetTypeRepo.FoundOrThrowAsync(id, Constants.ENTITY.ASSET_TYPE + Constants.ERROR.NOT_EXIST_ERROR);
Mapper.Map(assetType, uAssetType);
await _assetTypeServices.Update(uAssetType);
return Ok(uAssetType);
Expand All @@ -53,8 +56,8 @@ public async Task<IActionResult> UpdateAssetType(Guid id, [FromBody] UpdateAsset
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteAssetType(Guid id)
{
await _assetTypeRepo.FoundOrThrowAsync(id, "Asset Type not exist.");
await _assetTypeRepo.FoundOrThrowAsync(id, Constants.ENTITY.ASSET_TYPE + Constants.ERROR.NOT_EXIST_ERROR);
await _assetTypeServices.Delete(id);
return NoContent();
}
}
}
13 changes: 8 additions & 5 deletions Api/Controllers/AssetsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ public class AssetsController : BaseController
{
private readonly IAssetServices _assetServices;
private readonly IGenericRepository<AssetEntity> _assetRepo;
public AssetsController(IAssetServices assetServices, IGenericRepository<AssetEntity> assetRepo)
private readonly IGenericRepository<AssetTypeEntity> _assetTypeRepo;
public AssetsController(IAssetServices assetServices, IGenericRepository<AssetEntity> assetRepo, IGenericRepository<AssetTypeEntity> assetTypeRepo)
{
_assetServices = assetServices;
_assetRepo = assetRepo;
_assetTypeRepo = assetTypeRepo;
}

[HttpGet]
Expand All @@ -33,16 +35,17 @@ public async Task<IActionResult> GetAsset(Guid id)
[HttpPost]
public async Task<IActionResult> CreateAsset([FromBody] CreateAssetRequest asset)
{
await _assetTypeRepo.FoundOrThrowAsync(asset.AssetTypeId, Constants.ENTITY.ASSET_TYPE + Constants.ERROR.NOT_EXIST_ERROR);
var newAsset = new AssetEntity();
Mapper.Map(asset, newAsset);
await _assetServices.Create(newAsset);
return CreatedAtAction("GetAsset", new { id = newAsset.Id }, newAsset);
return CreatedAtAction(nameof(GetAsset), new { id = newAsset.Id }, newAsset);
}

[HttpPut("{id}")]
public async Task<IActionResult> UpdateAsset(Guid id, [FromBody] UpdateAssetRequest asset)
{
var updateAsset = await _assetRepo.FoundOrThrowAsync(id, "Asset not exist.");
var updateAsset = await _assetRepo.FoundOrThrowAsync(id, Constants.ENTITY.ASSET + Constants.ERROR.NOT_EXIST_ERROR);
Mapper.Map(asset, updateAsset);
await _assetServices.Update(updateAsset);
return Ok(updateAsset);
Expand All @@ -51,8 +54,8 @@ public async Task<IActionResult> UpdateAsset(Guid id, [FromBody] UpdateAssetRequ
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteAsset(Guid id)
{
await _assetRepo.FoundOrThrowAsync(id, "Asset not exist.");
await _assetRepo.FoundOrThrowAsync(id, Constants.ENTITY.ASSET + Constants.ERROR.NOT_EXIST_ERROR);
await _assetServices.Delete(id);
return NoContent();
}
}
}
10 changes: 5 additions & 5 deletions Api/Controllers/AttributeGroupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,25 @@ public async Task<IActionResult> GetAttributeGroup(Guid id)
public async Task<IActionResult> CreateAttributeGroup([FromBody] CreateAttributeGroupRequest attributeGroup)
{
var attGrpEnt = new AttributeGroupEntity();
Mapper.Map(attributeGroup,attGrpEnt);
Mapper.Map(attributeGroup, attGrpEnt);
await _attributeServices.Create(attGrpEnt);
return CreatedAtAction(nameof(GetAttributeGroup), new { id = attGrpEnt.Id }, attGrpEnt);
}

[HttpPut("{id}")]
public async Task<IActionResult> UpdateAttributeGroup(Guid id, [FromBody] UpdateAttributeGroupRequest attributeGroup)
{
var attGrpEnt = await _attributeRepo.FoundOrThrowAsync(id, "Attribute Group not exist.");
var attGrpEnt = await _attributeRepo.FoundOrThrowAsync(id, Constants.ENTITY.ATTRIBUTE_GROUP + Constants.ERROR.NOT_EXIST_ERROR);
Mapper.Map(attributeGroup, attGrpEnt);
await _attributeServices.Update(attGrpEnt);
return Ok(attGrpEnt);
}

[HttpDelete("{id}")]
public async Task<IActionResult> Delete(Guid id)
public async Task<IActionResult> DeleteAttributeGroup(Guid id)
{
await _attributeRepo.FoundOrThrowAsync(id, "Attribute Group not exist.");
await _attributeRepo.FoundOrThrowAsync(id, Constants.ENTITY.ATTRIBUTE_GROUP + Constants.ERROR.NOT_EXIST_ERROR);
await _attributeServices.Delete(id);
return NoContent();
}
}
}
17 changes: 12 additions & 5 deletions Api/Controllers/CharacterAssetsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ public class CharacterAssetsController : BaseController
{
private readonly ICharacterAssetServices _characterAssetServices;
private readonly IGenericRepository<CharacterAssetEntity> _characterAssetRepo;
public CharacterAssetsController(ICharacterAssetServices characterAssetServices, IGenericRepository<CharacterAssetEntity> characterAssetRepo)
private readonly IGenericRepository<AssetEntity> _assetRepo;
private readonly IGenericRepository<CharacterEntity> _characterRepo;
public CharacterAssetsController(ICharacterAssetServices characterAssetServices, IGenericRepository<CharacterAssetEntity> characterAssetRepo
, IGenericRepository<AssetEntity> assetRepo, IGenericRepository<CharacterEntity> characterRepo)
{
_characterAssetServices = characterAssetServices;
_characterAssetRepo = characterAssetRepo;
_assetRepo = assetRepo;
_characterRepo = characterRepo;
}
[HttpGet]
public async Task<IActionResult> GetCharacterAssets()
Expand All @@ -34,16 +39,18 @@ public async Task<IActionResult> GetCharacterAsset(Guid id)
[HttpPost]
public async Task<IActionResult> CreateCharacterAsset([FromBody] CreateCharacterAssetRequest charAss)
{
await _assetRepo.FoundOrThrowAsync(charAss.AssetsId, Constants.ENTITY.ASSET + Constants.ERROR.NOT_EXIST_ERROR);
await _characterRepo.FoundOrThrowAsync(charAss.CharacterId, Constants.ENTITY.CHARACTER + Constants.ERROR.NOT_EXIST_ERROR);
var newCharAss = new CharacterAssetEntity();
Mapper.Map(charAss, newCharAss);
await _characterAssetServices.Create(newCharAss);
return CreatedAtAction("GetCharacterAsset", new {id = newCharAss.Id}, newCharAss);
return CreatedAtAction(nameof(GetCharacterAsset), new { id = newCharAss.Id }, newCharAss);
}

[HttpPut("{id}")]
public async Task<IActionResult> UpdateCharacterAsset(Guid id, [FromBody] UpdateCharacterAssetRequest charAss)
{
var updateCharAss = await _characterAssetRepo.FoundOrThrowAsync(id,"Character Asset not exist");
var updateCharAss = await _characterAssetRepo.FoundOrThrowAsync(id, Constants.ENTITY.CHARACTER_ASSET + Constants.ERROR.NOT_EXIST_ERROR);
Mapper.Map(charAss, updateCharAss);
await _characterAssetServices.Update(updateCharAss);
return Ok(updateCharAss);
Expand All @@ -52,8 +59,8 @@ public async Task<IActionResult> UpdateCharacterAsset(Guid id, [FromBody] Update
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteCharacterAsset(Guid id)
{
await _characterAssetRepo.FoundOrThrowAsync(id, "Character Asset not exist");
await _characterAssetRepo.FoundOrThrowAsync(id, Constants.ENTITY.CHARACTER_ASSET + Constants.ERROR.NOT_EXIST_ERROR);
await _characterAssetServices.Delete(id);
return NoContent();
}
}
}
Loading

0 comments on commit 8447b19

Please sign in to comment.