Skip to content

Commit

Permalink
1.0.0-RC-1
Browse files Browse the repository at this point in the history
  • Loading branch information
NatanAmorim committed Apr 18, 2024
1 parent 4b9d852 commit 5c51d08
Show file tree
Hide file tree
Showing 88 changed files with 4,418 additions and 813 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
87 changes: 87 additions & 0 deletions AutoMapperProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using AutoMapper;
using GsServer.Protobufs;
using GsServer.Models;

namespace GsServer.MapperProfile;

public class AutoMapperProfile : Profile
{
public AutoMapperProfile()
{
CreateMap<Attendance, GetAttendanceByIdResponse>()
.ForMember(dest => dest.AttendeesStatuses, src => src.MapFrom(src => src.AttendeesStatuses));
CreateMap<CreateAttendanceRequest, Attendance>()
.ForMember(dest => dest.AttendeesStatuses, src => src.MapFrom(src => src.AttendeesStatuses));
CreateMap<Models.AttendanceAttendeeStatus, Protobufs.AttendanceAttendeeStatus>();

CreateMap<Customer, GetCustomerByIdResponse>()
.ForMember(dest => dest.Dependents, src => src.MapFrom(src => src.Dependents));
CreateMap<Customer, CustomerOption>()
.ForMember(dest => dest.Dependents, src => src.MapFrom(src => src.Dependents));
CreateMap<CreateCustomerRequest, Customer>()
.ForMember(dest => dest.Dependents, src => src.MapFrom(src => src.Dependents));

CreateMap<Discipline, GetDisciplineByIdResponse>()
.ForMember(dest => dest.ClassDays, src => src.MapFrom(src => src.ClassDays));
CreateMap<CreateDisciplineRequest, Discipline>()
.ForMember(dest => dest.ClassDays, src => src.MapFrom(src => src.ClassDays));

CreateMap<Instructor, GetInstructorByIdResponse>();
CreateMap<Instructor, InstructorOption>();
CreateMap<CreateInstructorRequest, Instructor>();

CreateMap<Notification, GetNotificationByIdResponse>();
CreateMap<CreateNotificationRequest, Notification>();

// TODO
// CreateMap<Order, GetOrderByIdResponse>();
// CreateMap<CreateOrderRequest, Order>();
// CreateMap<Models.OrderStatus, Protobufs.OrderStatus>();

CreateMap<Payment, GetPaymentByIdResponse>()
.ForMember(dest => dest.Installments, src => src.MapFrom(src => src.Installments));
CreateMap<CreatePaymentRequest, Payment>()
.ForMember(dest => dest.Installments, src => src.MapFrom(src => src.Installments));
CreateMap<Models.PaymentInstallment, Protobufs.PaymentInstallment>();

CreateMap<Models.Person, Protobufs.Person>();

CreateMap<Product, GetProductByIdResponse>()
.ForMember(dest => dest.Variants, src => src.MapFrom(src => src.Variants));
CreateMap<CreateProductRequest, Product>()
.ForMember(dest => dest.Variants, src => src.MapFrom(src => src.Variants));
CreateMap<Models.ProductBrand, Protobufs.ProductBrand>();
CreateMap<Models.ProductCategory, Protobufs.ProductCategory>();
// TODO
// CreateMap<Models.ProductStockHistory, Protobufs.ProductStockHistory>();
CreateMap<Models.ProductVariant, Protobufs.ProductVariant>();
CreateMap<Models.ProductVariantInventory, Protobufs.ProductVariantInventory>();

CreateMap<Promotion, GetPromotionByIdResponse>();
CreateMap<CreatePromotionRequest, Promotion>();

CreateMap<Return, GetReturnByIdResponse>()
.ForMember(dest => dest.ItemsReturned, src => src.MapFrom(src => src.ItemsReturned));
CreateMap<CreateReturnRequest, Return>()
.ForMember(dest => dest.ItemsReturned, src => src.MapFrom(src => src.ItemsReturned));
CreateMap<Models.ReturnItem, Protobufs.ReturnItem>();

CreateMap<Sale, GetSaleByIdResponse>()
.ForMember(dest => dest.ItemsSold, src => src.MapFrom(src => src.ItemsSold));
CreateMap<CreateSaleRequest, Sale>()
.ForMember(dest => dest.ItemsSold, src => src.MapFrom(src => src.ItemsSold));
CreateMap<SaleBilling, GetSaleBillingByIdResponse>();
CreateMap<CreateSaleBillingRequest, SaleBilling>();
CreateMap<Models.SaleItem, Protobufs.SaleItem>();

CreateMap<Subscription, GetSubscriptionByIdResponse>();
CreateMap<CreateSubscriptionRequest, Subscription>();
CreateMap<SubscriptionBilling, GetSubscriptionBillingByIdResponse>();
CreateMap<CreateSubscriptionBillingRequest, SubscriptionBilling>();

CreateMap<User, GetUserByIdResponse>();
CreateMap<RegisterRequest, User>();

CreateMap<System.DayOfWeek, Protobufs.DayOfWeek>();
}
}
42 changes: 28 additions & 14 deletions BackgroundJobs/SubscriptionInvoiceBackgroundJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ namespace GsServer.BackgroundServices;
/// the customer should pay and may include detailed client information.
/// An invoice may indicate the existence of credit, as payment is not immediate.
/// </summary>
public class SubscriptionInvoiceBackgroundJob : BackgroundService
public class SubscriptionInvoiceBackgroundJob
(
ILogger<SubscriptionInvoiceBackgroundJob> logger
) : BackgroundService
{
private readonly ILogger<SubscriptionInvoiceBackgroundJob> _logger;
public SubscriptionInvoiceBackgroundJob(ILogger<SubscriptionInvoiceBackgroundJob> logger)
{
_logger = logger;
}
private readonly ILogger<SubscriptionInvoiceBackgroundJob> _logger = logger;

/// <summary>
/// Generates invoices in the background, runs daily at 12 AM UTC time.
Expand All @@ -25,27 +24,42 @@ protected async override Task ExecuteAsync(CancellationToken stoppingToken)
{
try
{
_logger.LogInformation("Background subscription invoice service started");
_logger.LogInformation(
"Executing Background Service: {BackgroundServiceName} started",
typeof(SubscriptionInvoiceBackgroundJob).Name
);

// Delay for Until 12 AM UTC time asynchronously.
// 9 AM BRT (Brasília Time), UTC/GMT -3 hours.
await Task.Delay((int)Math.Ceiling(MillisecondsUntilTwelveAmUtc()), stoppingToken);

_logger.LogInformation("Background subscription invoice service, generating invoices");
// TODO
// TODO store job in DB
_logger.LogInformation(
"Executing Background Service: {BackgroundServiceName}, generating invoices",
typeof(SubscriptionInvoiceBackgroundJob).Name
);
// TODO generate invoices

_logger.LogInformation("Background subscription invoice service, sending emails");
// TODO
_logger.LogInformation(
"Executing Background Service: {BackgroundServiceName}, sending notifications",
typeof(SubscriptionInvoiceBackgroundJob).Name
);
// TODO alert send emails or push notifications

_logger.LogInformation("Background subscription invoice service work completed");
_logger.LogInformation(
"Executing Background Service: {BackgroundServiceName} work completed",
typeof(SubscriptionInvoiceBackgroundJob).Name
);
// TODO Update `isCompleted = true;` in DB
}
catch (Exception Exception)
{
_logger.LogError(
"Background invoice service stopped because of an error {Exception}",
"Executing Background Service: {BackgroundServiceName} stopped because of an error {Exception}",
typeof(SubscriptionInvoiceBackgroundJob).Name,
Exception
);
// break; // TODO do I need to break?
break; // TODO do I need to break?
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ Todas as alterações notáveis ​​neste projeto serão documentadas neste ar
O formato é baseado em [Keep a Changelog (PT-BR)](https://keepachangelog.com/pt-BR/1.0.0/),
e este projeto adere a [Versionamento Semântico (PT-BR)](https://semver.org/lang/pt-BR/).

<!-- TODO
## 1.0.0-RC-1 (Mar XX, 2024)
- Finish implementation of gRPC with the new protobufs.
-->
## 1.0.0-RC-1 (Apr 18, 2024)

- Finish basic implementation of gRPC services with the new protobufs, some stuff will be implemented later, but it's not needed for critical functionality.
- Add Middleware `GlobalExceptionHandler` to be able to log and return even when unknown errors occur, but at the moment does not work with gRPC.
- Update protobufs from `a1d46b748` to `0adaf3a56`.

## 0.11.0-BETA (Mar 22, 2024)

Expand All @@ -27,8 +28,8 @@ e este projeto adere a [Versionamento Semântico (PT-BR)](https://semver.org/lan
## 0.10.0-BETA (Mar 22, 2024)

- Create "RequestTracerId" in every log using `HttpContext.TraceIdentifier`.
- Add Untested `AwsS3Service.cs`.
- Add Untested `AwsCloudWatch` for logging.
- Add **Untested** `AwsS3Service.cs`.
- Add **Untested** `AwsCloudWatch` for logging.
- Implement "DecimalValue" conversion to "C# Decimal".
- Update protobufs from `9e568008b` to `617c788f5`.

Expand Down
30 changes: 30 additions & 0 deletions CustomTypes/CalendarDate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace GsServer.Protobufs;

public partial class CalendarDate
{
public CalendarDate(int year, int month, int day)
{
Year = year;
Month = month;
Day = day;
}

public static implicit operator DateOnly(CalendarDate date)
{
return new DateOnly(
date.Year,
date.Month,
date.Day
);
}

public static implicit operator CalendarDate(DateOnly date)
{
return new CalendarDate()
{
Day = date.Day,
Month = date.Month,
Year = date.Year
};
}
}
31 changes: 31 additions & 0 deletions CustomTypes/DayOfWeek.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// namespace GsServer.Protobufs;

// public partial class DayOfWeek
// {
// public DayOfWeek()
// {
// // TODO
// }

// public static implicit operator DayOfWeek(Protobufs.DayOfWeek time)
// {
// return new System.DayOfWeek();
// }

// public static implicit operator DayOfWeek(System.DayOfWeek time)
// {
// return new Protobufs.DayOfWeek();
// }

// readonly Dictionary<DayOfWeek, System.DayOfWeek> DayOfWeekMapping = new()
// {
// { DayOfWeek.Sunday, System.DayOfWeek.Sunday },
// { DayOfWeek.Monday, System.DayOfWeek.Monday },
// { DayOfWeek.Tuesday, System.DayOfWeek.Tuesday },
// { DayOfWeek.Wednesday, System.DayOfWeek.Wednesday },
// { DayOfWeek.Thursday, System.DayOfWeek.Thursday },
// { DayOfWeek.Friday, System.DayOfWeek.Friday },
// { DayOfWeek.Saturday, System.DayOfWeek.Saturday }
// };
// }

27 changes: 27 additions & 0 deletions CustomTypes/TimeOfDay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace GsServer.Protobufs;

public partial class TimeOfDay
{
public TimeOfDay(int hour, int minute)
{
Hour = hour;
Minute = minute;
}

public static implicit operator TimeOnly(TimeOfDay time)
{
return new TimeOnly(
time.Hour,
time.Minute
);
}

public static implicit operator TimeOfDay(TimeOnly time)
{
return new TimeOfDay()
{
Hour = time.Hour,
Minute = time.Minute
};
}
}
67 changes: 38 additions & 29 deletions Data/DatabaseContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
global using Microsoft.EntityFrameworkCore;
using GsServer;
using GsServer.EntityConfigurations;
using GsServer.Models;

public class DatabaseContext(
Expand All @@ -13,39 +11,50 @@ IConfiguration configuration
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
/// This line should never be used in production and is only for debugging
// optionsBuilder.LogTo(str => Debug.WriteLine(str));
optionsBuilder.UseNpgsql(_configuration.GetConnectionString("db"));
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.UseSerialColumns();
modelBuilder.ApplyConfiguration(new AttendanceConfiguration());
modelBuilder.ApplyConfiguration(new CustomerConfiguration());
modelBuilder.ApplyConfiguration(new DisciplineConfiguration());
modelBuilder.ApplyConfiguration(new OrderConfiguration());
modelBuilder.ApplyConfiguration(new PersonConfiguration());
modelBuilder.ApplyConfiguration(new ProductConfiguration());
modelBuilder.ApplyConfiguration(new RefreshTokenConfiguration());
modelBuilder.ApplyConfiguration(new SaleConfiguration());
modelBuilder.ApplyConfiguration(new InstructorConfiguration());
modelBuilder.ApplyConfiguration(new UserConfiguration());
// modelBuilder.ApplyConfiguration(new AttendanceConfiguration());
// modelBuilder.ApplyConfiguration(new BackgroundJobConfiguration());
// modelBuilder.ApplyConfiguration(new CustomerConfiguration());
// modelBuilder.ApplyConfiguration(new DisciplineConfiguration());
// modelBuilder.ApplyConfiguration(new InstructorConfiguration());
// modelBuilder.ApplyConfiguration(new NotificationConfiguration());
// modelBuilder.ApplyConfiguration(new OrderConfiguration());
// modelBuilder.ApplyConfiguration(new PaymentConfiguration());
// modelBuilder.ApplyConfiguration(new PersonConfiguration());
// modelBuilder.ApplyConfiguration(new ProductConfiguration());
// modelBuilder.ApplyConfiguration(new PromotionConfiguration());
// modelBuilder.ApplyConfiguration(new RefreshTokenConfiguration());
// modelBuilder.ApplyConfiguration(new ReturnConfiguration());
// modelBuilder.ApplyConfiguration(new SaleConfiguration());
// modelBuilder.ApplyConfiguration(new SaleBillingConfiguration());
// modelBuilder.ApplyConfiguration(new SubscriptionConfiguration());
// modelBuilder.ApplyConfiguration(new SubscriptionBillingConfiguration());
// modelBuilder.ApplyConfiguration(new UserConfiguration());
}

public DbSet<AttendanceModel> Attendances => Set<AttendanceModel>();
public DbSet<BackgroundJobModel> BackgroundJobs => Set<BackgroundJobModel>();
public DbSet<CustomerModel> Customers => Set<CustomerModel>();
public DbSet<DisciplineModel> Disciplines => Set<DisciplineModel>();
public DbSet<InstructorModel> Instructors => Set<InstructorModel>();
public DbSet<NotificationModel> Notifications => Set<NotificationModel>();
public DbSet<OrderModel> Orders => Set<OrderModel>();
public DbSet<PaymentModel> Payments => Set<PaymentModel>();
public DbSet<PersonModel> People => Set<PersonModel>();
public DbSet<ProductModel> Products => Set<ProductModel>();
public DbSet<PromotionModel> Promotions => Set<PromotionModel>();
public DbSet<RefreshTokenModel> RefreshTokens => Set<RefreshTokenModel>();
public DbSet<SaleModel> Sales => Set<SaleModel>();
public DbSet<SaleBillingModel> SalesBilling => Set<SaleBillingModel>();
public DbSet<SubscriptionModel> Subscriptions => Set<SubscriptionModel>();
public DbSet<SubscriptionBillingModel> SubscriptionsBilling => Set<SubscriptionBillingModel>();
public DbSet<UserModel> Users => Set<UserModel>();
public DbSet<Attendance> Attendances => Set<Attendance>();
public DbSet<BackgroundJobStatus> BackgroundJobs => Set<BackgroundJobStatus>();
public DbSet<Customer> Customers => Set<Customer>();
public DbSet<Discipline> Disciplines => Set<Discipline>();
public DbSet<Instructor> Instructors => Set<Instructor>();
public DbSet<Notification> Notifications => Set<Notification>();
public DbSet<Order> Orders => Set<Order>();
public DbSet<Payment> Payments => Set<Payment>();
public DbSet<Person> Persons => Set<Person>(); // Yes, it could also be called "People"
public DbSet<Product> Products => Set<Product>();
public DbSet<Promotion> Promotions => Set<Promotion>();
public DbSet<RefreshToken> RefreshTokens => Set<RefreshToken>();
public DbSet<Return> Returns => Set<Return>();
public DbSet<Sale> Sales => Set<Sale>();
public DbSet<SaleBilling> SaleBillings => Set<SaleBilling>();
public DbSet<Subscription> Subscriptions => Set<Subscription>();
public DbSet<SubscriptionBilling> SubscriptionBillings => Set<SubscriptionBilling>();
public DbSet<User> Users => Set<User>();
}
Loading

0 comments on commit 5c51d08

Please sign in to comment.