60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package repository
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"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"
|
|
)
|
|
|
|
// DBDoctor represents a doctor from the database
|
|
type DBDoctor struct {
|
|
ID int `db:"id"`
|
|
Doctor_UsersID string `db:"Doctor_UsersID"`
|
|
DoctorID string `db:"DoctorID"`
|
|
DoctorName string `db:"DoctorName"`
|
|
DoctorCreatedAt time.Time `db:"DoctorCreatedAt"`
|
|
DoctorLastUpdatedAt time.Time `db:"DoctorLastUpdatedAt"`
|
|
}
|
|
|
|
// DoctorRepository handles database operations related to doctors
|
|
type DoctorRepository struct {
|
|
*Repository
|
|
}
|
|
|
|
// NewDoctorRepository creates a new doctor repository
|
|
func NewDoctorRepository() *DoctorRepository {
|
|
return &DoctorRepository{
|
|
Repository: NewRepository(),
|
|
}
|
|
}
|
|
|
|
// GetDoctorDetailsByUserID retrieves doctor details for a user
|
|
func (r *DoctorRepository) GetDoctorDetailsByUserID(userID string) (*DBDoctor, error) {
|
|
var dbDoctor DBDoctor
|
|
|
|
query := `SELECT * FROM doctor WHERE Doctor_UsersID = ?`
|
|
err := database.DB.Get(&dbDoctor, query, userID)
|
|
|
|
if err != nil {
|
|
return nil, fmt.Errorf("database error getting doctor details: %w", err)
|
|
}
|
|
|
|
return &dbDoctor, nil
|
|
}
|
|
|
|
// CreateDoctorTx creates a new doctor record within a transaction
|
|
func (r *DoctorRepository) CreateDoctorTx(tx *sqlx.Tx, doctorDetails *models.DoctorDetails, userID string) error {
|
|
query := `INSERT INTO doctor (Doctor_UsersID, DoctorID, DoctorName, DoctorCreatedAt, DoctorLastUpdatedAt)
|
|
VALUES (?, ?, ?, NOW(), NOW())`
|
|
|
|
_, err := tx.Exec(query, userID, doctorDetails.DoctorID, doctorDetails.DoctorName)
|
|
if err != nil {
|
|
return fmt.Errorf("database error creating doctor: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|