1
0

feat(views): recalculate all positions when updating

This commit is contained in:
kolaente
2024-03-15 13:45:30 +01:00
parent 8ce476491e
commit ca4e3e01c5
5 changed files with 42 additions and 47 deletions

View File

@ -210,7 +210,7 @@ func (p *ProjectView) ReadAll(s *xorm.Session, a web.Auth, _ string, _ int, _ in
// @Failure 500 {object} models.Message "Internal error"
// @Router /projects/{project}/views/{id} [get]
func (p *ProjectView) ReadOne(s *xorm.Session, _ web.Auth) (err error) {
view, err := GetProjectViewByID(s, p.ID, p.ProjectID)
view, err := GetProjectViewByIDAndProject(s, p.ID, p.ProjectID)
if err != nil {
return err
}
@ -273,7 +273,7 @@ func (p *ProjectView) Create(s *xorm.Session, a web.Auth) (err error) {
// @Router /projects/{project}/views/{id} [post]
func (p *ProjectView) Update(s *xorm.Session, _ web.Auth) (err error) {
// Check if the project view exists
_, err = GetProjectViewByID(s, p.ID, p.ProjectID)
_, err = GetProjectViewByIDAndProject(s, p.ID, p.ProjectID)
if err != nil {
return
}
@ -286,7 +286,7 @@ func (p *ProjectView) Update(s *xorm.Session, _ web.Auth) (err error) {
return
}
func GetProjectViewByID(s *xorm.Session, id, projectID int64) (view *ProjectView, err error) {
func GetProjectViewByIDAndProject(s *xorm.Session, id, projectID int64) (view *ProjectView, err error) {
exists, err := s.
Where("id = ? AND project_id = ?", id, projectID).
NoAutoCondition().
@ -304,6 +304,24 @@ func GetProjectViewByID(s *xorm.Session, id, projectID int64) (view *ProjectView
return
}
func GetProjectViewByID(s *xorm.Session, id int64) (view *ProjectView, err error) {
exists, err := s.
Where("id = ?", id).
NoAutoCondition().
Get(view)
if err != nil {
return nil, err
}
if !exists {
return nil, &ErrProjectViewDoesNotExist{
ProjectViewID: id,
}
}
return
}
func CreateDefaultViewsForProject(s *xorm.Session, project *Project, a web.Auth, createBacklogBucket bool) (err error) {
list := &ProjectView{
ProjectID: project.ID,