fix: shortlink generation logic update/create
This commit is contained in:
@@ -139,3 +139,28 @@ func (r *ShortLinkRepository) UpdateShortLink(shortLink *models.ShortLink) error
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetActiveShortLinkByPatientAndStudy retrieves an active (unexpired, not revoked) shortlink
|
||||
// for the given patient ID and study UID
|
||||
func (r *ShortLinkRepository) GetActiveShortLinkByPatientAndStudy(patientID string, studyUID string) (*models.ShortLink, error) {
|
||||
var dbShortLink DBShortLink
|
||||
|
||||
query := `SELECT * FROM shortlink
|
||||
WHERE Shortlink_PatientID = ?
|
||||
AND Shortlink_Study_IUID = ?
|
||||
AND ShortlinkExpiredAt > NOW()
|
||||
AND ShortlinkIsRevoked = FALSE
|
||||
ORDER BY ShortlinkExpiredAt DESC
|
||||
LIMIT 1`
|
||||
|
||||
err := database.DB.Get(&dbShortLink, query, patientID, studyUID)
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, fmt.Errorf("database error getting active shortlink: %w", err)
|
||||
}
|
||||
|
||||
return dbShortLink.ToShortLink(), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user