|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "encoding/json" |
| 6 | + "fmt" |
| 7 | + "io" |
| 8 | + "os" |
| 9 | + "strconv" |
| 10 | + |
| 11 | + "github.com/authorhealth/go-elation" |
| 12 | + "github.com/spf13/cobra" |
| 13 | +) |
| 14 | + |
| 15 | +var getAppointment = &cobra.Command{ |
| 16 | + Use: "get-appointment [appointment ID]", |
| 17 | + Args: cobra.ExactArgs(1), |
| 18 | + Run: wrapRunFunc(func(ctx context.Context, client elation.Client, args []string) error { |
| 19 | + appointmentID, _ := strconv.ParseInt(args[0], 10, 64) |
| 20 | + response, _, err := client.Appointments().Get(ctx, appointmentID) |
| 21 | + if err != nil { |
| 22 | + return err |
| 23 | + } |
| 24 | + |
| 25 | + responseJson, err := json.Marshal(response) |
| 26 | + if err != nil { |
| 27 | + return err |
| 28 | + } |
| 29 | + |
| 30 | + _, err = fmt.Fprintln(os.Stdout, string(responseJson)) |
| 31 | + |
| 32 | + return err |
| 33 | + }), |
| 34 | +} |
| 35 | + |
| 36 | +var updateAppointment = &cobra.Command{ |
| 37 | + Use: "update-appointment [appointment ID]", |
| 38 | + Args: cobra.ExactArgs(1), |
| 39 | + Run: wrapRunFunc(func(ctx context.Context, client elation.Client, args []string) error { |
| 40 | + appointmentID, _ := strconv.ParseInt(args[0], 10, 64) |
| 41 | + requestBytes, err := io.ReadAll(os.Stdin) |
| 42 | + if err != nil { |
| 43 | + return err |
| 44 | + } |
| 45 | + |
| 46 | + request := &elation.AppointmentUpdate{} |
| 47 | + err = json.Unmarshal(requestBytes, request) |
| 48 | + if err != nil { |
| 49 | + return err |
| 50 | + } |
| 51 | + |
| 52 | + response, _, err := client.Appointments().Update(ctx, appointmentID, request) |
| 53 | + if err != nil { |
| 54 | + return err |
| 55 | + } |
| 56 | + |
| 57 | + responseJson, err := json.Marshal(response) |
| 58 | + if err != nil { |
| 59 | + return err |
| 60 | + } |
| 61 | + |
| 62 | + _, err = fmt.Fprintln(os.Stdout, string(responseJson)) |
| 63 | + |
| 64 | + return err |
| 65 | + }), |
| 66 | +} |
| 67 | + |
| 68 | +func init() { |
| 69 | + rootCmd.AddCommand(getAppointment) |
| 70 | + rootCmd.AddCommand(updateAppointment) |
| 71 | +} |
0 commit comments