This commit is contained in:
parent
def414917b
commit
99cec81d91
@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"task_manager/internal/domain/project"
|
||||
"task_manager/internal/domain/tasks"
|
||||
"task_manager/internal/domain/users"
|
||||
"task_manager/internal/persistance"
|
||||
@ -118,10 +119,8 @@ func (rm *TaskManager) handleUserProjects(w http.ResponseWriter, r *http.Request
|
||||
respondWithJSON(w, http.StatusOK, projects)
|
||||
}
|
||||
func (rm *TaskManager) handleAssignUserToProject(w http.ResponseWriter, r *http.Request) {
|
||||
var input struct {
|
||||
IdUser int `json:"id_user"`
|
||||
IdProject int `json:"id_project"`
|
||||
}
|
||||
|
||||
var input project.UserProjectLink
|
||||
|
||||
err := json.NewDecoder(r.Body).Decode(&input)
|
||||
if err != nil {
|
||||
@ -131,6 +130,11 @@ func (rm *TaskManager) handleAssignUserToProject(w http.ResponseWriter, r *http.
|
||||
|
||||
// Заглушка: реализация привязки пользователя к проекту
|
||||
// Для добавления необходимо доработать метод в репозитории
|
||||
err = rm.repo.AssignProject(&input)
|
||||
if err != nil {
|
||||
respondWithError(w, http.StatusBadRequest, "Faild to assign project", err)
|
||||
return
|
||||
}
|
||||
|
||||
respondWithJSON(w, http.StatusOK, map[string]string{
|
||||
"message": "User assigned to project successfully",
|
||||
|
@ -9,3 +9,9 @@ type Project struct {
|
||||
Date string `json:"date"`
|
||||
Sprints []sprint.Sprint
|
||||
}
|
||||
|
||||
type UserProjectLink struct {
|
||||
Id int `json:"id"`
|
||||
IdUser int `json:"id_user"`
|
||||
IdProject int `json:"id_project"`
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
func (tm *TaskManagerRepository) AddProject(newProject *project.Project) error {
|
||||
func (tm *TaskManagerRepository) AddProject(newProject *project.UserProjectLink) error {
|
||||
err := tm.db.QueryRow(`INSERT INTO task_manager.project(name,description)
|
||||
VALUES ($1,$2)
|
||||
RETURNING id
|
||||
@ -26,6 +26,16 @@ func (tm *TaskManagerRepository) DeleteProject(project *project.Project) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tm *TaskManagerRepository) GetProjects() ([]project.Project, error) {
|
||||
return nil, nil
|
||||
func (tm *TaskManagerRepository) AssignProject(link *project.UserProjectLink) error {
|
||||
|
||||
err := tm.db.QueryRow(`INSERT INTO task_manager.user_project(users,projects)
|
||||
VALUES ($1,$2)
|
||||
RETURNING id
|
||||
`, link.IdUser, link.IdProject).Scan(&link.Id)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user