mirror of
https://gitlab.com/foxixus/neomovies-api.git
synced 2025-12-15 20:16:10 +05:00
add supporters list
This commit is contained in:
@@ -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")
|
||||
|
||||
3
main.go
3
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")
|
||||
|
||||
59
pkg/handlers/support.go
Normal file
59
pkg/handlers/support.go
Normal 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
35
supporters-list.json
Normal 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
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user