Code indexing in gitaly is broken and leads to code not being visible to the user. We work on the issue with highest priority.

Skip to content
Snippets Groups Projects
Commit 958c9167 authored by GotthardG's avatar GotthardG
Browse files

added puck events

parent 66a0ce32
No related branches found
No related tags found
No related merge requests found
from sqlalchemy import Column, Integer, String, Date, ForeignKey, JSON, Interval, DateTime, Boolean
from sqlalchemy import Column, Integer, String, Date, ForeignKey, JSON, DateTime, Boolean
from sqlalchemy.orm import relationship
from .database import Base
from datetime import datetime, timedelta
import uuid
from datetime import datetime
class Shipment(Base):
......@@ -118,6 +117,7 @@ class Puck(Base):
dewar_id = Column(Integer, ForeignKey('dewars.id'))
dewar = relationship("Dewar", back_populates="pucks")
samples = relationship("Sample", back_populates="puck")
events = relationship("PuckEvent", back_populates="puck")
class Sample(Base):
......@@ -168,13 +168,13 @@ class SampleEvent(Base):
sample = relationship("Sample", back_populates="events")
#class PuckEvent(Base):
# __tablename__ = "sample_events"
#
# id = Column(Integer, primary_key=True, index=True)
# puck_id = Column(Integer, ForeignKey('puck.id'))
# tell_position = Column(String(255), nullable=True)
# event_type = Column(String(255), index=True)
# timestamp = Column(DateTime, default=datetime.utcnow)
#
# sample = relationship("Sample", back_populates="events")
class PuckEvent(Base):
__tablename__ = "puck_events"
id = Column(Integer, primary_key=True, index=True)
puck_id = Column(Integer, ForeignKey('pucks.id'))
tell_position = Column(String(255), nullable=True)
event_type = Column(String(255), index=True)
timestamp = Column(DateTime, default=datetime.utcnow)
puck = relationship("Puck", back_populates="events")
\ No newline at end of file
......@@ -2,9 +2,10 @@ from fastapi import APIRouter, HTTPException, status, Depends
from sqlalchemy.orm import Session
from typing import List
import uuid
from app.schemas import Puck as PuckSchema, PuckCreate, PuckUpdate
from app.models import Puck as PuckModel, Sample as SampleModel
from app.schemas import Puck as PuckSchema, PuckCreate, PuckUpdate, SetTellPosition, PuckEventCreate
from app.models import Puck as PuckModel, Sample as SampleModel, PuckEvent as PuckEventModel
from app.dependencies import get_db
from datetime import datetime
router = APIRouter()
......@@ -61,3 +62,43 @@ async def delete_puck(puck_id: str, db: Session = Depends(get_db)):
db.delete(puck)
db.commit()
return
@router.put("/{puck_id}/tell_position", status_code=status.HTTP_200_OK)
async def set_tell_position(
puck_id: int,
request: SetTellPosition,
db: Session = Depends(get_db)
):
# Get the requested tell_position
tell_position = request.tell_position
# Define valid positions
valid_positions = [f"{letter}{num}" for letter in "ABCDEF" for num in range(1, 6)] + ["null", None]
# Validate tell_position
if tell_position not in valid_positions:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=f"Invalid tell_position value. Must be one of {valid_positions}.",
)
# Set the correct tell_position logic
actual_position = None if tell_position in ["null", None] else tell_position
# Create a new PuckEvent (always a new event, even with null/None)
new_puck_event = PuckEventModel(
puck_id=puck_id,
tell_position=actual_position, # Null for disassociation, else the valid position
event_type="tell_position_set", # Example event type
timestamp=datetime.utcnow(),
)
db.add(new_puck_event)
db.commit()
db.refresh(new_puck_event)
# Send the response
return {
"message": "New tell position event created successfully",
"tell_position": new_puck_event.tell_position,
"timestamp": new_puck_event.timestamp,
}
......@@ -306,4 +306,14 @@ class SlotSchema(BaseModel):
local_contact: Optional[str]
class Config:
from_attributes = True
\ No newline at end of file
from_attributes = True
class PuckEventCreate(BaseModel):
event_type: str
class SetTellPosition(BaseModel):
tell_position: str = Field(
...,
pattern="^[A-F][1-5]$|^null$|^None$", # Use 'pattern' instead of 'regex'
description="Valid values are A1-A5, B1-B5, ..., F1-F5, or null."
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment