(c *gin.Context)
| 208 | ) |
| 209 | |
| 210 | func (s *BatchUserService) Delete(c *gin.Context) error { |
| 211 | dep := dependency.FromContext(c) |
| 212 | userClient := dep.UserClient() |
| 213 | fileClient := dep.FileClient() |
| 214 | |
| 215 | current := inventory.UserFromContext(c) |
| 216 | ae := serializer.NewAggregateError() |
| 217 | for _, id := range s.IDs { |
| 218 | if current.ID == id || id == 1 { |
| 219 | ae.Add(strconv.Itoa(id), serializer.NewError(serializer.CodeInvalidActionOnDefaultUser, "Cannot delete current user", nil)) |
| 220 | continue |
| 221 | } |
| 222 | |
| 223 | fc, tx, ctx, err := inventory.WithTx(c, fileClient) |
| 224 | if err != nil { |
| 225 | ae.Add(strconv.Itoa(id), serializer.NewError(serializer.CodeDBError, "Failed to start transaction", err)) |
| 226 | continue |
| 227 | } |
| 228 | |
| 229 | uc, _, ctx, err := inventory.WithTx(ctx, userClient) |
| 230 | if err != nil { |
| 231 | ae.Add(strconv.Itoa(id), serializer.NewError(serializer.CodeDBError, "Failed to start transaction", err)) |
| 232 | continue |
| 233 | } |
| 234 | |
| 235 | if err := fc.DeleteByUser(ctx, id); err != nil { |
| 236 | _ = inventory.Rollback(tx) |
| 237 | ae.Add(strconv.Itoa(id), serializer.NewError(serializer.CodeDBError, "Failed to delete user files", err)) |
| 238 | continue |
| 239 | } |
| 240 | |
| 241 | if err := uc.Delete(ctx, id); err != nil { |
| 242 | _ = inventory.Rollback(tx) |
| 243 | ae.Add(strconv.Itoa(id), serializer.NewError(serializer.CodeDBError, "Failed to delete user", err)) |
| 244 | continue |
| 245 | } |
| 246 | |
| 247 | if err := inventory.Commit(tx); err != nil { |
| 248 | ae.Add(strconv.Itoa(id), serializer.NewError(serializer.CodeDBError, "Failed to commit transaction", err)) |
| 249 | continue |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | return ae.Aggregate() |
| 254 | } |
nothing calls this directly
no test coverage detected