@@ -24,9 +24,8 @@ type equipmentCategoriesData struct {
2424}
2525
2626type equipmentCategoryData struct {
27- OrgID string
28- Category * categories.EquipmentCategory
29- ID string
27+ OrgID string
28+ ID string
3029}
3130
3231func (app * application ) getEquipmentCategories (w http.ResponseWriter , r * http.Request ) * httperr.Error {
@@ -124,8 +123,8 @@ func (app *application) getEquipmentCategory(w http.ResponseWriter, r *http.Requ
124123 }
125124
126125 data := app .html .TemplateData (r )
127- data .Form = & categories.Form {}
128- data .Data = equipmentCategoryData {OrgID : orgID , Category : category , ID : catID }
126+ data .Form = & categories.Form {Name : category . Name }
127+ data .Data = equipmentCategoryData {OrgID : orgID , ID : catID }
129128 return app .html .Render (w , r , http .StatusOK , pages .EquipmentCategoriesDetail , data )
130129}
131130
@@ -139,18 +138,10 @@ func (app *application) postEquipmentCategory(w http.ResponseWriter, r *http.Req
139138 return & httperr.Error {Error : err , Message : "Bad request." , Code : http .StatusBadRequest }
140139 }
141140
142- category , err := app .services .equipmentcategories .GetByID (ctx , catID )
143- if err != nil {
144- if errors .Is (err , database .ErrNotFound ) {
145- return & httperr.Error {Error : err , Message : "Equipment category not found." , Code : http .StatusNotFound }
146- }
147- return & httperr.Error {Error : err , Message : "Failed to retrieve equipment category." , Code : http .StatusInternalServerError }
148- }
149-
150141 reRender := func (f * categories.Form ) * httperr.Error {
151142 data := app .html .TemplateData (r )
152143 data .Form = f
153- data .Data = equipmentCategoryData {OrgID : orgID , Category : category , ID : catID }
144+ data .Data = equipmentCategoryData {OrgID : orgID , ID : catID }
154145 return app .html .Render (w , r , http .StatusUnprocessableEntity , pages .EquipmentCategoriesDetail , data )
155146 }
156147
@@ -192,11 +183,11 @@ func (app *application) postDeleteEquipmentCategory(w http.ResponseWriter, r *ht
192183 }
193184 return & httperr.Error {Error : fetchErr , Message : "Failed to retrieve equipment category." , Code : http .StatusInternalServerError }
194185 }
195- f := & categories.Form {}
186+ f := & categories.Form {Name : category . Name }
196187 f .AddError ("delete" , "Cannot delete: this category is assigned to one or more equipment items." )
197188 data := app .html .TemplateData (r )
198189 data .Form = f
199- data .Data = equipmentCategoryData {OrgID : orgID , Category : category , ID : catID }
190+ data .Data = equipmentCategoryData {OrgID : orgID , ID : catID }
200191 return app .html .Render (w , r , http .StatusUnprocessableEntity , pages .EquipmentCategoriesDetail , data )
201192 }
202193 return & httperr.Error {
0 commit comments