penambahan template
This commit is contained in:
13
pkg/database/satu_data/database.go
Normal file
13
pkg/database/satu_data/database.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package satu_data
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type DatabaseService struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewDatabaseService(db *gorm.DB) *DatabaseService {
|
||||
return &DatabaseService{DB: db}
|
||||
}
|
||||
@@ -1 +1,24 @@
|
||||
package satu_data
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"log"
|
||||
"template_blueprint/pkg/models/satu_data"
|
||||
)
|
||||
|
||||
func (s *DatabaseService) PoliklinikGetData(Status_pelayanan string) []*satu_data.PoliklinikGetData {
|
||||
var datapoliklinik []*satu_data.PoliklinikGetData
|
||||
query := `select dlr."Nama",dlr."Kode",dlr."id" from daftar_lokasi_ruang dlr where dlr."Status_pelayanan" = ?`
|
||||
errQuery := s.DB.Debug().Raw(query, Status_pelayanan).Scan(&datapoliklinik).Error
|
||||
if errQuery != nil {
|
||||
if errors.Is(errQuery, gorm.ErrRecordNotFound) {
|
||||
errMsg := errors.New("Data Tidak Ditemukan")
|
||||
log.Println(errMsg)
|
||||
return nil
|
||||
}
|
||||
log.Println(errQuery)
|
||||
return nil
|
||||
}
|
||||
return datapoliklinik
|
||||
}
|
||||
|
||||
21
pkg/handlers/poliklinik/poliklinik.go
Normal file
21
pkg/handlers/poliklinik/poliklinik.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package poliklinik
|
||||
|
||||
import (
|
||||
""
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http"
|
||||
"template_blueprint/internal/database"
|
||||
connDatabase "template_blueprint/pkg/database/satu_data"
|
||||
)
|
||||
|
||||
func GetDataPoliklinik(c *gin.Context) {
|
||||
db := database.New().GetDB("satudata")
|
||||
satudata := connDatabase.NewDatabaseService(db)
|
||||
statuspelayanan := c.Param("statuspelayanan")
|
||||
|
||||
log.Println("REQUEST", statuspelayanan)
|
||||
dataPoliklinik := satudata.PoliklinikGetData(statuspelayanan)
|
||||
|
||||
c.JSON(http.StatusOK, dataPoliklinik)
|
||||
}
|
||||
7
pkg/models/satu_data/poliklinik.go
Normal file
7
pkg/models/satu_data/poliklinik.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package satu_data
|
||||
|
||||
type PoliklinikGetData struct {
|
||||
ID string `gorm:"column:id" json:"id"`
|
||||
Nama string `gorm:"column:name" json:"nama"`
|
||||
Kode string `gorm:"column:kode" json:"kode"`
|
||||
}
|
||||
Reference in New Issue
Block a user