feat(t242): delete unused freight orders
This commit is contained in:
@@ -69,6 +69,12 @@ type CreateFreightDateSyncCommand struct {
|
||||
SyncToNow bool
|
||||
}
|
||||
|
||||
type DeleteFreightOrderCommand struct {
|
||||
CreatorSubject string
|
||||
ActorUserID string
|
||||
OrderID string
|
||||
}
|
||||
|
||||
type CreateFreightSyncResult struct {
|
||||
Run domain.FreightSyncRun
|
||||
Replayed bool
|
||||
@@ -701,6 +707,44 @@ func (service *FreightService) GetOrder(
|
||||
return detail, nil
|
||||
}
|
||||
|
||||
func (service *FreightService) DeleteOrder(
|
||||
ctx context.Context,
|
||||
command DeleteFreightOrderCommand,
|
||||
) error {
|
||||
command.CreatorSubject = strings.TrimSpace(command.CreatorSubject)
|
||||
command.ActorUserID = strings.TrimSpace(command.ActorUserID)
|
||||
command.OrderID = strings.TrimSpace(command.OrderID)
|
||||
fields := map[string]string{}
|
||||
if command.CreatorSubject == "" {
|
||||
fields["creator_subject"] = "is required"
|
||||
}
|
||||
if !isUUID(command.ActorUserID) {
|
||||
fields["actor_user_id"] = "must be a UUID"
|
||||
}
|
||||
if !isUUID(command.OrderID) {
|
||||
fields["order_id"] = "must be a UUID"
|
||||
}
|
||||
if len(fields) > 0 {
|
||||
return invalidError(
|
||||
"FREIGHT_DELETE_INVALID",
|
||||
"freight order deletion is invalid",
|
||||
fields,
|
||||
)
|
||||
}
|
||||
storageKeys, err := service.repository.DeleteFreightOrder(
|
||||
ctx,
|
||||
command.CreatorSubject,
|
||||
command.OrderID,
|
||||
)
|
||||
if err != nil {
|
||||
return wrapRepositoryError(err)
|
||||
}
|
||||
if service.imageCache != nil {
|
||||
service.imageCache.DeleteStoredImages(storageKeys)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (service *FreightService) normalize(
|
||||
source domain.FreightSourceBatch,
|
||||
) (domain.FreightImportBatch, error) {
|
||||
|
||||
Reference in New Issue
Block a user