Skip to content

Commit 40320c0

Browse files
committed
Add edit user handler
1 parent 20de033 commit 40320c0

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

backend/circles/handler.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,32 @@ func GetInviteUsersHandler(w http.ResponseWriter, r *http.Request) {
8585
json.NewEncoder(w).Encode(users)
8686
}
8787

88+
func GetEditUsersHandler(w http.ResponseWriter, r *http.Request) {
89+
userID := r.Context().Value(middleware.UserIDKey).(string)
90+
type Circle struct {
91+
ID string `json:"circle_id"`
92+
}
93+
var circle Circle
94+
err := json.NewDecoder(r.Body).Decode(&circle)
95+
if err != nil {
96+
fmt.Printf("HTTP 400 bad request\n")
97+
w.WriteHeader(http.StatusBadRequest)
98+
json.NewEncoder(w).Encode("HTTP 400 bad request")
99+
return
100+
}
101+
fmt.Println("Circle ID EDIT: " + circle.ID + " USER ID: " + userID)
102+
users, err := postgres.GetInviteUsersInCircle(userID, circle.ID)
103+
if err != nil {
104+
fmt.Printf("Failed to get users in circle\n")
105+
w.WriteHeader(http.StatusInternalServerError)
106+
json.NewEncoder(w).Encode("Failed to get users in circle")
107+
return
108+
}
109+
fmt.Printf("Users in circle: %v\n", users)
110+
w.WriteHeader(http.StatusOK)
111+
json.NewEncoder(w).Encode(users)
112+
}
113+
88114
func CreateCircleHandler(w http.ResponseWriter, r *http.Request, hub *websockets.Hub) {
89115
var createCircleData models.CreateCircleData
90116
err := json.NewDecoder(r.Body).Decode(&createCircleData)

backend/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ func main() {
8484
}),
8585
),
8686
))
87+
mux.Handle("/api/circles/edit", middleware.AddCorsHeaders(
88+
middleware.AuthMiddleware(
89+
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
90+
circles.GetEditUsersHandler(w, r)
91+
}),
92+
),
93+
))
8794
mux.Handle("/api/circles/delete/{id}", middleware.AddCorsHeaders(
8895
middleware.AuthMiddleware(
8996
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)