handleDialView handles the "GET /dials/:id" route. It updates
(w http.ResponseWriter, r *http.Request)
| 107 | |
| 108 | // handleDialView handles the "GET /dials/:id" route. It updates |
| 109 | func (s *Server) handleDialView(w http.ResponseWriter, r *http.Request) { |
| 110 | // Parse ID from path. |
| 111 | id, err := strconv.Atoi(mux.Vars(r)["id"]) |
| 112 | if err != nil { |
| 113 | Error(w, r, wtf.Errorf(wtf.EINVALID, "Invalid ID format")) |
| 114 | return |
| 115 | } |
| 116 | |
| 117 | // Fetch dial from the database. |
| 118 | dial, err := s.DialService.FindDialByID(r.Context(), id) |
| 119 | if err != nil { |
| 120 | Error(w, r, err) |
| 121 | return |
| 122 | } |
| 123 | |
| 124 | // Fetch associated memberships from the database. |
| 125 | dial.Memberships, _, err = s.DialMembershipService.FindDialMemberships(r.Context(), wtf.DialMembershipFilter{DialID: &dial.ID}) |
| 126 | if err != nil { |
| 127 | Error(w, r, err) |
| 128 | return |
| 129 | } |
| 130 | |
| 131 | // Format returned data based on HTTP accept header. |
| 132 | switch r.Header.Get("Accept") { |
| 133 | case "application/json": |
| 134 | w.Header().Set("Content-type", "application/json") |
| 135 | if err := json.NewEncoder(w).Encode(dial); err != nil { |
| 136 | LogError(r, err) |
| 137 | return |
| 138 | } |
| 139 | |
| 140 | default: |
| 141 | tmpl := html.DialViewTemplate{ |
| 142 | Dial: dial, |
| 143 | InviteURL: fmt.Sprintf("%s/invite/%s", s.URL(), dial.InviteCode), |
| 144 | } |
| 145 | tmpl.Render(r.Context(), w) |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | // handleDialNew handles the "GET /dials/new" route. |
| 150 | // It renders an HTML form for editing a new dial. |
nothing calls this directly
no test coverage detected