feat(views): recalculate all positions when updating
This commit is contained in:
@ -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,
|
||||
|
Reference in New Issue
Block a user