Skip to content

Commit

Permalink
fix server routes, add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mSulimenko committed Dec 19, 2024
1 parent c418ac5 commit c19f8cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions server/handlers/server_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,33 @@ func GetServerByID(w http.ResponseWriter, r *http.Request) {
}

// GET /servers/{id}
//{
// "hostname": "server-01",
// "address": "192.168.1.1",
// "description": "Main server for processing tasks",
// "status": "active",
// "cpu_info": "Intel Xeon E5-2670",
// "gpu_info": "NVIDIA Tesla V100",
// "ram_size_gb": 128
//}

func CreateServer(w http.ResponseWriter, r *http.Request) {
var newServer models.Server
if err := render.DecodeJSON(r.Body, &newServer); err != nil {
http.Error(w, "Invalid input", http.StatusBadRequest)
return
}

if newServer.Hostname == "" || newServer.Address == "" { //Уточнить, какие поля обязательные
if newServer.Hostname == "" || newServer.Address == "" {
http.Error(w, "Hostname and Address are required", http.StatusBadRequest)
return
}

newServer.CurrentJobs = []primitive.ObjectID{}
newServer.CompletedJobs = []primitive.ObjectID{}

newServer.CreatedAt = time.Now()
newServer.UpdatedAt = time.Now()

newServer.ID = primitive.NewObjectID()
serversCollection := db.GetCollection("servers")

Expand Down
2 changes: 1 addition & 1 deletion server/routes/server_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
func ServerRoutes(r chi.Router) {
r.Get("/servers", handlers.GetServers)
r.Get("/servers/{id}", handlers.GetServerByID)
r.Post("/servers", handlers.CreateServer)
r.Post("/servers", handlers.CreateServer) // Этот роут юзай для создания сервера
r.Put("/servers/{id}", handlers.UpdateServer)
r.Patch("/servers/{id}", handlers.PatchServer)
r.Delete("/servers/{id}", handlers.DeleteServer)
Expand Down

0 comments on commit c19f8cc

Please sign in to comment.