Spaces:
Configuration error
Configuration error
Delete utils
Browse files- utils/APIResponse.go +0 -40
- utils/Exception.go +0 -1
- utils/Helper.go +0 -11
- utils/Logger.go +0 -21
- utils/api_response.go +0 -52
- utils/util.go +0 -9
- utils/utils.go +0 -9
utils/APIResponse.go
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
package utils
|
| 2 |
-
|
| 3 |
-
import (
|
| 4 |
-
"net/http"
|
| 5 |
-
"reflect"
|
| 6 |
-
|
| 7 |
-
"api.qobiltu.id/models"
|
| 8 |
-
"api.qobiltu.id/services"
|
| 9 |
-
"github.com/gin-gonic/gin"
|
| 10 |
-
)
|
| 11 |
-
|
| 12 |
-
func ResponseOK(c *gin.Context, data any) {
|
| 13 |
-
c.JSON(http.StatusOK, gin.H{"message": "Request Success!", "data": data, "status": "success"})
|
| 14 |
-
return
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
func ResponseFAIL(c *gin.Context, status int, exception models.Exception) {
|
| 18 |
-
message := exception.Message
|
| 19 |
-
exception.Message = ""
|
| 20 |
-
c.AbortWithStatusJSON(status, gin.H{"status": "error", "message": message, "error": exception})
|
| 21 |
-
return
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
func SendResponse(c *gin.Context, data services.Service[any, any]) {
|
| 25 |
-
if reflect.ValueOf(data.Exception).IsNil() {
|
| 26 |
-
ResponseOK(c, data)
|
| 27 |
-
} else {
|
| 28 |
-
if data.Exception.Unauthorized {
|
| 29 |
-
ResponseFAIL(c, 401, data.Exception)
|
| 30 |
-
} else if data.Exception.BadRequest {
|
| 31 |
-
ResponseFAIL(c, 400, data.Exception)
|
| 32 |
-
} else if data.Exception.DataNotFound {
|
| 33 |
-
ResponseFAIL(c, 404, data.Exception)
|
| 34 |
-
} else if data.Exception.InternalServerError {
|
| 35 |
-
ResponseFAIL(c, 500, data.Exception)
|
| 36 |
-
} else {
|
| 37 |
-
ResponseFAIL(c, 403, data.Exception)
|
| 38 |
-
}
|
| 39 |
-
}
|
| 40 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/Exception.go
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
package utils
|
|
|
|
|
|
utils/Helper.go
DELETED
|
@@ -1,11 +0,0 @@
|
|
| 1 |
-
package utils
|
| 2 |
-
|
| 3 |
-
import (
|
| 4 |
-
"api.qobiltu.id/models"
|
| 5 |
-
"github.com/gin-gonic/gin"
|
| 6 |
-
)
|
| 7 |
-
|
| 8 |
-
func GetAccount(c *gin.Context) models.AccountData {
|
| 9 |
-
cParam, _ := c.Get("accountData")
|
| 10 |
-
return cParam.(models.AccountData)
|
| 11 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/Logger.go
DELETED
|
@@ -1,21 +0,0 @@
|
|
| 1 |
-
package utils
|
| 2 |
-
|
| 3 |
-
import (
|
| 4 |
-
"fmt"
|
| 5 |
-
"log"
|
| 6 |
-
"os"
|
| 7 |
-
|
| 8 |
-
"api.qobiltu.id/config"
|
| 9 |
-
)
|
| 10 |
-
|
| 11 |
-
func LogError(errorLogged error) {
|
| 12 |
-
fmt.Println("There is an error!")
|
| 13 |
-
file, err := os.OpenFile(config.LOG_PATH+"error_log.txt", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666)
|
| 14 |
-
if err != nil {
|
| 15 |
-
log.Fatal(err)
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
log.SetOutput(file)
|
| 19 |
-
|
| 20 |
-
log.Println("Error Log :", errorLogged)
|
| 21 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/api_response.go
DELETED
|
@@ -1,52 +0,0 @@
|
|
| 1 |
-
package utils
|
| 2 |
-
|
| 3 |
-
import (
|
| 4 |
-
"net/http"
|
| 5 |
-
"reflect"
|
| 6 |
-
|
| 7 |
-
"api.qobiltu.id/models"
|
| 8 |
-
"api.qobiltu.id/services"
|
| 9 |
-
"github.com/gin-gonic/gin"
|
| 10 |
-
)
|
| 11 |
-
|
| 12 |
-
func ResponseOK(c *gin.Context, data any) {
|
| 13 |
-
res := models.SuccessResponse{
|
| 14 |
-
Status: "success",
|
| 15 |
-
Message: "Data retrieved successfully!",
|
| 16 |
-
Data: data,
|
| 17 |
-
MetaData: c.Request.Body,
|
| 18 |
-
}
|
| 19 |
-
c.JSON(http.StatusOK, res)
|
| 20 |
-
return
|
| 21 |
-
}
|
| 22 |
-
|
| 23 |
-
func ResponseFAIL(c *gin.Context, status int, exception models.Exception) {
|
| 24 |
-
message := exception.Message
|
| 25 |
-
exception.Message = ""
|
| 26 |
-
res := models.ErrorResponse{
|
| 27 |
-
Status: "error",
|
| 28 |
-
Message: message,
|
| 29 |
-
Errors: exception,
|
| 30 |
-
MetaData: c.Request.Body,
|
| 31 |
-
}
|
| 32 |
-
c.AbortWithStatusJSON(status, res)
|
| 33 |
-
return
|
| 34 |
-
}
|
| 35 |
-
|
| 36 |
-
func SendResponse(c *gin.Context, data services.Service[any, any]) {
|
| 37 |
-
if reflect.ValueOf(data.Exception).IsNil() {
|
| 38 |
-
ResponseOK(c, data)
|
| 39 |
-
} else {
|
| 40 |
-
if data.Exception.Unauthorized {
|
| 41 |
-
ResponseFAIL(c, 401, data.Exception)
|
| 42 |
-
} else if data.Exception.BadRequest {
|
| 43 |
-
ResponseFAIL(c, 400, data.Exception)
|
| 44 |
-
} else if data.Exception.DataNotFound {
|
| 45 |
-
ResponseFAIL(c, 404, data.Exception)
|
| 46 |
-
} else if data.Exception.InternalServerError {
|
| 47 |
-
ResponseFAIL(c, 500, data.Exception)
|
| 48 |
-
} else {
|
| 49 |
-
ResponseFAIL(c, 403, data.Exception)
|
| 50 |
-
}
|
| 51 |
-
}
|
| 52 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/util.go
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
package utils
|
| 2 |
-
|
| 3 |
-
func ternaryMessage(condition bool, valueIfTrue string, valueIfFalse string) string {
|
| 4 |
-
if condition {
|
| 5 |
-
return valueIfTrue
|
| 6 |
-
} else {
|
| 7 |
-
return valueIfFalse
|
| 8 |
-
}
|
| 9 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/utils.go
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
package utils
|
| 2 |
-
|
| 3 |
-
func ternaryMessage(condition bool, valueIfTrue string, valueIfFalse string) string {
|
| 4 |
-
if condition {
|
| 5 |
-
return valueIfTrue
|
| 6 |
-
} else {
|
| 7 |
-
return valueIfFalse
|
| 8 |
-
}
|
| 9 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|