@@ -40,7 +40,7 @@ func TeamCreationHandler(rtr *router.Router) http.HandlerFunc {
4040 if err := json .NewDecoder (r .Body ).Decode (& t ); err != nil {
4141
4242 //http.Error(w, "error reading teamName field, invalid json payload", http.StatusBadRequest)
43- w .WriteHeader (http .StatusBadRequest )
43+ // w.WriteHeader(http.StatusBadRequest)
4444 apiResponse := types.ApiResponse {
4545 Success : false ,
4646 Message : "invalid json payload" ,
@@ -94,9 +94,15 @@ func TeamCreationHandler(rtr *router.Router) http.HandlerFunc {
9494
9595 go teamChannel .Start ()
9696
97- json .NewEncoder (w ).Encode (map [string ]string {
98- "team_id" : teamId ,
99- })
97+ payload , _ := json .Marshal (map [string ]string {"team_id" : teamId })
98+
99+ apiResponse := types.ApiResponse {
100+ Success : true ,
101+ Message : "success" ,
102+ Payload : payload ,
103+ }
104+
105+ json .NewEncoder (w ).Encode (apiResponse )
100106
101107 })
102108
@@ -126,7 +132,16 @@ func TeamUpdateHandler(rtr *router.Router) http.HandlerFunc {
126132
127133 if err := json .NewDecoder (r .Body ).Decode (& t ); err != nil {
128134
129- http .Error (w , "error getting team_id field, invalid json payload" , http .StatusBadRequest )
135+ //http.Error(w, "error getting team_id field, invalid json payload", http.StatusBadRequest)
136+
137+ apiResponse := types.ApiResponse {
138+ Success : false ,
139+ Message : "error getting team_id from json payload" ,
140+ Payload : nil ,
141+ }
142+
143+ json .NewEncoder (w ).Encode (apiResponse )
144+
130145 return
131146
132147 }
@@ -155,7 +170,15 @@ func TeamUpdateHandler(rtr *router.Router) http.HandlerFunc {
155170 teamChannel := rtr .State .ChanPool .GetChannel (team .ID )
156171 teamChannel .Broadcast (protocol.Packet {Type : "BackgroundMessage" , BackgroundMessage : protocol.BackgroundMessage {Relay : fmt .Sprintf ("teamId:%s -> %s joined the team" , team .ID , profile .Email ), MsgContext : "channel_creation" }})
157172
158- if err := json .NewEncoder (w ).Encode (team ); err != nil {
173+ payload , _ := json .Marshal (team )
174+
175+ apiResponse := types.ApiResponse {
176+ Success : true ,
177+ Message : "Member added to team successfully!" ,
178+ Payload : payload ,
179+ }
180+
181+ if err := json .NewEncoder (w ).Encode (apiResponse ); err != nil {
159182 http .Error (w , "error encoding response" , http .StatusInternalServerError )
160183 }
161184
@@ -186,10 +209,18 @@ func GetTeamHandler(rtr *router.Router) http.HandlerFunc {
186209
187210 if teamId == "" && userId == "" {
188211 //http.Error(w, "Either user_id or team_id must be provided", http.StatusBadRequest)
189- w .WriteHeader (http .StatusBadRequest )
190- json .NewEncoder (w ).Encode (map [string ]string {
191- "error" : "either used_id or team_id not provided" ,
192- })
212+ //w.WriteHeader(http.StatusBadRequest)
213+ //json.NewEncoder(w).Encode(map[string]string{
214+ // "error": "either user_id or team_id not provided",
215+ //})
216+
217+ apiResponse := types.ApiResponse {
218+ Success : false ,
219+ Message : "either user_id or team_id not provided" ,
220+ Payload : nil ,
221+ }
222+ json .NewEncoder (w ).Encode (apiResponse )
223+
193224 return
194225 }
195226
@@ -202,18 +233,26 @@ func GetTeamHandler(rtr *router.Router) http.HandlerFunc {
202233 parsedId , parseErr := uuid .Parse (userId )
203234 if parseErr != nil {
204235 //http.Error(w, "invalid player_id format", http.StatusBadRequest)
205- w .WriteHeader (http .StatusBadRequest )
206- json .NewEncoder (w ).Encode (map [string ]string {
207- "error" : "player id format is invalid, should be uuid string" ,
208- })
236+ //w.WriteHeader(http.StatusBadRequest)
237+ //json.NewEncoder(w).Encode(map[string]string{
238+ // "error": "player id format is invalid, should be uuid string",
239+ //})
240+
241+ apiResponse := types.ApiResponse {
242+ Success : false ,
243+ Message : "player id format is invalid, should be uuid string" ,
244+ Payload : nil ,
245+ }
246+ json .NewEncoder (w ).Encode (apiResponse )
247+
209248 }
210249 team , err = rtr .State .DB .GetTeamByUserId (context .Background (), parsedId )
211250 }
212251
213252 if err != nil {
214253 rtr .Logger .Error ("failed to fetch team" , slog .String ("error" , err .Error ()))
215254 //http.Error(w, "internal server error", http.StatusInternalServerError)
216- w .WriteHeader (http .StatusBadRequest )
255+ w .WriteHeader (http .StatusInternalServerError )
217256 json .NewEncoder (w ).Encode (map [string ]string {
218257 "error" : "internal server error" ,
219258 })
0 commit comments