feat: add frontend + backend + database to retrieve and compute news from Yahoo

This commit is contained in:
2026-04-18 23:53:57 +02:00
parent f9b6d35c49
commit 93668273ff
84 changed files with 15431 additions and 0 deletions

View File

@ -0,0 +1,48 @@
package httputil
import (
"net/http"
"reflect"
"github.com/gin-gonic/gin"
)
// nilToEmpty converts nil slices to empty slices so JSON serializes as [] not null
func nilToEmpty(data interface{}) interface{} {
if data == nil {
return data
}
v := reflect.ValueOf(data)
if v.Kind() == reflect.Slice && v.IsNil() {
return reflect.MakeSlice(v.Type(), 0, 0).Interface()
}
return data
}
func OK(c *gin.Context, data interface{}) {
c.JSON(http.StatusOK, gin.H{"data": nilToEmpty(data)})
}
func Created(c *gin.Context, data interface{}) {
c.JSON(http.StatusCreated, gin.H{"data": nilToEmpty(data)})
}
func NoContent(c *gin.Context) {
c.Status(http.StatusNoContent)
}
func BadRequest(c *gin.Context, err error) {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
}
func Unauthorized(c *gin.Context) {
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthorized"})
}
func NotFound(c *gin.Context) {
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
}
func InternalError(c *gin.Context, err error) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
}