add supporters list

This commit is contained in:
2025-11-25 17:35:18 +02:00
parent 48c09e4fb6
commit b323e6940d
4 changed files with 100 additions and 0 deletions

View File

@@ -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")

View File

@@ -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")

59
pkg/handlers/support.go Normal file
View File

@@ -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)
}

35
supporters-list.json Normal file
View File

@@ -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
}
]