feat: initialize frontend with React and Vite setup
- Add main application structure with App component - Implement state management for counter functionality - Create CSS styles for application layout and components - Include assets for logos and hero image - Set up Vite configuration for development environment - Establish global CSS variables for theming
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
from sqlalchemy import Column, String, Boolean, Integer, DateTime, Text
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.sql import func
|
||||
from .session import Base
|
||||
import uuid
|
||||
|
||||
class Researcher(Base):
|
||||
__tablename__ = "researchers"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
orcid_id = Column(String(19), unique=True, nullable=False)
|
||||
name = Column(Text)
|
||||
authenticated = Column(Boolean, default=False)
|
||||
access_token = Column(Text)
|
||||
last_sync_at = Column(DateTime)
|
||||
|
||||
class Publication(Base):
|
||||
__tablename__ = "publications"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
researcher_id = Column(UUID(as_uuid=True))
|
||||
put_code = Column(Integer)
|
||||
title = Column(Text)
|
||||
doi = Column(Text)
|
||||
pub_year = Column(Integer)
|
||||
type = Column(Text)
|
||||
hash_fingerprint = Column(Text)
|
||||
last_modified = Column(DateTime)
|
||||
@@ -0,0 +1,10 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker, declarative_base
|
||||
import os
|
||||
|
||||
DATABASE_URL = os.getenv("DATABASE_URL")
|
||||
|
||||
engine = create_engine(DATABASE_URL)
|
||||
SessionLocal = sessionmaker(bind=engine, autocommit=False, autoflush=False)
|
||||
|
||||
Base = declarative_base()
|
||||
@@ -0,0 +1,9 @@
|
||||
from fastapi import FastAPI
|
||||
from app.services.orcid_client import ORCIDClient
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@app.get("/orcid/{orcid_id}/works")
|
||||
def test_works(orcid_id: str):
|
||||
client = ORCIDClient()
|
||||
return client.fetch_works(orcid_id)
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import httpx
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class ORCIDClient:
|
||||
"""
|
||||
Cliente para interactuar con la Public API de ORCID.
|
||||
Permite:
|
||||
- Obtener token público
|
||||
- Consultar /record
|
||||
- Consultar /works
|
||||
"""
|
||||
|
||||
TOKEN_URL = "https://orcid.org/oauth/token"
|
||||
BASE_URL = "https://pub.orcid.org/v3.0"
|
||||
|
||||
def __init__(self):
|
||||
self.client_id = os.getenv("ORCID_CLIENT_ID")
|
||||
self.client_secret = os.getenv("ORCID_CLIENT_SECRET")
|
||||
self._token_cache: Optional[str] = None
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# 1. Obtener token público
|
||||
# ---------------------------------------------------------
|
||||
def get_public_token(self) -> str:
|
||||
"""
|
||||
Obtiene un token público de ORCID (scope: /read-public).
|
||||
Se cachea en memoria para evitar pedirlo cada vez.
|
||||
"""
|
||||
if self._token_cache:
|
||||
return self._token_cache
|
||||
|
||||
data = {
|
||||
"client_id": self.client_id,
|
||||
"client_secret": self.client_secret,
|
||||
"grant_type": "client_credentials",
|
||||
"scope": "/read-public"
|
||||
}
|
||||
|
||||
with httpx.Client(timeout=20.0) as client:
|
||||
response = client.post(self.TOKEN_URL, data=data)
|
||||
response.raise_for_status()
|
||||
token = response.json()["access_token"]
|
||||
self._token_cache = token
|
||||
return token
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# Headers comunes
|
||||
# ---------------------------------------------------------
|
||||
def _headers(self):
|
||||
token = self.get_public_token()
|
||||
return {
|
||||
"Accept": "application/json",
|
||||
"Authorization": f"Bearer {token}"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# 2. Consultar /record
|
||||
# ---------------------------------------------------------
|
||||
def fetch_record(self, orcid_id: str) -> dict:
|
||||
url = f"{self.BASE_URL}/{orcid_id}/record"
|
||||
with httpx.Client(timeout=20.0) as client:
|
||||
response = client.get(url, headers=self._headers())
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# 3. Consultar /works
|
||||
# ---------------------------------------------------------
|
||||
def fetch_works(self, orcid_id: str) -> dict:
|
||||
url = f"{self.BASE_URL}/{orcid_id}/works"
|
||||
with httpx.Client(timeout=20.0) as client:
|
||||
response = client.get(url, headers=self._headers())
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
Reference in New Issue
Block a user