feat: get news by slug and and author detail

This commit is contained in:
ericprd
2025-03-06 11:06:06 +08:00
parent d217ec8a62
commit 85247643e6
9 changed files with 76 additions and 1 deletions
+34
View File
@@ -0,0 +1,34 @@
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 GetBySlug(
router chi.Router,
newsSvc newssvc.News,
) {
router.Get("/news/{slug}", func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
slug := chi.URLParam(r, "slug")
news, err := newsSvc.GetBySlug(slug)
if err != nil {
response.ResponseWithErrorCode(
ctx,
w,
err,
response.ErrBadRequest.Code,
response.ErrBadRequest.HttpCode,
err.Error(),
)
return
}
response.RespondJsonSuccess(ctx, w, news)
})
}
+1
View File
@@ -4,6 +4,7 @@ import "go.uber.org/fx"
var Module = fx.Module("news", fx.Invoke(
GetAll,
GetBySlug,
Create,
Delete,
))