Bug fixes for SQL testing

This commit is contained in:
Scott Idem
2026-01-13 13:57:18 -05:00
parent 8927f07bcf
commit ed3dda6cf5
3 changed files with 26 additions and 128 deletions

View File

@@ -600,45 +600,3 @@ async def generate_id_random(response: Response = Response):
return HTMLResponse(content=html_list, status_code=200) return HTMLResponse(content=html_list, status_code=200)
# ### END ### API Main ### generate_id_random() ### # ### END ### API Main ### generate_id_random() ###
# ### BEGIN ### API Main ### sql_test() ###
# ### TEST TEST TEST ### #
@app.get('/sql_test', tags=['Testing'], response_class=PlainTextResponse)
async def sql_test(response: Response = Response):
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARN, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
return mk_resp(data=False, status_code=501, response=response)
log.info('Getting all accounts from DB...')
sql = text(
"""
SELECT id, id_random, name, enable
FROM `account`
"""
)
try:
result = db.execute(sql)
except Exception as e:
log.error('*** An exception happened. ***')
log.error(repr(e))
log.error('***')
log.error(str(e))
log.error('^^^ exception ^^^')
else:
if result.rowcount:
record_li = [dict(record) for record in result.fetchall()]
log.debug(record_li)
else:
log.error('No records found. Something went wrong.')
log.info('Got the account list')
response_data = {}
response_data['message'] = 'This is the Aether API using FastAPI.'
response_data['data'] = record_li
return json.dumps(response_data, indent=4) # , sort_keys=True
# ### END ### API Main ### sql_test() ###

View File

