fix code
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func PostData(url string, header *config.Header, headers map[string]string, request *suratkontrol.RequestHeaderRencanaKontrol) (*suratkontrol.ResponseInsert, error) {
|
||||
func PostData(url string, header *config.Header, headers map[string]string, request *suratkontrol.RequestHeaderRencanaKontrol) (*suratkontrol.Response, error) {
|
||||
log.Println("URL", url)
|
||||
|
||||
reqMarshall, err := json.Marshal(request)
|
||||
@@ -51,7 +51,7 @@ func PostData(url string, header *config.Header, headers map[string]string, requ
|
||||
|
||||
log.Println("Res:", string(res))
|
||||
|
||||
var resSuratKontrolRaw suratkontrol.ResponseInsertRaw
|
||||
var resSuratKontrolRaw suratkontrol.ResponseRaw
|
||||
err = json.Unmarshal([]byte(string(res)), &resSuratKontrolRaw)
|
||||
if err != nil {
|
||||
log.Printf("Error Unmarshaling: %v", err)
|
||||
@@ -60,7 +60,7 @@ func PostData(url string, header *config.Header, headers map[string]string, requ
|
||||
|
||||
log.Println("ResponseRaw : ", resSuratKontrolRaw)
|
||||
|
||||
responses := &suratkontrol.ResponseInsert{}
|
||||
responses := &suratkontrol.Response{}
|
||||
if resSuratKontrolRaw.MetaData.Code != "200" {
|
||||
errMsg := errors.New(resSuratKontrolRaw.MetaData.Message)
|
||||
log.Printf("error : %v", errMsg)
|
||||
@@ -87,7 +87,7 @@ func PostData(url string, header *config.Header, headers map[string]string, requ
|
||||
return nil, err
|
||||
}
|
||||
|
||||
responses = &suratkontrol.ResponseInsert{
|
||||
responses = &suratkontrol.Response{
|
||||
MetaData: resSuratKontrolRaw.MetaData,
|
||||
Response: resSuratKontrol,
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func PostData(url string, header *config.Header, headers map[string]string, requ
|
||||
return responses, nil
|
||||
}
|
||||
|
||||
func ResponseUpdateSuratKontrol(url string, header *config.Header, headers map[string]string, request *suratkontrol.RequestHeaderRencanaKontrol) (*suratkontrol.ResponseInsert, error) {
|
||||
func ResponseUpdateSuratKontrol(url string, header *config.Header, headers map[string]string, request *suratkontrol.RequestHeaderRencanaKontrol) (*suratkontrol.Response, error) {
|
||||
log.Println("URL", url)
|
||||
|
||||
reqMarshall, err := json.Marshal(request)
|
||||
@@ -138,7 +138,7 @@ func ResponseUpdateSuratKontrol(url string, header *config.Header, headers map[s
|
||||
return nil, err
|
||||
}
|
||||
|
||||
responses := &suratkontrol.ResponseInsert{}
|
||||
responses := &suratkontrol.Response{}
|
||||
if resSuratKontrolRaw.MetaData.Code != "200" {
|
||||
errMsg := errors.New(resSuratKontrolRaw.MetaData.Message)
|
||||
log.Printf("error : %v", errMsg)
|
||||
@@ -165,7 +165,7 @@ func ResponseUpdateSuratKontrol(url string, header *config.Header, headers map[s
|
||||
return nil, err
|
||||
}
|
||||
|
||||
responses = &suratkontrol.ResponseInsert{
|
||||
responses = &suratkontrol.Response{
|
||||
MetaData: resSuratKontrolRaw.MetaData,
|
||||
Response: *resSuratKontrol,
|
||||
}
|
||||
@@ -173,7 +173,7 @@ func ResponseUpdateSuratKontrol(url string, header *config.Header, headers map[s
|
||||
return responses, nil
|
||||
}
|
||||
|
||||
func ResponseDeleteSuratKontrol(url string, header *config.Header, headers map[string]string, request *suratkontrol.RequestHeaderRencanaKontrol) (interface{}, error) {
|
||||
func ResponseDeleteSuratKontrol(url string, header *config.Header, headers map[string]string, request *suratkontrol.RequestHeaderRencanaKontrol) (*suratkontrol.Response, error) {
|
||||
log.Println("URL", url)
|
||||
|
||||
reqMarshall, err := json.Marshal(request)
|
||||
@@ -213,9 +213,8 @@ func ResponseDeleteSuratKontrol(url string, header *config.Header, headers map[s
|
||||
return nil, err
|
||||
}
|
||||
|
||||
responses := &suratkontrol.ResponseUpper{
|
||||
responses := &suratkontrol.Response{
|
||||
MetaData: resSuratKontrolRaw.MetaData,
|
||||
Response: suratkontrol.ResponseSuratKontrol{},
|
||||
}
|
||||
|
||||
log.Println("res: ", responses)
|
||||
|
||||
@@ -290,6 +290,26 @@ func DeleteSuratKontrol(c *gin.Context) {
|
||||
|
||||
timeNow := time.Now().Format("2006-01-02 15:04:05")
|
||||
|
||||
if req.NomorSurKon == "" {
|
||||
reqUpdate := &sk.DataSuratKontrol{
|
||||
DateUpdated: timeNow,
|
||||
ID: req.IDDataSurKon,
|
||||
StatusSurKon: 0,
|
||||
}
|
||||
|
||||
err = suratkontrol.UpdateDataSuratKontrol(reqUpdate)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
c.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
res := &sk.MetadataString{
|
||||
Code: "200",
|
||||
Message: "Berhasil Hapus Data",
|
||||
}
|
||||
c.JSON(http.StatusOK, res)
|
||||
}
|
||||
|
||||
conf := config.ConfigBpjs{}
|
||||
|
||||
header := cfg.SetHeaderDev(conf)
|
||||
@@ -331,7 +351,6 @@ func DeleteSuratKontrol(c *gin.Context) {
|
||||
c.JSON(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, res)
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ func main() {
|
||||
suratKontrol.GET("/printSurKon/:idSurKon", suratkontrol.PrintSurKon)
|
||||
suratKontrol.POST("/insert", suratkontrol.InsertSuratKontrol)
|
||||
suratKontrol.PUT("/update", suratkontrol.UpdateSuratKontrol)
|
||||
suratKontrol.DELETE("/delete", suratkontrol.DeleteSuratKontrol)
|
||||
suratKontrol.POST("/delete", suratkontrol.DeleteSuratKontrol)
|
||||
}
|
||||
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
||||
@@ -58,8 +58,8 @@ type RequestDeleteRencanaKontrol struct {
|
||||
}
|
||||
|
||||
type ResponseRaw struct {
|
||||
Response string `json:"response"`
|
||||
MetaData Metadata `json:"metadata"`
|
||||
Response string `json:"response"`
|
||||
MetaData MetadataString `json:"metadata"`
|
||||
}
|
||||
|
||||
type ResponseRawUpper struct {
|
||||
@@ -92,7 +92,7 @@ type ResponseGetSuratKontrolBySEP struct {
|
||||
Response ResponseSuratKontrolBySEP `json:"response"`
|
||||
}
|
||||
|
||||
type ResponseInsert struct {
|
||||
type Response struct {
|
||||
MetaData MetadataString `json:"metadata"`
|
||||
Response ResponseSuratKontrol `json:"response"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user