package newshttp

import (
	newssvc "legalgo-BE-go/internal/services/news"
	"legalgo-BE-go/internal/utilities/response"
	"net/http"

	"github.com/go-chi/chi/v5"
)

func GetAll(
	router chi.Router,
	newsSvc newssvc.News,
) {
	router.Get("/news", func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()
		news, err := newsSvc.GetAll()
		if err != nil {
			response.ResponseWithErrorCode(
				ctx,
				w,
				err,
				response.ErrBadRequest.Code,
				response.ErrBadRequest.HttpCode,
				err.Error(),
			)
			return
		}

		response.RespondJsonSuccess(ctx, w, news)
	})
}