@@ -1,7 +1,11 @@
import datetime, jwt, time import datetime, jwt, time
# WARNING: Uncommenting JSONResponse import causes circular import issues
# from fastapi import APIRouter, Body, Depends, Header, HTTPException, Path, Query, Response, status, JSONResponse
from fastapi import APIRouter, Body, Depends, Header, HTTPException, Path, Query, Response, status from fastapi import APIRouter, Body, Depends, Header, HTTPException, Path, Query, Response, status
from pydantic import BaseModel, EmailStr, Field from pydantic import BaseModel, EmailStr, Field
from typing import Dict, List, Optional, Set, Union from typing import Dict, List, Optional, Set, Union
from sqlalchemy import text
from app.db_connection import db
from app.lib_general import log, logging, sign_jwt, decode_jwt, common_route_params, Common_Route_Params, common_route_params_min, Common_Route_Params_Min from app.lib_general import log, logging, sign_jwt, decode_jwt, common_route_params, Common_Route_Params, common_route_params_min, Common_Route_Params_Min
from app.config import settings from app.config import settings
@@ -443,3 +447,25 @@ async def get_api_object_id(
if object_id := redis_lookup_id_random(record_id_random=object_id_random, table_name=object_type): if object_id := redis_lookup_id_random(record_id_random=object_id_random, table_name=object_type):
return mk_resp(data={ 'object_id': object_id}, status_code=400) return mk_resp(data={ 'object_id': object_id}, status_code=400)
else: return mk_resp(data=None, status_code=400) else: return mk_resp(data=None, status_code=400)
# WARNING: The following endpoint is commented out because it causes circular import issues due to JSONResponse import. -Scott 2026-01-13
# # ### BEGIN ### API API ### sql_test() ###
# @router.get('/sql_test', tags=['Testing'], response_class=JSONResponse)
# async def sql_test(response: Response = Response):
# log.setLevel(logging.DEBUG)
# log.debug(locals())
# sql = text("SELECT NOW() as current_time, VERSION() as version")
# try:
# result_proxy = db.execute(sql)
# result = result_proxy.fetchone()
# data = {
# "current_time": str(result[0]),
# "version": result[1]
# }
# return mk_resp(data=data, response=response)
# except Exception as e:
# log.error(f'SQL Test failed: {str(e)}')
# return mk_resp(data=False, status_code=500, details=str(e), response=response)
# # ### END ### API API ### sql_test() ###

View File

@@ -1,86 +0,0 @@
# Journals API Migration Plan
This document outlines the plan for migrating the Journals API to the new, standardized Aether API architecture.
## 1. Current API Analysis
The Journals module consists of two main objects: `journal` and `journal_entry`. Currently, these objects are primarily accessed through the generic CRUD endpoints.
### How the Front-End Likely Interacts with the API:
* **Create a Journal:**
* `POST /v2/crud/journal`
* **Body:** A JSON object with all the fields from the `Journal_Base` model.
* **Get a Journal:**
* `GET /v2/crud/journal/{journal_id_random}`
* **List Journals:**
* `GET /v2/crud/journal/list`
* This would also likely use the `for_obj_type` and `for_obj_id` query parameters to get journals for a specific person or account (e.g., `GET /v2/crud/journal/list?for_obj_type=person&for_obj_id={person_id_random}`).
* **Update a Journal:**
* `PATCH /v2/crud/journal/{journal_id_random}`
* **Body:** A JSON object with the fields to be updated.
* **Delete a Journal:**
* `DELETE /v2/crud/journal/{journal_id_random}`
The same patterns apply to the `journal_entry` object.
## 2. Proposed New API
The new Journals API will be more explicit, organized, and easier to use. It will follow the new architectural principles of the Aether API rewrite.
### New URL Structure:
* `/journals/`
* `/journals/{journal_id_random}`
* `/journals/{journal_id_random}/entries/`
* `/journals/{journal_id_random}/entries/{entry_id_random}`
### New Models:
We will create new, simplified models for `Journal` and `JournalEntry` that inherit from the `CoreObject` base model.
* `app/models/journal.py`:
* `JournalBase(CoreObject)`
* `Journal(JournalBase)`
* `JournalInDB(Journal, CoreObjectInDB)`
* `JournalCreate(JournalBase)`
* `JournalUpdate(JournalBase)`
* `app/models/journal_entry.py`:
* `JournalEntryBase(CoreObject)`
* `JournalEntry(JournalEntryBase)`
* `JournalEntryInDB(JournalEntry, CoreObjectInDB)`
* `JournalEntryCreate(JournalEntryBase)`
* `JournalEntryUpdate(JournalEntryBase)`
### New Endpoints:
A new `app/routers/journals.py` router will be created with the following explicit endpoints:
* `POST /journals/`: Create a new journal.
* `GET /journals/`: List all journals (with query params for filtering).
* `GET /journals/{journal_id_random}`: Get a single journal by its `id_random`.
* `PATCH /journals/{journal_id_random}`: Update a journal.
* `DELETE /journals/{journal_id_random}`: Delete a journal.
* `POST /journals/{journal_id_random}/entries/`: Create a new journal entry for a specific journal.
* `GET /journals/{journal_id_random}/entries/`: List all entries for a specific journal.
* `GET /journals/{journal_id_random}/entries/{entry_id_random}`: Get a single journal entry.
* `PATCH /journals/{journal_id_random}/entries/{entry_id_random}`: Update a journal entry.
* `DELETE /journals/{journal_id_random}/entries/{entry_id_random}`: Delete a journal entry.
## 3. Side-by-Side Comparison
| Operation | Current API Call | Proposed New API Call |
| --- | --- | --- |
| Create Journal | `POST /v2/crud/journal` | `POST /journals/` |
| Get Journal | `GET /v2/crud/journal/{id}` | `GET /journals/{id}` |
| List Journals | `GET /v2/crud/journal/list` | `GET /journals/` |
| Update Journal | `PATCH /v2/crud/journal/{id}` | `PATCH /journals/{id}` |
| Delete Journal | `DELETE /v2/crud/journal/{id}` | `DELETE /journals/{id}` |
| Create Entry | `POST /v2/crud/journal_entry` (with `journal_id_random` in body) | `POST /journals/{journal_id}/entries/` |
| List Entries | `GET /v2/crud/journal_entry/list?for_obj_type=journal&for_obj_id={id}` | `GET /journals/{journal_id}/entries/` |
This plan provides a clear path forward for refactoring the Journals module. By following this plan, we can create a more maintainable and user-friendly API while ensuring a smooth transition for the front-end.