From b323e6940de1ef3dd88f0226c45db382d84cd542 Mon Sep 17 00:00:00 2001 From: Ernela Date: Tue, 25 Nov 2025 17:35:18 +0200 Subject: [PATCH] add supporters list --- api/index.go | 3 +++ main.go | 3 +++ pkg/handlers/support.go | 59 +++++++++++++++++++++++++++++++++++++++++ supporters-list.json | 35 ++++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 pkg/handlers/support.go create mode 100644 supporters-list.json diff --git a/api/index.go b/api/index.go index 95f9960..ca64056 100644 --- a/api/index.go +++ b/api/index.go @@ -69,6 +69,7 @@ func Handler(w http.ResponseWriter, r *http.Request) { torrentsHandler := handlersPkg.NewTorrentsHandler(torrentService, tmdbService) reactionsHandler := handlersPkg.NewReactionsHandler(reactionsService) imagesHandler := handlersPkg.NewImagesHandler() + supportHandler := handlersPkg.NewSupportHandler() router := mux.NewRouter() @@ -115,6 +116,8 @@ func Handler(w http.ResponseWriter, r *http.Request) { api.HandleFunc("/images/{type}/{id}", imagesHandler.GetImage).Methods("GET") + api.HandleFunc("/support/list", supportHandler.GetSupportersList).Methods("GET") + // Movies routes - specific paths first, then parameterized api.HandleFunc("/movies/search", movieHandler.Search).Methods("GET") api.HandleFunc("/movies/popular", movieHandler.Popular).Methods("GET") diff --git a/main.go b/main.go index 695ba14..d0f0e89 100644 --- a/main.go +++ b/main.go @@ -68,6 +68,7 @@ func main() { torrentsHandler := appHandlers.NewTorrentsHandler(torrentService, tmdbService) reactionsHandler := appHandlers.NewReactionsHandler(reactionsService) imagesHandler := appHandlers.NewImagesHandler() + supportHandler := appHandlers.NewSupportHandler() r := mux.NewRouter() @@ -112,6 +113,8 @@ func main() { api.HandleFunc("/images/{type}/{id}", imagesHandler.GetImage).Methods("GET") + api.HandleFunc("/support/list", supportHandler.GetSupportersList).Methods("GET") + // Movies routes - specific paths first, then parameterized api.HandleFunc("/movies/search", movieHandler.Search).Methods("GET") api.HandleFunc("/movies/popular", movieHandler.Popular).Methods("GET") diff --git a/pkg/handlers/support.go b/pkg/handlers/support.go new file mode 100644 index 0000000..d05687e --- /dev/null +++ b/pkg/handlers/support.go @@ -0,0 +1,59 @@ +package handlers + +import ( + "encoding/json" + "net/http" + "os" + "path/filepath" +) + +type Supporter struct { + ID int `json:"id"` + Name string `json:"name"` + Type string `json:"type"` + Amount *float64 `json:"amount,omitempty"` + Currency string `json:"currency,omitempty"` + Description string `json:"description"` + Contributions []string `json:"contributions"` + Year int `json:"year"` + IsActive bool `json:"isActive"` +} + +type SupportHandler struct{} + +func NewSupportHandler() *SupportHandler { + return &SupportHandler{} +} + +func (h *SupportHandler) GetSupportersList(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + + // Get the path to supporters-list.json + // It should be in the root of the project + supportersPath := filepath.Join(".", "supporters-list.json") + + // Try to read the file + data, err := os.ReadFile(supportersPath) + if err != nil { + // If file not found, return empty list + if os.IsNotExist(err) { + w.WriteHeader(http.StatusOK) + json.NewEncoder(w).Encode([]Supporter{}) + return + } + // Other errors + w.WriteHeader(http.StatusInternalServerError) + json.NewEncoder(w).Encode(map[string]string{"error": "Failed to read supporters list"}) + return + } + + var supporters []Supporter + if err := json.Unmarshal(data, &supporters); err != nil { + w.WriteHeader(http.StatusInternalServerError) + json.NewEncoder(w).Encode(map[string]string{"error": "Failed to parse supporters list"}) + return + } + + w.WriteHeader(http.StatusOK) + json.NewEncoder(w).Encode(supporters) +} diff --git a/supporters-list.json b/supporters-list.json new file mode 100644 index 0000000..a97bd4c --- /dev/null +++ b/supporters-list.json @@ -0,0 +1,35 @@ +[ + { + "id": 1, + "name": "Sophron Ragozin", + "type": "service", + "description": "Покупка и продления основного домена neomovies.ru", + "contributions": [ + "Домен neomovies.ru" + ], + "year": 2025, + "isActive": true + }, + { + "id": 2, + "name": "Chernuha", + "type": "service", + "description": "Покупка домена neomovies.run", + "contributions": [ + "Домен neomovies.run" + ], + "year": 2025, + "isActive": true + }, + { + "id": 3, + "name": "Iwnuply", + "type": "code", + "description": "Создание докер контейнера для API и Frontend", + "contributions": [ + "Docker" + ], + "year": 2025, + "isActive": true + } +]