Removed Firefly
This commit is contained in:
parent
744bfa8114
commit
095fcd88f4
@ -1,64 +0,0 @@
|
||||
namespace active_allocator.Controllers;
|
||||
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using active_allocator.Models.Accounts;
|
||||
using active_allocator.Services;
|
||||
using active_allocator.Authorization;
|
||||
using active_allocator.Helpers;
|
||||
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class FireFlyController : ControllerBase
|
||||
{
|
||||
private IFireFlyService _fireFlyService;
|
||||
private IMapper _mapper;
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
public FireFlyController(
|
||||
IFireFlyService fireFlyService,
|
||||
IMapper mapper,
|
||||
IOptions<AppSettings> appSettings)
|
||||
{
|
||||
_fireFlyService = fireFlyService;
|
||||
_mapper = mapper;
|
||||
_appSettings = appSettings.Value;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetAll()
|
||||
{
|
||||
var transactions = await _fireFlyService.GetAll();
|
||||
return Ok(transactions);
|
||||
}
|
||||
/*
|
||||
[HttpGet("{id}")]
|
||||
public IActionResult GetById(int id)
|
||||
{
|
||||
var account = _accountService.GetById(id);
|
||||
return Ok(account);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Create([FromBody]AccountCreateRequest model)
|
||||
{
|
||||
_accountService.Create(model);
|
||||
return Ok(new { message = "account created" });
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult Update(int id, [FromBody]AccountUpdateRequest model)
|
||||
{
|
||||
_accountService.Update(id, model);
|
||||
return Ok(new { message = "account updated" });
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public IActionResult Delete(int id)
|
||||
{
|
||||
_accountService.Delete(id);
|
||||
return Ok(new { message = "account deleted" });
|
||||
}*/
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace active_allocator.Models.FireFlyTransactions;
|
||||
|
||||
public class Attributes
|
||||
{
|
||||
public DateTime created_at { get; set; }
|
||||
public DateTime updated_at { get; set; }
|
||||
public string user { get; set; }
|
||||
public string group_title { get; set; }
|
||||
public List<Transaction> transactions { get; set; }
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
namespace active_allocator.Models.FireFlyTransactions;
|
||||
|
||||
public class Datum
|
||||
{
|
||||
public string type { get; set; }
|
||||
public string id { get; set; }
|
||||
public Attributes attributes { get; set; }
|
||||
public Links links { get; set; }
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
namespace active_allocator.Models.FireFlyTransactions;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
public class Links
|
||||
{
|
||||
[JsonProperty("0")]
|
||||
public _0 _0 { get; set; }
|
||||
public string self { get; set; }
|
||||
public string first { get; set; }
|
||||
public string next { get; set; }
|
||||
public string prev { get; set; }
|
||||
public string last { get; set; }
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
namespace active_allocator.Models.FireFlyTransactions;
|
||||
|
||||
public class Meta
|
||||
{
|
||||
public Pagination pagination { get; set; }
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace active_allocator.Models.FireFlyTransactions;
|
||||
|
||||
public class Pagination
|
||||
{
|
||||
public int total { get; set; }
|
||||
public int count { get; set; }
|
||||
public int per_page { get; set; }
|
||||
public int current_page { get; set; }
|
||||
public int total_pages { get; set; }
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace active_allocator.Models.FireFlyTransactions;
|
||||
|
||||
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
|
||||
|
||||
public class Root
|
||||
{
|
||||
public List<Datum> data { get; set; }
|
||||
public Meta meta { get; set; }
|
||||
public Links links { get; set; }
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
namespace active_allocator.Models.FireFlyTransactions;
|
||||
|
||||
public class Transaction
|
||||
{
|
||||
public string user { get; set; }
|
||||
public string transaction_journal_id { get; set; }
|
||||
public string type { get; set; }
|
||||
public DateTime date { get; set; }
|
||||
public int? order { get; set; }
|
||||
public string currency_id { get; set; }
|
||||
public string currency_code { get; set; }
|
||||
public string currency_symbol { get; set; }
|
||||
public string currency_name { get; set; }
|
||||
public int? currency_decimal_places { get; set; }
|
||||
public string foreign_currency_id { get; set; }
|
||||
public string foreign_currency_code { get; set; }
|
||||
public string foreign_currency_symbol { get; set; }
|
||||
public int? foreign_currency_decimal_places { get; set; }
|
||||
public string amount { get; set; }
|
||||
public string foreign_amount { get; set; }
|
||||
public string description { get; set; }
|
||||
public string source_id { get; set; }
|
||||
public string source_name { get; set; }
|
||||
public string source_iban { get; set; }
|
||||
public string source_type { get; set; }
|
||||
public string destination_id { get; set; }
|
||||
public string destination_name { get; set; }
|
||||
public string destination_iban { get; set; }
|
||||
public string destination_type { get; set; }
|
||||
public string budget_id { get; set; }
|
||||
public string budget_name { get; set; }
|
||||
public string category_id { get; set; }
|
||||
public string category_name { get; set; }
|
||||
public string bill_id { get; set; }
|
||||
public string bill_name { get; set; }
|
||||
public bool reconciled { get; set; }
|
||||
public string notes { get; set; }
|
||||
public object tags { get; set; }
|
||||
public string internal_reference { get; set; }
|
||||
public string external_id { get; set; }
|
||||
public string external_url { get; set; }
|
||||
public string original_source { get; set; }
|
||||
public int? recurrence_id { get; set; }
|
||||
public int? recurrence_total { get; set; }
|
||||
public int? recurrence_count { get; set; }
|
||||
public string bunq_payment_id { get; set; }
|
||||
public string import_hash_v2 { get; set; }
|
||||
public string sepa_cc { get; set; }
|
||||
public string sepa_ct_op { get; set; }
|
||||
public string sepa_ct_id { get; set; }
|
||||
public string sepa_db { get; set; }
|
||||
public string sepa_country { get; set; }
|
||||
public string sepa_ep { get; set; }
|
||||
public string sepa_ci { get; set; }
|
||||
public string sepa_batch_id { get; set; }
|
||||
public DateTime? interest_date { get; set; }
|
||||
public DateTime? book_date { get; set; }
|
||||
public DateTime? process_date { get; set; }
|
||||
public DateTime? due_date { get; set; }
|
||||
public DateTime? payment_date { get; set; }
|
||||
public DateTime? invoice_date { get; set; }
|
||||
public double? latitude { get; set; }
|
||||
public double? longitude { get; set; }
|
||||
public int? zoom_level { get; set; }
|
||||
public bool has_attachments { get; set; }
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace active_allocator.Models.FireFlyTransactions;
|
||||
|
||||
public class _0
|
||||
{
|
||||
public string rel { get; set; }
|
||||
public string uri { get; set; }
|
||||
}
|
@ -51,7 +51,6 @@ internal class Program
|
||||
builder.Services.AddScoped<IJwtUtils, JwtUtils>();
|
||||
builder.Services.AddScoped<IAccountService, AccountService>();
|
||||
builder.Services.AddScoped<ICurrencyTypeService, CurrencyTypeService>();
|
||||
builder.Services.AddScoped<IFireFlyService, FireFlyService>();
|
||||
builder.Services.AddScoped<ITransactionService, TransactionService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
@ -1,139 +0,0 @@
|
||||
namespace active_allocator.Services;
|
||||
|
||||
using AutoMapper;
|
||||
using BCrypt.Net;
|
||||
using active_allocator.Entities;
|
||||
using active_allocator.Helpers;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using Newtonsoft.Json;
|
||||
using Internal;
|
||||
using active_allocator.Models.FireFlyTransactions;
|
||||
|
||||
public interface IFireFlyService
|
||||
{
|
||||
Task<IEnumerable<Datum>> GetAll();/*
|
||||
Account GetById(int id);
|
||||
void Create(AccountCreateRequest model);
|
||||
void Update(int id, AccountUpdateRequest model);
|
||||
void Delete(int id);*/
|
||||
}
|
||||
|
||||
public class FireFlyService : IFireFlyService
|
||||
{
|
||||
private DataContext _context;
|
||||
private readonly IMapper _mapper;
|
||||
private string baseUrl = "http://10.0.10.21:8080/api/v1/";
|
||||
private string bearerToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiODc3ZTVlNzYyMDBiMTJiMDk2ZTQ5NjM2NWQyY2EwZjk5MmVjMzZkNGVjNmVjYjUzYTk4YzZjZTg2Y2I5N2JhMjNjODZjMDNlMDJiNDk3OWYiLCJpYXQiOjE2ODQ4NTgwODYuNjk0OTY4LCJuYmYiOjE2ODQ4NTgwODYuNjk0OTcxLCJleHAiOjE3MTY0ODA0ODYuNjI1MTA3LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.QbKdlv8h0Wqz-zd_hinX288SUWgiyEqDijHmO-6-JN2YN79GungzCddR169mjp9G-AIUykhQ3tOYKiQWSnreOLXZoWJDs6RX6MxqTZIvIFx-Fjt_5qaFt8D6pqm-LVs0j-c0xlW1BvGoZy-tHNnNbaH15vWuLN4sxsekbsfdcIq1JKsR5pYlI59SUdQzkISFjDCKqJaSCQM_lPAaYv9EEmf54yOy8hGHLQHdJmPyv-ngCar0KB5DKMimAof40FuQVMvYUueWxSej-NYp26ZXMRlRAU3A7qL2qVZA6R-Hh9wKkO8evyCrRoh3cQB1XaPMpJMN6E7m_7tsxHnOUNZ2fj0vW7LR4QKbgePhhpW6aXIrkH1_FkeMZn2MNrwoo1FuhEd3ij73K0-rbkikrKhW0G2hyqh0Lvf1HtU0kzWmOCNV9oqjHLm8fPAkcB1g8ngPcoc5ZdcEe1MF9ngJqwNvdQgqIsYr3SmWoY2G2ZVa7Fr3hn7-4D91DV5Pk_R52IfCPWqUvyPIoZfM6vGKuv4F9aGzcTotU69IJUr0-k780elzm1k7K2otYmskJe_xa4sW7E2-OYuFqD2TMBVp6j3rB6ZR5LCGZP9jETJsFis23JSzZpe0XAFf6SVi8BBOOoJxqyefZr-gdOdrZ6_5ffVKmVUbXzXQMEIC-GDz-2Vkbrs";
|
||||
|
||||
public FireFlyService(
|
||||
DataContext context,
|
||||
IMapper mapper)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Datum>> GetAll()
|
||||
{
|
||||
string endpointUrl = "transactions?page=";
|
||||
int totalPages = 1;
|
||||
List<Datum> transactions = new List<Datum>();
|
||||
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken);
|
||||
|
||||
for (int i = 1; i <= totalPages; i++)
|
||||
{
|
||||
using (var response = await httpClient.GetAsync(baseUrl + endpointUrl + i.ToString()))
|
||||
{
|
||||
string apiResponse = await response.Content.ReadAsStringAsync();
|
||||
Root payload = JsonConvert.DeserializeObject<Root>(apiResponse);
|
||||
|
||||
if (payload?.meta?.pagination != null)
|
||||
totalPages = payload.meta.pagination.total_pages;
|
||||
|
||||
transactions.AddRange(payload.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return transactions;
|
||||
}
|
||||
/*
|
||||
public Account GetById(int id)
|
||||
{
|
||||
return getAccount(id);
|
||||
}
|
||||
|
||||
public void Create(AccountCreateRequest model)
|
||||
{
|
||||
// Check that account with same name or same external number doesn't exist
|
||||
IEnumerable<Account> accountsWithSameName = _context.Accounts.Where(a => a.Name.ToUpper() == model.Name.ToUpper());
|
||||
|
||||
if (accountsWithSameName.Count() > 0)
|
||||
throw new AppException("Account with name '" + model.Name + "' already exists");
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(model.ExternalAccountNumber))
|
||||
{
|
||||
IEnumerable<Account> matches = _context.Accounts.Where(a => a.ExternalAccountNumber == model.ExternalAccountNumber);
|
||||
|
||||
if (matches.Count() > 0)
|
||||
throw new AppException("Account with external account number '" + model.ExternalAccountNumber + "' already exists under account named '" + matches.First().Name + "'");
|
||||
}
|
||||
|
||||
// map model to new account object
|
||||
//var account = _mapper.Map<Account>(model);
|
||||
|
||||
Account account = new Account {
|
||||
Name = model.Name,
|
||||
OwnerId = model.Owner,
|
||||
Owner = _userService.GetById(model.Owner),
|
||||
InitialBalance = Convert.ToDecimal(model.InitialBalance),
|
||||
Balance = Convert.ToDecimal(model.InitialBalance),
|
||||
LastActivity = DateTime.UtcNow,
|
||||
CreatedOn = DateTime.UtcNow,
|
||||
CurrencyId = model.Currency,
|
||||
Currency = _currencyTypeService.GetById(model.Currency),
|
||||
ExternalAccountNumber = model.ExternalAccountNumber
|
||||
};
|
||||
|
||||
_context.Accounts.Add(account);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
public void Update(int id, AccountUpdateRequest model)
|
||||
{
|
||||
var account = getAccount(id);
|
||||
|
||||
// validate
|
||||
if (model.Name != account.Name && _context.Accounts.Any(x => x.Name == model.Name))
|
||||
throw new AppException("Account with the name '" + model.Name + "' already exists");
|
||||
|
||||
// copy model to account and save
|
||||
_mapper.Map(model, account);
|
||||
_context.Accounts.Update(account);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
{
|
||||
var account = getAccount(id);
|
||||
_context.Accounts.Remove(account);
|
||||
_context.SaveChanges();
|
||||
}
|
||||
|
||||
// helper methods
|
||||
|
||||
private Account getAccount(int id)
|
||||
{
|
||||
var account = _context.Accounts.Find(id);
|
||||
if (account == null) throw new KeyNotFoundException("Account not found");
|
||||
return account;
|
||||
}*/
|
||||
}
|
@ -25,18 +25,15 @@ public class UserService : IUserService
|
||||
private DataContext _context;
|
||||
private IJwtUtils _jwtUtils;
|
||||
private readonly IMapper _mapper;
|
||||
private IFireFlyService _fireFlyService;
|
||||
|
||||
public UserService(
|
||||
DataContext context,
|
||||
IMapper mapper,
|
||||
IJwtUtils jwtUtils,
|
||||
IFireFlyService fireFlyService)
|
||||
IJwtUtils jwtUtils)
|
||||
{
|
||||
_context = context;
|
||||
_mapper = mapper;
|
||||
_jwtUtils = jwtUtils;
|
||||
_fireFlyService = fireFlyService;
|
||||
}
|
||||
|
||||
public AuthenticateResponse Authenticate(AuthenticateRequest model)
|
||||
@ -76,18 +73,6 @@ public class UserService : IUserService
|
||||
|
||||
public IEnumerable<User> GetAll()
|
||||
{
|
||||
/*foreach (Models.FireFlyTransactions.Datum item in _fireFlyService.GetAll())
|
||||
{
|
||||
Console.WriteLine($"Id: {item.id}");
|
||||
|
||||
foreach (Models.FireFlyTransactions.Transaction tr in item.attributes.transactions)
|
||||
{
|
||||
Console.WriteLine($"\t{Convert.ToDecimal(tr.amount)} Description: {tr.description}");
|
||||
}
|
||||
|
||||
Console.WriteLine("");
|
||||
}
|
||||
*/
|
||||
return _context.Users;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user