| 123456789101112131415161718192021222324252627 |
- package api
- import (
- "encoding/json"
- "net/http"
- "GoApi/internal/repository"
- )
- type EventController struct {
- Repo repository.EventRepository
- }
- func NewEventController(repo repository.EventRepository) EventController {
- return EventController{Repo: repo}
- }
- func (c EventController) GetEventsHandler(w http.ResponseWriter, r *http.Request) {
- events, err := c.Repo.GetEvents()
- if err != nil {
- http.Error(w, "ERROR: Not found events", http.StatusInternalServerError)
- return
- }
- w.Header().Set("Content-Type", "application/json")
- json.NewEncoder(w).Encode(events)
- }
|