Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions 0.API/ROAPI.Api/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:64767",
"sslPort": 44301
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Api": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
13 changes: 7 additions & 6 deletions 0.Api/ROAPI.Api/Controllers/Account/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public AccountController(ILoginService loginService, IMapper mapper, IConfigurat
_ragnarokConfigurations = configurationService.GetRagnarokConfigurations();
_httpContextAccessor = httpContextAccessor;
}
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesErrorResponseType(typeof(AccountModel))]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(statusCode: StatusCodes.Status200OK, type: typeof(AccountModel))]
[ProducesResponseType(statusCode: StatusCodes.Status404NotFound, type: typeof(Nullable))]
[ProducesResponseType(statusCode: StatusCodes.Status401Unauthorized, type: typeof(Nullable))]
[HttpGet]
public async Task<ActionResult<AccountModel>> Get()
{
Expand All @@ -59,9 +59,8 @@ public async Task<ActionResult<AccountModel>> Get()
return NotFound();

}
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesErrorResponseType(typeof(AccessTokenModel))]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(statusCode: StatusCodes.Status200OK, type: typeof(AccessTokenModel))]
[ProducesResponseType(statusCode: StatusCodes.Status400BadRequest, type: typeof(AccessTokenModel))]
[AllowAnonymous]
[HttpPost("Login")]
public async Task<ActionResult<AccessTokenModel>> Login(
Expand Down Expand Up @@ -115,6 +114,7 @@ public async Task<ActionResult<AccessTokenModel>> Login(

}
}

[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[AllowAnonymous]
Expand All @@ -139,6 +139,7 @@ private async Task<AccessTokenModel> GenerateToken(
new[] {
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString("N")),
new Claim("user", login),
new Claim("accountId", account.account_id.ToString()),
new Claim(ClaimTypes.Role, account.group_id.ToString())
}
);
Expand Down
112 changes: 112 additions & 0 deletions 0.Api/ROAPI.Api/Controllers/Characters/CharacterController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.Mvc;
using ROAPI.Api.Models.Character;
using ROAPI.Application.Character.Dtos;
using ROAPI.Application.Character.Interfaces;

namespace ROAPI.Api.Controllers.Characters
{
[Authorize("Bearer")]
[Route("api/[controller]")]
[ApiController]
public class CharacterController : ControllerBase
{
private readonly ICharacterService _characterService;
private readonly IMapper _mapper;
private readonly ClaimsIdentity _identity;
private readonly int _accountId;

public CharacterController(ICharacterService characterService, IMapper mapper)
{
_identity = HttpContext.User.Identity as ClaimsIdentity;
int.TryParse(_identity.Claims.Where(s => s.Type.ToLower() == "accountid").FirstOrDefault()?.Value, out _accountId);
_characterService = characterService;
_mapper = mapper;
}
[ProducesResponseType(statusCode: StatusCodes.Status200OK, type: typeof(List<CharacterModel>))]
[ProducesResponseType(statusCode: StatusCodes.Status404NotFound, type: typeof(Nullable))]
[HttpGet("Getcharbyaccountid/{accountId}")]
[Authorize(Roles = "99")]
public async Task<ActionResult<List<CharacterModel>>> GetByAccountId([FromBody]int accountId)
{
var characters = await _characterService.GetCharsByAccountId(accountId);
if (characters != null)
return Ok(_mapper.Map<List<CharacterModel>>(characters));
else
return NotFound();
}
[ProducesResponseType(statusCode: StatusCodes.Status200OK, type: typeof(CharacterModel))]
[ProducesResponseType(statusCode: StatusCodes.Status404NotFound, type: typeof(Nullable))]
[HttpGet("Getcharbyid/{id}")]
public async Task<ActionResult<CharacterModel>> GetByCharId([FromBody]int charId)
{
var character = await _characterService.GetChar(charId);
if (_identity.Claims.Where(s => s.Type.ToLower() == "roles").FirstOrDefault()?.Value != "99")
{
if (character.accountId != _accountId)
return new StatusCodeResult(StatusCodes.Status401Unauthorized);
}
if (character != null)
return Ok(_mapper.Map<CharacterModel>(character));
else
return NotFound();
}
[ProducesResponseType(statusCode: StatusCodes.Status200OK, type: typeof(List<CharacterModel>))]
[ProducesResponseType(statusCode: StatusCodes.Status404NotFound, type: typeof(Nullable))]
[HttpGet("GetChars")]
public async Task<ActionResult<List<CharacterModel>>> GetChars(bool paged = false, int page = 1, int pageSize = 10)
{
if (_accountId == 0)
return NotFound();
var characters = paged?
await _characterService.GetCharsByAccountId(_accountId, page, pageSize) :
await _characterService.GetCharsByAccountId(_accountId);

return Ok(_mapper.Map<List<CharacterModel>>(characters));
}
[ProducesResponseType(statusCode: StatusCodes.Status200OK, type: typeof(List<CharacterModel>))]
[ProducesResponseType(statusCode: StatusCodes.Status404NotFound, type: typeof(Nullable))]
[HttpGet("GetList")]
[Authorize(Roles = "99")]
public async Task<ActionResult<List<CharacterModel>>> GetList(bool paged = false, int page = 1, int pageSize = 10)
{
var characters = paged ?
await _characterService.GetChars(page, pageSize) :
await _characterService.GetChars();
if (characters != null)
return Ok(_mapper.Map<List<CharacterModel>>(characters));
else
return NotFound();
}
[ProducesResponseType(statusCode: StatusCodes.Status200OK, type: typeof(CharacterModel))]
[ProducesResponseType(statusCode: StatusCodes.Status304NotModified)]
[HttpPatch("Edit/{characterId}")]
public async Task<ActionResult<CharacterModel>> Patch(int characterId, [FromBody]JsonPatchDocument<CharacterModel> model)
{

var actualDto = await _characterService.GetChar(characterId);
if(_identity.Claims.Where(s => s.Type.ToLower() == "roles").FirstOrDefault()?.Value != "99")
{
if (actualDto.accountId != _accountId)
return new StatusCodeResult(StatusCodes.Status401Unauthorized);
}
if(actualDto == null && actualDto.charId != characterId)
return new StatusCodeResult(304);
var actualModel = _mapper.Map<CharacterModel>(actualDto);
model.ApplyTo(actualModel);
var result = await _characterService.Updatecharacter(_mapper.Map<CharacterDto>(actualModel));
if(result == null)
return new StatusCodeResult(304);
return Ok(_mapper.Map<CharacterModel>(result));

}
}
}
7 changes: 5 additions & 2 deletions 0.Api/ROAPI.Api/Extensions/AddConnectionDbExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ public static class AddConnectionDbExtension
{
public static void AddConnectionDbService(this IServiceCollection services, IConfiguration configuration )
{
services.AddDbContext<MainDbContext>(options =>
services.AddDbContext<MainDbContext>(options => {
options.UseMySql(
configuration.GetConnectionString("MainConnection")));
configuration.GetConnectionString("MainConnection"));
//options.EnableSensitiveDataLogging();
//options.EnableDetailedErrors();
});
services.AddDbContext<LogDbContext>(options =>
options.UseMySql(
configuration.GetConnectionString("LogConnection")));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.Extensions.DependencyInjection;
using ROAPI.Application.Character.Interfaces;
using ROAPI.Application.Character.Services;
using ROAPI.Domain.Character.Contracts.Repositories;
using ROAPI.Domain.Character.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ROAPI.Api.Extensions.Depencies
{
public static class CharacterDependenciesExtension
{
public static IServiceCollection AddCharacterDependencies(this IServiceCollection services)
{
//Domain
services.AddTransient<ICharacterRepository, CharacterRepository>();

//Application
services.AddScoped<ICharacterService, CharacterService>();

return services;
}
}
}
58 changes: 58 additions & 0 deletions 0.Api/ROAPI.Api/Mappings/CharacterMapping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using AutoMapper;
using ROAPI.Api.Models.Character;
using ROAPI.Application.Character.Dtos;
using ROAPI.Data.Data.Entities.Character;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ROAPI.Api.Mappings
{
public class CharacterMapping:Profile
{
public CharacterMapping()
{
CreateMap<CharacterModel, CharacterDto>()
.ReverseMap();
CreateMap<CharacterDto, CharacterEntity>()
.ForMember(dest => dest.account_id, opt => opt.MapFrom(src => src.accountId))
.ForMember(dest => dest.char_id, opt => opt.MapFrom(src => src.charId))
.ForMember(dest => dest.char_num, opt => opt.MapFrom(src => src.charNum))
.ForMember(dest => dest.base_exp, opt => opt.MapFrom(src => src.baseExp))
.ForMember(dest => dest.base_level, opt => opt.MapFrom(src => src.baseLevel))
.ForMember(dest => dest.clan_id, opt => opt.MapFrom(src => src.clanId))
.ForMember(dest => dest.clothes_color, opt => opt.MapFrom(src => src.clothesColor))
.ForMember(dest => dest.delete_date, opt => opt.MapFrom(src => src.deleteDate))
.ForMember(dest => dest.elemental_id, opt => opt.MapFrom(src => src.elementalId))
.ForMember(dest => dest.guild_id, opt => opt.MapFrom(src => src.guildId))
.ForMember(dest => dest.hair_color, opt => opt.MapFrom(src => src.hairColor))
.ForMember(dest => dest.head_bottom, opt => opt.MapFrom(src => src.headBottom))
.ForMember(dest => dest.head_mid, opt => opt.MapFrom(src => src.headMid))
.ForMember(dest => dest.head_top, opt => opt.MapFrom(src => src.headTop))
.ForMember(dest => dest.homun_id, opt => opt.MapFrom(src => src.homunId))
.ForMember(dest => dest.hotkey_rowshift, opt => opt.MapFrom(src => src.hotkeyRowshift))
.ForMember(dest => dest.job_exp, opt => opt.MapFrom(src => src.jobExp))
.ForMember(dest => dest.job_level, opt => opt.MapFrom(src => src.jobLevel))
.ForMember(dest => dest.last_login, opt => opt.MapFrom(src => src.lastLogin))
.ForMember(dest => dest.last_map, opt => opt.MapFrom(src => src.lastMap))
.ForMember(dest => dest.last_x, opt => opt.MapFrom(src => src.lastX))
.ForMember(dest => dest.last_y, opt => opt.MapFrom(src => src.lastY))
.ForMember(dest => dest.max_hp, opt => opt.MapFrom(src => src.maxHp))
.ForMember(dest => dest.max_sp, opt => opt.MapFrom(src => src.maxSp))
.ForMember(dest => dest.partner_id, opt => opt.MapFrom(src => src.partnerId))
.ForMember(dest => dest.party_id, opt => opt.MapFrom(src => src.partyId))
.ForMember(dest => dest.pet_id, opt => opt.MapFrom(src => src.petId))
.ForMember(dest => dest.save_map, opt => opt.MapFrom(src => src.saveMap))
.ForMember(dest => dest.save_x, opt => opt.MapFrom(src => src.saveX))
.ForMember(dest => dest.save_y, opt => opt.MapFrom(src => src.saveY))
.ForMember(dest => dest.show_equip, opt => opt.MapFrom(src => src.showEquip))
.ForMember(dest => dest.skill_point, opt => opt.MapFrom(src => src.skillPoint))
.ForMember(dest => dest.status_point, opt => opt.MapFrom(src => src.statusPoint))
.ForMember(dest => dest.title_id, opt => opt.MapFrom(src => src.titleId))
.ForMember(dest => dest.unban_time, opt => opt.MapFrom(src => src.unbanTime))
.ForMember(dest => dest.uniqueitem_counter, opt => opt.MapFrom(src => src.uniqueitemCounter))
.ReverseMap();
}
}
}
75 changes: 75 additions & 0 deletions 0.Api/ROAPI.Api/Models/Character/CharacterModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ROAPI.Api.Models.Character
{
public class CharacterModel
{
public int CharId { get; set; }
public int AccountId { get; set; }
public int CharNum { get; set; }
public string Name { get; set; }
public int Class { get; set; }
public int BaseLevel { get; set; }
public int JobLevel { get; set; }
public long BaseExp { get; set; }
public long JobExp { get; set; }
public long Zeny { get; set; }
public int Str { get; set; }
public int Agi { get; set; }
public int Vit { get; set; }
public int Int { get; set; }
public int Dex { get; set; }
public int Luk { get; set; }
public int MaxHp { get; set; }
public int Hp { get; set; }
public int MaxSp { get; set; }
public int Sp { get; set; }
public int StatusPoint { get; set; }
public int SkillPoint { get; set; }
public int Option { get; set; }
public int Karma { get; set; }
public int Manner { get; set; }
public int PartyId { get; set; }
public int GuildId { get; set; }
public int PetId { get; set; }
public int HomunId { get; set; }
public int ElementalId { get; set; }
public int Hair { get; set; }
public int HairColor { get; set; }
public int ClothesColor { get; set; }
public int Body { get; set; }
public int Weapon { get; set; }
public int Shield { get; set; }
public int HeadTop { get; set; }
public int HeadMid { get; set; }
public int HeadBottom { get; set; }
public int Robe { get; set; }
public string LastMap { get; set; }
public int LastX { get; set; }
public int LastY { get; set; }
public string SaveMap { get; set; }
public int SaveX { get; set; }
public int SaveY { get; set; }
public int PartnerId { get; set; }
public int Online { get; set; }
public int Father { get; set; }
public int Mother { get; set; }
public int Child { get; set; }
public int Fame { get; set; }
public int Rename { get; set; }
public int DeleteDate { get; set; }
public int Moves { get; set; }
public int UnbanTime { get; set; }
public int Font { get; set; }
public int UniqueitemCounter { get; set; }
public string Sex { get; set; }
public int HotkeyRowshift { get; set; }
public int? ClanId { get; set; }
public DateTime? LastLogin { get; set; }
public int TitleId { get; set; }
public int ShowEquip { get; set; }
}
}
27 changes: 27 additions & 0 deletions 0.Api/ROAPI.Api/Properties/PublishProfiles/CustomProfile.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>luan122-001-site4.atempurl.com/swagger</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<TargetFramework>netcoreapp2.2</TargetFramework>
<ProjectGuid>3f17e218-9c69-463f-9b9e-c62bde97a03b</ProjectGuid>
<SelfContained>false</SelfContained>
<_IsPortable>true</_IsPortable>
<MSDeployServiceURL>https://luan122-001-site4.atempurl.com:8172/MsDeploy.axd?site=luan122-001-site4</MSDeployServiceURL>
<DeployIisAppPath>luan122-001-site4</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>luan122-001</UserName>
<_SavePWD>True</_SavePWD>
</PropertyGroup>
</Project>
Loading