add: /uploaded_dicom for pydicom-google-upload to get shortlink

This commit is contained in:
mario
2025-05-16 10:36:19 +07:00
parent 28339e855c
commit 36417fe515
7 changed files with 283 additions and 15 deletions

View File

@@ -13,16 +13,16 @@ import (
// DBShortLink represents a shortlink from the database
type DBShortLink struct {
ShortlinkID int `db:"ShortlinkID"`
ShortlinkCode string `db:"ShortlinkCode"`
Shortlink_PatientID string `db:"Shortlink_PatientID"`
Shortlink_Study_IUID string `db:"Shortlink_Study_IUID"`
ShortlinkHashDoB string `db:"ShortlinkHashDoB"`
ShortlinkExpiredAt time.Time `db:"ShortlinkExpiredAt"`
ShortlinkIsRevoked bool `db:"ShortlinkIsRevoked"`
ShortlinkRemainingTries int `db:"ShortlinkRemainingTries"`
ShortlinkCreatedAt time.Time `db:"ShortlinkCreatedAt"`
ShortlinkCreate_UserID int `db:"ShortlinkCreate_UserID"`
ShortlinkID int `db:"ShortlinkID"`
ShortlinkCode string `db:"ShortlinkCode"`
Shortlink_PatientID string `db:"Shortlink_PatientID"`
Shortlink_Study_IUID string `db:"Shortlink_Study_IUID"`
ShortlinkHashDoB string `db:"ShortlinkHashDoB"`
ShortlinkExpiredAt time.Time `db:"ShortlinkExpiredAt"`
ShortlinkIsRevoked bool `db:"ShortlinkIsRevoked"`
ShortlinkRemainingTries int `db:"ShortlinkRemainingTries"`
ShortlinkCreatedAt time.Time `db:"ShortlinkCreatedAt"`
ShortlinkCreate_UserID sql.NullInt64 `db:"ShortlinkCreate_UserID"`
}
// ShortLinkRepository handles database operations related to shortlinks
@@ -39,6 +39,13 @@ func NewShortLinkRepository() *ShortLinkRepository {
// ToShortLink converts a DBShortLink to a ShortLink model
func (s *DBShortLink) ToShortLink() *models.ShortLink {
var createdByID string
if s.ShortlinkCreate_UserID.Valid {
createdByID = fmt.Sprintf("%d", s.ShortlinkCreate_UserID.Int64)
} else {
createdByID = ""
}
return &models.ShortLink{
ID: fmt.Sprintf("%d", s.ShortlinkID),
Token: s.ShortlinkCode,
@@ -49,7 +56,7 @@ func (s *DBShortLink) ToShortLink() *models.ShortLink {
IsRevoked: s.ShortlinkIsRevoked,
RemainingTries: s.ShortlinkRemainingTries,
CreatedAt: s.ShortlinkCreatedAt.Format(time.RFC3339),
CreatedByID: fmt.Sprintf("%d", s.ShortlinkCreate_UserID),
CreatedByID: createdByID,
}
}
@@ -84,9 +91,19 @@ func (r *ShortLinkRepository) CreateShortLinkTx(tx *sqlx.Tx, shortLink *models.S
ShortlinkCreate_UserID)
VALUES (?, ?, ?, ?, ?, ?, ?, NOW(), ?)`
createdByID, err := strconv.Atoi(shortLink.CreatedByID)
if err != nil {
return fmt.Errorf("invalid created by ID: %w", err)
var createdByID sql.NullInt64
// Handle empty CreatedByID
if shortLink.CreatedByID != "" {
id, err := strconv.Atoi(shortLink.CreatedByID)
if err != nil {
return fmt.Errorf("invalid created by ID: %w", err)
}
createdByID.Int64 = int64(id)
createdByID.Valid = true
} else {
// If CreatedByID is empty, insert NULL
createdByID.Valid = false
}
expiresAt, err := time.Parse(time.RFC3339, shortLink.ExpiresAt)