init project
This commit is contained in:
44
pkg/database/mongo/patient.go
Normal file
44
pkg/database/mongo/patient.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"log"
|
||||
"template_blueprint/pkg/models/patient"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *DatabaseService) InsertPatient(req *patient.Patient) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
_, err := s.DB.Collection("patient").InsertOne(ctx, patient.Patient{
|
||||
ID: req.ID,
|
||||
NoRM: req.NoRM,
|
||||
Name: req.Name,
|
||||
Telecom: req.Telecom,
|
||||
Gender: req.Gender,
|
||||
BirthDate: req.BirthDate,
|
||||
Address: req.Address,
|
||||
})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DatabaseService) GetAllDataPatient() ([]*patient.Patient, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
dataUser, err := s.DB.Collection("patient").Find(ctx, bson.D{})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
var users []*patient.Patient
|
||||
err = dataUser.All(ctx, &users)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
return users, nil
|
||||
}
|
||||
Reference in New Issue
Block a user