58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package login
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
"os"
|
|
"template_blueprint/internal/database"
|
|
"template_blueprint/pkg/database/mongo"
|
|
)
|
|
|
|
func Getlogin(c *gin.Context) {
|
|
local := os.Getenv("MONGODB_DEV_MASTER")
|
|
db := database.New(local).GetMongoDB()
|
|
if db == nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"})
|
|
return
|
|
}
|
|
|
|
mongoDB := mongo.NewDatabaseServiceMongo(db)
|
|
dataEncounter, errSelect := mongoDB.Getlogin()
|
|
if errSelect != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"message": errSelect.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"data": dataEncounter,
|
|
"message": "login Sukses Ter-ambil ",
|
|
})
|
|
}
|
|
|
|
func GetloginbyID(c *gin.Context) {
|
|
local := os.Getenv("MONGODB_DEV_MASTER")
|
|
db := database.New(local).GetMongoDB()
|
|
if db == nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"message": "Database connection failed"})
|
|
return
|
|
}
|
|
|
|
id := c.Param("id")
|
|
|
|
if id == "" {
|
|
c.JSON(http.StatusBadRequest, gin.H{"message": "Parameter 'id' dibutuhkan"})
|
|
return
|
|
}
|
|
|
|
mongoDB := mongo.NewDatabaseServiceMongo(db)
|
|
dataID, err := mongoDB.GetByid(id)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"data": dataID,
|
|
"message": "ID berhasil di cari",
|
|
})
|
|
}
|