Files
2025-05-15 13:45:45 +07:00

221 lines
5.8 KiB
Go

package mongo
import (
Mongomaster "api-poliklinik/pkg/models/mongo/master/masteraddress"
"context"
"go.mongodb.org/mongo-driver/bson"
"log"
"time"
)
func (s *DatabaseService) Insertcommunication(req Mongomaster.Communication) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := s.DBMongo.Collection("communication").InsertOne(ctx, req)
if err != nil {
log.Println(err)
return err
}
return nil
}
func (s *DatabaseService) Insertdisability(req Mongomaster.Disability) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := s.DBMongo.Collection("disability").InsertOne(ctx, req)
if err != nil {
log.Println(err)
return err
}
return nil
}
func (s *DatabaseService) Inserteducation(req Mongomaster.Education) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := s.DBMongo.Collection("education").InsertOne(ctx, req)
if err != nil {
log.Println(err)
return err
}
return nil
}
func (s *DatabaseService) Insertjob(req Mongomaster.Job) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := s.DBMongo.Collection("job").InsertOne(ctx, req)
if err != nil {
log.Println(err)
return err
}
return nil
}
func (s *DatabaseService) Insertmartial(req Mongomaster.MartialStatus) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := s.DBMongo.Collection("martialstatus").InsertOne(ctx, req)
if err != nil {
log.Println(err)
return err
}
return nil
}
func (s *DatabaseService) Insertreligion(req Mongomaster.Religion) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := s.DBMongo.Collection("religion").InsertOne(ctx, req)
if err != nil {
log.Println(err)
return err
}
return nil
}
func (s *DatabaseService) Inserttribe(req Mongomaster.Tribe) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := s.DBMongo.Collection("tribe").InsertOne(ctx, req)
if err != nil {
log.Println(err)
return err
}
return nil
}
func (s *DatabaseService) Getcommunication() ([]*Mongomaster.Communication, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
datacommunication, err := s.DBMongo.Collection("communication").Find(ctx, bson.D{})
if err != nil {
log.Println(err)
}
var komunikasi []*Mongomaster.Communication
err = datacommunication.All(ctx, &komunikasi)
if err != nil {
log.Println(err)
return nil, err
}
return komunikasi, nil
}
func (s *DatabaseService) Getdisability() ([]*Mongomaster.Disability, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
datadisabilitas, err := s.DBMongo.Collection("disability").Find(ctx, bson.D{})
if err != nil {
log.Println(err)
}
var disabilitas []*Mongomaster.Disability
err = datadisabilitas.All(ctx, &disabilitas)
if err != nil {
log.Println(err)
return nil, err
}
return disabilitas, nil
}
func (s *DatabaseService) Geteducation() ([]*Mongomaster.Education, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
datapendidikan, err := s.DBMongo.Collection("education").Find(ctx, bson.D{})
if err != nil {
log.Println(err)
}
var pendidikan []*Mongomaster.Education
err = datapendidikan.All(ctx, &pendidikan)
if err != nil {
log.Println(err)
return nil, err
}
return pendidikan, nil
}
func (s *DatabaseService) Getjob() ([]*Mongomaster.Job, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
datapekerjaan, err := s.DBMongo.Collection("job").Find(ctx, bson.D{})
if err != nil {
log.Println(err)
}
var pekerjaan []*Mongomaster.Job
err = datapekerjaan.All(ctx, &pekerjaan)
if err != nil {
log.Println(err)
return nil, err
}
return pekerjaan, nil
}
func (s *DatabaseService) Getmartial() ([]*Mongomaster.MartialStatus, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
datapernikahan, err := s.DBMongo.Collection("martialstatus").Find(ctx, bson.D{})
if err != nil {
log.Println(err)
}
var pernikahan []*Mongomaster.MartialStatus
err = datapernikahan.All(ctx, &pernikahan)
if err != nil {
log.Println(err)
return nil, err
}
return pernikahan, nil
}
func (s *DatabaseService) Getreligion() ([]*Mongomaster.Religion, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
dataagama, err := s.DBMongo.Collection("religion").Find(ctx, bson.D{})
if err != nil {
log.Println(err)
}
var agama []*Mongomaster.Religion
err = dataagama.All(ctx, &agama)
if err != nil {
log.Println(err)
return nil, err
}
return agama, nil
}
func (s *DatabaseService) Getsuku() ([]*Mongomaster.Tribe, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
datasuku, err := s.DBMongo.Collection("tribe").Find(ctx, bson.D{})
if err != nil {
log.Println(err)
}
var suku []*Mongomaster.Tribe
err = datasuku.All(ctx, &suku)
if err != nil {
log.Println(err)
return nil, err
}
return suku, nil
}
func (s *DatabaseService) Inserticd(req Mongomaster.Icdmongo) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := s.DBMongo.Collection("icd").InsertOne(ctx, req)
if err != nil {
log.Println(err)
return err
}
return nil
}
func (s *DatabaseService) InsertSMF(req Mongomaster.Smfmongo) error {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
_, err := s.DBMongo.Collection("smf").InsertOne(ctx, req)
if err != nil {
log.Println(err)
return err
}
return nil
}