add: db tx commit and rollback implementation

This commit is contained in:
mario
2025-05-15 15:42:33 +07:00
parent 264435f67e
commit d2ec8c0f07
11 changed files with 216 additions and 60 deletions

View File

@@ -6,6 +6,7 @@ import (
"devone.aplikasi.web.id/gitea/mario/go-ohif-proxy/internal/api/models"
"devone.aplikasi.web.id/gitea/mario/go-ohif-proxy/internal/database"
"github.com/jmoiron/sqlx"
)
// DBStudy represents a study from the database
@@ -69,8 +70,8 @@ func (r *StudyRepository) GetStudyByUID(studyUID string) (*DBStudy, error) {
return &study, nil
}
// CreateStudy creates a new study record for a patient
func (r *StudyRepository) CreateStudy(patientID string, study models.Study) error {
// CreateStudyTx creates a new study record for a patient within a transaction
func (r *StudyRepository) CreateStudyTx(tx *sqlx.Tx, patientID string, study models.Study) error {
// Parse study date if provided
var studyDate *time.Time
if study.StudyDate != "" {
@@ -85,7 +86,7 @@ func (r *StudyRepository) CreateStudy(patientID string, study models.Study) erro
(Study_PatientID, StudyIUID, StudyAccessionNumber, StudyDate, StudyCreatedAt, StudyUpdatedAt)
VALUES (?, ?, ?, ?, NOW(), NOW())`
_, err := database.DB.Exec(query,
_, err := tx.Exec(query,
patientID,
study.StudyInstanceUID,
study.AccessionNumber,