diff --git a/config/swagger.yaml b/config/swagger.yaml index e343fbf..614b6e8 100644 --- a/config/swagger.yaml +++ b/config/swagger.yaml @@ -246,7 +246,7 @@ components: properties: id: type: integer - name: + title: type: string description: type: string \ No newline at end of file diff --git a/internal/app/handlers.go b/internal/app/handlers.go index 0cd6ffb..a8e2319 100644 --- a/internal/app/handlers.go +++ b/internal/app/handlers.go @@ -3,6 +3,7 @@ package app import ( "encoding/json" "errors" + "io" "net/http" "strconv" "task_manager/internal/domain/project" @@ -147,9 +148,31 @@ func (rm *TaskManager) handleAssignUserToProject(w http.ResponseWriter, r *http. } func (rm *TaskManager) handleCreateProject(w http.ResponseWriter, r *http.Request) { - respondWithJSON(w, http.StatusNotImplemented, map[string]string{ - "message": "Create project not implemented yet", + + var newProject project.Project + + body, err := io.ReadAll(r.Body) + if err != nil { + respondWithError(w, http.StatusBadRequest, "Faild read body", err) + return + } + + err = json.Unmarshal(body, &newProject) + if err != nil { + respondWithError(w, http.StatusBadRequest, "Faild unmurshal body", err) + return + } + + err = rm.repo.AddProject(&newProject) + if err != nil { + respondWithError(w, http.StatusBadRequest, "Faild add project", err) + return + } + + respondWithJSON(w, http.StatusOK, map[string]string{ + "message": "Project assigned to project successfully", }) + } func (rm *TaskManager) handleCreateTask(w http.ResponseWriter, r *http.Request) { var task tasks.Task