mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-10 21:53:51 +02:00
feat:#34 refactored function to intended service, fixed docker files
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user