Skip to content

Commit

Permalink
schedule create
Browse files Browse the repository at this point in the history
  • Loading branch information
mstgnz committed Jul 7, 2024
1 parent 00c9ebe commit afd84e9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
9 changes: 9 additions & 0 deletions config/conf.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"io"
"log"
"math"
"net/http"
Expand Down Expand Up @@ -132,3 +133,11 @@ func ActiveClass(a, b int) string {
}
return active
}

func WriteBody(r *http.Request) {
if body, err := io.ReadAll(r.Body); err != nil {
log.Println("WriteBody: ", err)
} else {
log.Println("WriteBody: ", string(body))
}
}
37 changes: 36 additions & 1 deletion handler/web/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,42 @@ func (h *ScheduleHandler) HomeHandler(w http.ResponseWriter, r *http.Request) er
}

func (h *ScheduleHandler) CreateHandler(w http.ResponseWriter, r *http.Request) error {
jsonData, err := config.ConvertStringBoolsToBool(r, "active")
jsonData, err := config.ConvertStringIDsToInt(r, "group_id")
if err != nil {
_, _ = w.Write([]byte(err.Error()))
return nil
}
r.Body = io.NopCloser(strings.NewReader(string(jsonData)))

jsonData, err = config.ConvertStringIDsToInt(r, "request_id")
if err != nil {
_, _ = w.Write([]byte(err.Error()))
return nil
}
r.Body = io.NopCloser(strings.NewReader(string(jsonData)))

jsonData, err = config.ConvertStringIDsToInt(r, "notification_id")
if err != nil {
_, _ = w.Write([]byte(err.Error()))
return nil
}
r.Body = io.NopCloser(strings.NewReader(string(jsonData)))

jsonData, err = config.ConvertStringIDsToInt(r, "timeout")
if err != nil {
_, _ = w.Write([]byte(err.Error()))
return nil
}
r.Body = io.NopCloser(strings.NewReader(string(jsonData)))

jsonData, err = config.ConvertStringIDsToInt(r, "retries")
if err != nil {
_, _ = w.Write([]byte(err.Error()))
return nil
}
r.Body = io.NopCloser(strings.NewReader(string(jsonData)))

jsonData, err = config.ConvertStringBoolsToBool(r, "active")
if err != nil {
_, _ = w.Write([]byte(err.Error()))
return nil
Expand Down
6 changes: 3 additions & 3 deletions views/components/schedule/new.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{define "scheduleNew" }}
<div class="row justify-content-center mt-2">
<div class="col-8">
<form hx-post="/requests" hx-target="#request-toast" hx-ext="json-enc" novalidate autocomplete="off">
<form hx-post="/schedules" hx-target="#schedule" hx-ext="json-enc" novalidate autocomplete="off">
<div class="form-floating mb-2">
<select class="form-select" name="group_id" required>
<option value="0" selected>Choose Group</option>
Expand Down Expand Up @@ -50,8 +50,8 @@
</select>
<label for="active">Status</label>
</div>
<button type="submit" class="btn btn-primary w-100 py-2 mb-1">Request Save</button>
<span id="request-toast"></span>
<button type="submit" class="btn btn-primary w-100 py-2 mb-1">Schedule Save</button>
<span id="schedule"></span>
</form>
</div>
</div>
Expand Down

0 comments on commit afd84e9

Please sign in to comment.