Skip to content
Merged
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
10 changes: 5 additions & 5 deletions Back-End/Workflows/pr.yml → .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ jobs:
call-external-service:
runs-on: ubuntu-latest
steps:
- name: Chamar API para processar PR
- name: Chamar API PR AI
run: |
curl -X POST \
-H "Content-Type: application/json" \
-H "X-API-TOKEN: ${{ secrets.GITHUB_TOKEN }}" \
-H "X-API-TOKEN: ${{ secrets.PRAI_API_TOKEN }}" \
-d '{
"repository": "${{ github.repository }}",
"pr_number": ${{ github.event.pull_request.number }},
"pr_url": "${{ github.event.pull_request.url }}",
"diff_url": "${{ github.event.pull_request.diff_url }}"
"email": ${{ secrets.email }},
"password": "${{ secrets.password }}",
}' \
https://b70c040bdbc5.ngrok-free.app/api/prai/gen
https://api.softwareai.site/api/prai/gen
39 changes: 38 additions & 1 deletion Back-End/Models/postgreSQL.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import bcrypt
from datetime import datetime, timedelta
import secrets

import json
from sqlalchemy import Numeric

TOKEN_DEFAULT_EXPIRES_DAYS = 30

Expand Down Expand Up @@ -96,3 +97,39 @@ class SystemSettings(db.Model):
enable_logging = db.Column(db.Boolean, default=True)
log_level = db.Column(db.String(50), default='INFO')
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)


class Invoice(db.Model):
__tablename__ = 'invoices'

id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=True)
number = db.Column(db.String(64), nullable=False) # número/identificador da fatura
date = db.Column(db.DateTime, default=datetime.utcnow)
amount = db.Column(Numeric(12, 2), nullable=False, default=0.0)
currency = db.Column(db.String(8), default='BRL')
status = db.Column(db.String(32), default='pending') # paid, pending, failed
plan_name = db.Column(db.String(128), nullable=True)
pdf_path = db.Column(db.String(500), nullable=True) # path relativo em ./invoices/ ou None
pdf_url = db.Column(db.String(1000), nullable=True) # opcional: url externa se armazenada em S3 etc.
lines = db.Column(db.Text, nullable=True) # JSON serializado com itens [{description, qty, price}, ...]
created_at = db.Column(db.DateTime, default=datetime.utcnow)
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)

def to_dict(self, include_lines=False):
data = {
"id": str(self.id),
"number": self.number,
"date": self.date.isoformat() if self.date else None,
"amount": float(self.amount) if self.amount is not None else 0.0,
"currency": self.currency,
"status": self.status,
"planName": self.plan_name,
"pdfUrl": self.pdf_url or (f"/api/invoices/{self.id}/download" if self.pdf_path else None)
}
if include_lines:
try:
data["lines"] = json.loads(self.lines) if self.lines else []
except Exception:
data["lines"] = []
return data
48 changes: 0 additions & 48 deletions Back-End/Modules/Resolvers/user_plan.py

This file was deleted.

47 changes: 47 additions & 0 deletions Back-End/TestDiscovery/seed_invoices_for_freitas.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
docker exec -i meu_postgres2 psql -U postgres -d meubanco <<'SQL'
-- seed_invoices_for_freitas.sql
BEGIN;

-- 1) garante que o usuário exista (insere se não existir) e retorna id em CTE
WITH upsert_user AS (
INSERT INTO users (email, username, password_hash, created_at, plan_name, limit_monthly_tokens, tokens_used, acess_token, expires_at)
VALUES (
'freitasalexandre815@gmail.com',
'freitasalexandre',
'<bcrypt-placeholder>',
NOW(),
'Pro',
1000000,
1234,
'testtoken-inv-5000',
NOW() + INTERVAL '30 days'
)
ON CONFLICT (email) DO UPDATE
SET username = EXCLUDED.username
RETURNING id
), uid AS (
SELECT id FROM upsert_user
UNION ALL
SELECT id FROM users WHERE email = 'freitasalexandre815@gmail.com' LIMIT 1
)

-- 2) Insere 3 faturas somente se não existirem com o mesmo número para esse usuário
INSERT INTO invoices (user_id, number, date, amount, currency, status, plan_name, pdf_path, pdf_url, lines, created_at, updated_at)
SELECT uid.id, v.number, v.date, v.amount, v.currency, v.status, v.plan_name, v.pdf_path, v.pdf_url, v.lines, v.created_at, v.updated_at
FROM uid
CROSS JOIN (
VALUES
('INV-2025-0001', NOW() - INTERVAL '10 days', 49.90, 'BRL', 'paid', 'Pro', 'invoice-2025-0001.pdf', NULL, '[{"description":"Assinatura mensal Pro","qty":1,"price":49.90}]', NOW() - INTERVAL '10 days', NOW() - INTERVAL '10 days'),
('INV-2025-0002', NOW() - INTERVAL '5 days', 49.90, 'BRL', 'pending', 'Pro', NULL, NULL, '[{"description":"Renovação pendente - Pro","qty":1,"price":49.90}]', NOW() - INTERVAL '5 days', NOW() - INTERVAL '5 days'),
('INV-2025-0003', NOW() - INTERVAL '30 days', 249.00, 'BRL', 'paid', 'Business', NULL, 'https://example-bucket.s3.amazonaws.com/invoice-2025-0003.pdf', '[{"description":"Assinatura anual Business","qty":1,"price":249.00}]', NOW() - INTERVAL '30 days', NOW() - INTERVAL '30 days')
) AS v(number, date, amount, currency, status, plan_name, pdf_path, pdf_url, lines, created_at, updated_at)
WHERE NOT EXISTS (
SELECT 1 FROM invoices i WHERE i.number = v.number AND i.user_id = uid.id
);

-- 3) Ajusta sequences
SELECT setval(pg_get_serial_sequence('users','id'), (SELECT COALESCE(MAX(id),1) FROM users));
SELECT setval(pg_get_serial_sequence('invoices','id'), (SELECT COALESCE(MAX(id),1) FROM invoices));

COMMIT;
SQL
22 changes: 22 additions & 0 deletions Back-End/Workflows/PullRequest/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Processar Pull Request

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
call-external-service:
runs-on: ubuntu-latest
steps:
- name: Chamar API PR AI
run: |
curl -X POST \
-H "Content-Type: application/json" \
-H "X-API-TOKEN: ${{ secrets.PRAI_API_TOKEN }}" \
-d '{
"repository": "${{ github.repository }}",
"pr_number": ${{ github.event.pull_request.number }},
"email": ${{ secrets.email }},
"password": "${{ secrets.password }}",
}' \
https://api.softwareai.site/api/prai/gen
Loading