pembaruhan baru
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"api-poliklinik/pkg/models/mongo/location"
|
||||
"context"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (s *DatabaseService) Insertlokasi(req location.Location) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
_, err := s.DBMongo.Collection("location").InsertOne(ctx, req)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *DatabaseService) Getlocation() ([]*location.Location, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
datalocation, err := s.DBMongo.Collection("location").Find(ctx, bson.D{})
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
var location []*location.Location
|
||||
err = datalocation.All(ctx, &location)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
return location, nil
|
||||
}
|
||||
Reference in New Issue
Block a user