update terbaru
This commit is contained in:
@@ -3,7 +3,10 @@ package mongo
|
||||
import (
|
||||
"api-poliklinik/pkg/models/mongo/practitioner"
|
||||
"context"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
"go.mongodb.org/mongo-driver/mongo/options"
|
||||
"log"
|
||||
"time"
|
||||
@@ -55,3 +58,27 @@ func (s *DatabaseService) GetDokterBySMF(display string, value string) ([]*pract
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (s *DatabaseService) GetDokterByid(id string) (*practitioner.Practitioner, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
objectID, err := primitive.ObjectIDFromHex(id)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid ID format: %v", err)
|
||||
}
|
||||
filter := bson.M{
|
||||
"_id": objectID,
|
||||
}
|
||||
|
||||
var result practitioner.Practitioner
|
||||
err = s.DBMongo.Collection("practitioner").FindOne(ctx, filter).Decode(&result)
|
||||
if err != nil {
|
||||
if err == mongo.ErrNoDocuments {
|
||||
return nil, fmt.Errorf("dokter dengan ID %s tidak ditemukan", id)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user