@@ -2,6 +2,7 @@ package handler
22
33import (
44 "encoding/json"
5+ "fmt"
56 "net/http"
67 "worker-session/internal/session"
78
@@ -25,14 +26,14 @@ func getParams(r *http.Request) (string, string, string) {
2526 return group , instance , key
2627}
2728
28- func (h * Session ) POST_GroupFolder (r * http.Request ) * Response {
29+ func (h * Session ) POST_Group (r * http.Request ) * Response {
2930 var body map [string ]string
3031 e := render .DecodeJSON (r .Body , & body )
3132 if err := UnmarshalDescriptionError (e ); err != nil {
3233 return err
3334 }
3435
35- status , err := h .service .CreateFolder (body ["group" ], "" )
36+ status , err := h .service .CreateGroup (body ["group" ])
3637
3738 response := NewResponse (status )
3839
@@ -44,7 +45,24 @@ func (h *Session) POST_GroupFolder(r *http.Request) *Response {
4445 return response
4546}
4647
47- func (h * Session ) POST_InstanceFolder (r * http.Request ) * Response {
48+ func (h * Session ) DELETE_Group (r * http.Request ) * Response {
49+ params_group , _ , _ := getParams (r )
50+
51+ status , err := h .service .RemoveGroup (params_group )
52+
53+ response := NewResponse (status )
54+
55+ if err != nil {
56+ response .SetError (err )
57+ return response
58+ }
59+
60+ response .SetCode (status )
61+
62+ return response
63+ }
64+
65+ func (h * Session ) POST_InstanceDB (r * http.Request ) * Response {
4866 var body map [string ]string
4967 e := render .DecodeJSON (r .Body , & body )
5068 if err := UnmarshalDescriptionError (e ); err != nil {
@@ -53,7 +71,7 @@ func (h *Session) POST_InstanceFolder(r *http.Request) *Response {
5371
5472 params_group , _ , _ := getParams (r )
5573
56- status , err := h .service .CreateFolder (params_group , body ["instance" ])
74+ status , err := h .service .CreateInstanceDb (params_group , body ["instance" ])
5775
5876 response := NewResponse (status )
5977
@@ -65,10 +83,10 @@ func (h *Session) POST_InstanceFolder(r *http.Request) *Response {
6583 return response
6684}
6785
68- func (h * Session ) DELETE_InstanceFolder (r * http.Request ) * Response {
86+ func (h * Session ) DELETE_InstanceDB (r * http.Request ) * Response {
6987 params_group , params_instance , _ := getParams (r )
7088
71- status , err := h .service .RemoveFolder (params_group , params_instance )
89+ status , err := h .service .RemoveInstanceDb (params_group , params_instance )
7290
7391 response := NewResponse (status )
7492
@@ -83,7 +101,7 @@ func (h *Session) DELETE_InstanceFolder(r *http.Request) *Response {
83101}
84102
85103func (h * Session ) POST_Credentials (r * http.Request ) * Response {
86- var body map [string ]string
104+ var body map [string ]any
87105 e := render .DecodeJSON (r .Body , & body )
88106 if err := UnmarshalDescriptionError (e ); err != nil {
89107 return err
@@ -119,9 +137,15 @@ func (h *Session) GET_Credentials(r *http.Request) *Response {
119137 return response
120138 }
121139
140+ json_str := string (binary )
141+ var unescaped string
142+ json .Unmarshal ([]byte (json_str ), & unescaped )
143+
122144 var data map [string ]any
123- err = json .Unmarshal (binary , & data )
145+ err = json .Unmarshal ([]byte (unescaped ), & data )
146+ fmt .Println ("2" )
124147 if err != nil {
148+ response .SetCode (http .StatusBadRequest )
125149 response .SetError (err )
126150 return response
127151 }
0 commit comments