feat:#34 refactored function to intended service, fixed docker files

This commit is contained in:
Elmar Kresse
2024-06-10 16:57:40 +02:00
parent cb76b5c188
commit 2d7701b0c9
96 changed files with 212 additions and 79 deletions

View File

@@ -2,6 +2,7 @@ package connector
import (
"encoding/json"
"errors"
"htwkalender-ical/model"
"log/slog"
)
@@ -77,3 +78,24 @@ func parseModuleResponse(body []byte) (model.Module, error) {
return module, nil
}
func SaveFeedRecord(modules []model.FeedCollection) (string, error) {
var token string
response, err := PostRequestApi("/api/feed", modules)
if err != nil {
return "", err
}
if response.StatusCode() != 200 {
return "", errors.New("failed to save feed")
}
// parse the response body json to string
err = json.Unmarshal(response.Body(), &token)
if err != nil {
return "", err
}
return token, nil
}

View File

@@ -2,12 +2,13 @@ package connector
import (
"github.com/gofiber/fiber/v3/client"
"htwkalender-ical/model"
"time"
)
func RequestApi(path string) (*client.Response, error) {
const host = "http://127.0.0.1:8090"
var host = "http://htwkalender-backend:8090"
func RequestApi(path string) (*client.Response, error) {
cc := client.New()
cc.SetTimeout(5 * time.Second)
@@ -23,8 +24,6 @@ func RequestApi(path string) (*client.Response, error) {
func DeleteRequestApi(path string) error {
var host = "http://htwkalender-backend:8090"
cc := client.New()
cc.SetTimeout(5 * time.Second)
@@ -36,3 +35,25 @@ func DeleteRequestApi(path string) error {
return nil
}
func PostRequestApi(path string, body []model.FeedCollection) (*client.Response, error) {
cc := client.New()
cc.SetTimeout(5 * time.Second)
config := client.Config{
Body: body,
Header: map[string]string{
"Content-Type": "application/json",
"Accept": "*/*",
},
}
// set retry to 0
response, err := cc.Post(host+path, config)
if err != nil {
return nil, err
}
return response, nil
}