step 8 : configurasi url path selfie, load file, image not found, and deploy to devone
This commit is contained in:
@@ -4,3 +4,12 @@ dbpass: absensi102938
|
|||||||
dbhost: devone.aplikasi.web.id
|
dbhost: devone.aplikasi.web.id
|
||||||
dbport: 3306
|
dbport: 3306
|
||||||
dbname: absensi
|
dbname: absensi
|
||||||
|
|
||||||
|
# lokasi file
|
||||||
|
clockInFolder: ./selfie_attachment/
|
||||||
|
clockOutFolder: ./selfie_attachment/
|
||||||
|
cutiFolder: ./cuti/
|
||||||
|
ijinFolder: ./ijin/
|
||||||
|
|
||||||
|
# lokasi file not found
|
||||||
|
notFoundImage: ./no_image_found.jpg
|
||||||
|
|||||||
@@ -147,11 +147,12 @@ func (transabsensi *TransAbsensiResponse) ClockInAbsensi(T_TransactionM_StaffID
|
|||||||
var varGetM_StaffNIP string
|
var varGetM_StaffNIP string
|
||||||
var varProsesFotoSelfie string
|
var varProsesFotoSelfie string
|
||||||
var jamClockIn string
|
var jamClockIn string
|
||||||
|
var varFileName string
|
||||||
|
|
||||||
// check user token
|
// check user token
|
||||||
qCheckTokenStaff := `SELECT
|
qCheckTokenStaff := `SELECT
|
||||||
M_StaffToken,
|
M_StaffToken,
|
||||||
M_StaffNIP
|
LOWER(M_StaffNIP) AS M_StaffNIP
|
||||||
FROM m_staff
|
FROM m_staff
|
||||||
WHERE M_StaffIsActive = 'Y'
|
WHERE M_StaffIsActive = 'Y'
|
||||||
AND M_StaffToken = ?
|
AND M_StaffToken = ?
|
||||||
@@ -232,15 +233,6 @@ func (transabsensi *TransAbsensiResponse) ClockInAbsensi(T_TransactionM_StaffID
|
|||||||
log.Printf("documentPath: %s", photoPath)
|
log.Printf("documentPath: %s", photoPath)
|
||||||
|
|
||||||
// create folder selfie_attachment jika belum ada
|
// create folder selfie_attachment jika belum ada
|
||||||
|
|
||||||
// if _, err := os.Stat(photoPath); errors.Is(err, os.ErrNotExist) {
|
|
||||||
// err = os.MkdirAll(photoPath, os.ModePerm)
|
|
||||||
// if err != nil {
|
|
||||||
// log.Printf("here %v", err)
|
|
||||||
// return &ret, err
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if _, err := os.Stat(photoPath); errors.Is(err, os.ErrNotExist) {
|
if _, err := os.Stat(photoPath); errors.Is(err, os.ErrNotExist) {
|
||||||
err = os.MkdirAll(photoPath, os.ModePerm.Perm())
|
err = os.MkdirAll(photoPath, os.ModePerm.Perm())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -268,7 +260,8 @@ func (transabsensi *TransAbsensiResponse) ClockInAbsensi(T_TransactionM_StaffID
|
|||||||
fs.Write(decodedByte)
|
fs.Write(decodedByte)
|
||||||
fs.Sync()
|
fs.Sync()
|
||||||
|
|
||||||
varProsesFotoSelfie = strPhoto
|
varProsesFotoSelfie = "selfie_attachment/" + folderName + "/" + strPhoto
|
||||||
|
varFileName = strPhoto
|
||||||
}
|
}
|
||||||
|
|
||||||
qInsertClockIn := `INSERT INTO t_transaction (
|
qInsertClockIn := `INSERT INTO t_transaction (
|
||||||
@@ -280,7 +273,8 @@ func (transabsensi *TransAbsensiResponse) ClockInAbsensi(T_TransactionM_StaffID
|
|||||||
T_TransactionCurrentLatitude,
|
T_TransactionCurrentLatitude,
|
||||||
T_TransactionCurrentLongitude,
|
T_TransactionCurrentLongitude,
|
||||||
T_TransactionCurrentDistance,
|
T_TransactionCurrentDistance,
|
||||||
T_TransactionSelfiePhoto,
|
T_TransactionFileName,
|
||||||
|
T_TransactionSelfiePhotoPath,
|
||||||
T_TransactionIsActive,
|
T_TransactionIsActive,
|
||||||
T_TransactionCreated
|
T_TransactionCreated
|
||||||
) VALUES (
|
) VALUES (
|
||||||
@@ -294,6 +288,7 @@ func (transabsensi *TransAbsensiResponse) ClockInAbsensi(T_TransactionM_StaffID
|
|||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
?,
|
||||||
NOW()
|
NOW()
|
||||||
)`
|
)`
|
||||||
|
|
||||||
@@ -305,6 +300,7 @@ func (transabsensi *TransAbsensiResponse) ClockInAbsensi(T_TransactionM_StaffID
|
|||||||
T_TransactionCurrentLatitude,
|
T_TransactionCurrentLatitude,
|
||||||
T_TransactionCurrentLongitude,
|
T_TransactionCurrentLongitude,
|
||||||
T_TransactionCurrentDistance,
|
T_TransactionCurrentDistance,
|
||||||
|
&varFileName,
|
||||||
&varProsesFotoSelfie,
|
&varProsesFotoSelfie,
|
||||||
"Y",
|
"Y",
|
||||||
)
|
)
|
||||||
|
|||||||
BIN
backend/no_image_found.jpg
Normal file
BIN
backend/no_image_found.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 232 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 232 KiB |
|
Before Width: | Height: | Size: 232 KiB After Width: | Height: | Size: 232 KiB |
BIN
backend/server
Normal file
BIN
backend/server
Normal file
Binary file not shown.
@@ -42,6 +42,68 @@ func main() {
|
|||||||
srv := handler.NewDefaultServer(
|
srv := handler.NewDefaultServer(
|
||||||
generated.NewExecutableSchema(generated.Config{Resolvers: &resolver.Resolver{}}))
|
generated.NewExecutableSchema(generated.Config{Resolvers: &resolver.Resolver{}}))
|
||||||
|
|
||||||
|
// get file selfie
|
||||||
|
router.Get("/img/{typeAbsensi}/{subfolder}/{imgname}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
// inisialisasi
|
||||||
|
var urlPath string
|
||||||
|
|
||||||
|
// get from url param
|
||||||
|
typeAbsensi := chi.URLParam(r, "typeAbsensi")
|
||||||
|
subfolder := chi.URLParam(r, "subfolder")
|
||||||
|
imgname := chi.URLParam(r, "imgname")
|
||||||
|
|
||||||
|
// check param empty
|
||||||
|
if typeAbsensi == "" {
|
||||||
|
w.Write([]byte("Invalid typeAbsensi"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if subfolder == "" {
|
||||||
|
w.Write([]byte("Invalid subfolder"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if imgname == "" {
|
||||||
|
// w.Write([]byte("Invalid imgname"))
|
||||||
|
http.ServeFile(w, r, config.Data.Get("notFoundImage"))
|
||||||
|
// return
|
||||||
|
}
|
||||||
|
|
||||||
|
// klu clockin
|
||||||
|
if typeAbsensi == "clockin" {
|
||||||
|
// urlPath = "./selfie_attachment/" + subfolder + "/" + imgname
|
||||||
|
urlPath = config.Data.Get("clockInFolder") + subfolder + "/" + imgname
|
||||||
|
}
|
||||||
|
|
||||||
|
if typeAbsensi == "clockout" {
|
||||||
|
// urlPath = "./selfie_attachment/" + subfolder + "/" + imgname
|
||||||
|
urlPath = config.Data.Get("clockOutFolder") + subfolder + "/" + imgname
|
||||||
|
}
|
||||||
|
|
||||||
|
if typeAbsensi == "cuti" {
|
||||||
|
// urlPath = "./cuti/" + subfolder + "/" + imgname
|
||||||
|
urlPath = config.Data.Get("cutiFolder") + subfolder + "/" + imgname
|
||||||
|
}
|
||||||
|
|
||||||
|
if typeAbsensi == "ijin" {
|
||||||
|
// urlPath = "./ijin/" + subfolder + "/" + imgname
|
||||||
|
urlPath = config.Data.Get("ijinFolder") + subfolder + "/" + imgname
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := os.ReadFile(urlPath)
|
||||||
|
|
||||||
|
// gambar tidak ditemukan akan return image not found
|
||||||
|
if err != nil {
|
||||||
|
// w.Write([]byte("Invalid Attachment Clock In"))
|
||||||
|
// return
|
||||||
|
http.ServeFile(w, r, config.Data.Get("notFoundImage"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
http.ServeFile(w, r, urlPath)
|
||||||
|
})
|
||||||
|
|
||||||
router.Handle("/", playground.Handler("GraphQL playground", "/query"))
|
router.Handle("/", playground.Handler("GraphQL playground", "/query"))
|
||||||
router.Handle("/query", srv)
|
router.Handle("/query", srv)
|
||||||
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
|
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
|
||||||
|
|||||||
Reference in New Issue
Block a user