diff --git a/apiclient/sources.go b/apiclient/sources.go index 5af6d9f..0d9f9b7 100644 --- a/apiclient/sources.go +++ b/apiclient/sources.go @@ -16,6 +16,7 @@ const ( type Sources interface { ListAll(jwt string, page int) (domain.SourcesResponse, error) GetById(jwt string, id int64) (domain.SourcesResponse, error) + NewRss(jwt, name, url, sourceType string) (domain.SourcesResponse, error) } type sourceClient struct { @@ -53,7 +54,7 @@ func (c sourceClient) ListAll(jwt string, page int) (domain.SourcesResponse, err return bind, err } - if (resp.StatusCode != 200) { + if resp.StatusCode != 200 { return bind, errors.New(bind.Message) } @@ -69,9 +70,33 @@ func (c sourceClient) GetById(jwt string, id int64) (domain.SourcesResponse, err return bind, err } - if (statusCode != 200) { + if statusCode != 200 { return bind, errors.New(bind.Message) } return bind, nil } + +func (c sourceClient) NewRss(jwt, name, url, sourceType string) (domain.SourcesResponse, error) { + param := domain.NewSourceParamRequest{ + Name: name, + Url: url, + Tags: "", + } + bind := domain.SourcesResponse{} + var endpoint string + if sourceType == domain.SourceCollectorRss { + endpoint = fmt.Sprintf("%s/%s/new/rss", c.serverAddress, SourcesBaseRoute) + } + + statusCode, err := PostBodyUrlAuthorized(c.client, endpoint, jwt, param, &bind) + if err != nil { + return bind, err + } + + if statusCode != 200 { + return bind, errors.New("got the wrong status code back from the API") + } + + return bind, nil +} diff --git a/apiclient/util.go b/apiclient/util.go index 8be09a0..d161eb9 100644 --- a/apiclient/util.go +++ b/apiclient/util.go @@ -58,6 +58,35 @@ func PostUrlAuthorized(client http.Client, endpoint, jwtToken string, t any) err return nil } +func PostBodyUrlAuthorized(client http.Client, endpoint, jwtToken string, body any, t any) (int, error) { + jsonBody, err := json.Marshal(body) + if err != nil { + return 0, err + } + + req, err := http.NewRequest(http.MethodPost, endpoint, bytes.NewBuffer(jsonBody)) + if err != nil { + return 0, err + } + req.Header.Add(HeaderAuthorization, fmt.Sprintf("%s %s", "Bearer", jwtToken)) + req.Header.Add(HeaderContentType, ApplicationJson) + + //response, err := http.Post(endpoint, ApplicationJson, bytes.NewBuffer(jsonBody)) + response, err := client.Do(req) + if err != nil { + return response.StatusCode, err + } + + defer response.Body.Close() + decoder := json.NewDecoder(response.Body) + err = decoder.Decode(&t) + if err != nil { + return response.StatusCode, err + } + + return response.StatusCode, nil +} + func PostBodyUrl(client http.Client, endpoint string, body any, t any) error { jsonBody, err := json.Marshal(body) if err != nil { @@ -79,6 +108,22 @@ func PostBodyUrl(client http.Client, endpoint string, body any, t any) error { return nil } +func PostQuery(client http.Client, endpoint string, t any) (int, error) { + response, err := http.Post(endpoint, ApplicationJson, nil) + if err != nil { + return response.StatusCode, err + } + + defer response.Body.Close() + decoder := json.NewDecoder(response.Body) + err = decoder.Decode(&t) + if err != nil { + return response.StatusCode, err + } + + return response.StatusCode, nil +} + func Get(client http.Client, endpoint, jwt string, t any) (int, error) { req, err := http.NewRequest(http.MethodGet, endpoint, nil) if err != nil { diff --git a/components/bulma/block.templ b/components/bulma/block.templ new file mode 100644 index 0000000..57d129b --- /dev/null +++ b/components/bulma/block.templ @@ -0,0 +1,8 @@ +package bulma + +// Simple spacer that accepts children +templ Block() { +
+ { children... } +
+} \ No newline at end of file diff --git a/components/bulma/button.templ b/components/bulma/button.templ new file mode 100644 index 0000000..5385978 --- /dev/null +++ b/components/bulma/button.templ @@ -0,0 +1,30 @@ +package bulma + +// This creates a button that accepts children under it. +templ Button() { + +} + +// Used to create a button and lets you define the color. +// Accepts children. +templ ButtonColor(color string) { + +} + +templ ButtonNewTab(url, text string) { + +} + +templ ALink(url, title string) { + { title } +} + +templ ANewTab(url, text string) { + { text } +} diff --git a/internal/views/bulma/card.templ b/components/bulma/card.templ similarity index 100% rename from internal/views/bulma/card.templ rename to components/bulma/card.templ diff --git a/components/bulma/example/example.templ b/components/bulma/example/example.templ new file mode 100644 index 0000000..8940fe2 --- /dev/null +++ b/components/bulma/example/example.templ @@ -0,0 +1,19 @@ +package example + +import "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma" +import "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/html" +import "git.jamestombleson.com/jtom38/newsbot-portal/components/bulma/layout" + +templ example() { + @html.Doctype() + @html.New("en"){ + @html.NewHeader(){ + @bulma.UseBulmaCdn() + } + @html.NewBody() { + @layout.Container(bulma.BreakpointDefault) { + { children... } + } + } + } +} \ No newline at end of file diff --git a/components/bulma/example/layout.templ b/components/bulma/example/layout.templ new file mode 100644 index 0000000..f7ec372 --- /dev/null +++ b/components/bulma/example/layout.templ @@ -0,0 +1 @@ +package example diff --git a/components/bulma/form/control.templ b/components/bulma/form/control.templ new file mode 100644 index 0000000..d5183b2 --- /dev/null +++ b/components/bulma/form/control.templ @@ -0,0 +1,8 @@ +package form + +// Div container to add a input field to. +templ Control() { +
+ { children... } +
+} \ No newline at end of file diff --git a/components/bulma/form/field.templ b/components/bulma/form/field.templ new file mode 100644 index 0000000..ad7b0c3 --- /dev/null +++ b/components/bulma/form/field.templ @@ -0,0 +1,8 @@ +package form + +// This creates a field that you can add a Label, Control or Input object. +templ Field() { +
+ { children... } +
+} \ No newline at end of file diff --git a/components/bulma/form/input.templ b/components/bulma/form/input.templ new file mode 100644 index 0000000..12a45bc --- /dev/null +++ b/components/bulma/form/input.templ @@ -0,0 +1,19 @@ +package form + +templ TextInput(id, fieldType, placeholder string) { + +} + +templ TextInputColor(color, id, fieldType, placeholder string) { + if color == "" { + + } else { + + } +} + +templ Checkbox(text, id string) { + +} diff --git a/components/bulma/form/label.templ b/components/bulma/form/label.templ new file mode 100644 index 0000000..66deea3 --- /dev/null +++ b/components/bulma/form/label.templ @@ -0,0 +1,6 @@ +package form + +// This will create a small bit of text to add context to the form. +templ Label(text string) { + +} \ No newline at end of file diff --git a/components/bulma/form/new.templ b/components/bulma/form/new.templ new file mode 100644 index 0000000..8f5029e --- /dev/null +++ b/components/bulma/form/new.templ @@ -0,0 +1,13 @@ +package form + +type NewParam struct { + HxPost string +} + +templ New(param NewParam) { + if param.HxPost != "" { +
+ { children... } +
+ } +} diff --git a/components/bulma/form/select.templ b/components/bulma/form/select.templ new file mode 100644 index 0000000..8adffdc --- /dev/null +++ b/components/bulma/form/select.templ @@ -0,0 +1,33 @@ +package form + +templ SelectOne(color string, isRound bool) { + if isRound { +
+ +
+ } else { +
+ +
+ } +} + +templ SelectOneItem(name string) { + +} + +templ SelectMany(howManySelectable int, color string, isRound bool) { +
+ +
+} + +templ SelectManyItem(name string) { + +} diff --git a/components/bulma/form/submit.templ b/components/bulma/form/submit.templ new file mode 100644 index 0000000..e12ada7 --- /dev/null +++ b/components/bulma/form/submit.templ @@ -0,0 +1,5 @@ +package form + +templ Submit(text, color string) { + +} \ No newline at end of file diff --git a/components/bulma/form/textarea.templ b/components/bulma/form/textarea.templ new file mode 100644 index 0000000..d922742 --- /dev/null +++ b/components/bulma/form/textarea.templ @@ -0,0 +1,5 @@ +package form + +templ TextArea(id, placeholder, color string) { +