rentease/internal/server/handle_api_sync.go
Ruidy ac94faedb0
refactor: unify ID and API key naming conventions
This commit standardizes the naming of identifier and API key fields
across the codebase to use consistent camel case (e.g., `ID`, `APIKey`,
`DatabaseURL`). This includes updates to struct fields, method names,
function parameters, and environment variable references. The changes
improve code clarity and maintainability by reducing ambiguity and
aligning with Go naming conventions. No functional behavior is changed.
2025-10-03 19:47:41 +02:00

71 lines
1.8 KiB
Go

package server
import (
"encoding/json"
"fmt"
"io"
"net/http"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/log"
"github.com/rjNemo/rentease/internal/service/booking"
)
func handleSync(bs *booking.Service) echo.HandlerFunc {
type BookingInfo struct {
Content string `json:"content"`
}
return func(c echo.Context) error {
log.Info("received booking sync request from booking")
x := c.Request().Body
body, err := io.ReadAll(x)
if err != nil {
return c.String(http.StatusInternalServerError, err.Error())
}
bookingInfo := new(BookingInfo)
err = json.Unmarshal(body, bookingInfo)
if err != nil {
return c.String(http.StatusInternalServerError, fmt.Sprintf("error unmarshalling JSON: %s", err))
}
b, err := bs.ParseFromAPI(bookingInfo.Content)
if err != nil {
return c.String(http.StatusInternalServerError, err.Error())
}
log.Infof("created booking %q from %q", b.Name, b.Platform)
return c.JSON(http.StatusCreated, "👍")
}
}
func handleCreateBooking(bs *booking.Service) echo.HandlerFunc {
type BookingInfo struct {
Content string `json:"content"`
}
return func(c echo.Context) error {
log.Info("received booking sync request from booking")
x := c.Request().Body
body, err := io.ReadAll(x)
if err != nil {
return c.String(http.StatusInternalServerError, err.Error())
}
log.Info(string(body))
bookingInfo := new(BookingInfo)
err = json.Unmarshal(body, bookingInfo)
if err != nil {
return c.String(http.StatusInternalServerError, fmt.Sprintf("error unmarshalling JSON: %s", err))
}
b, err := bs.ParseFromAPI(bookingInfo.Content)
if err != nil {
return c.String(http.StatusInternalServerError, err.Error())
}
log.Infof("created booking %q from %q", b.Name, b.Platform)
return c.JSON(http.StatusCreated, "👍")
}
}