"""Logic for track crop info.""" from oto import response from product_film.constants import error from product_film.models import track_crop_info def get_track_crop_info(track_id=None): """Get Track Crop Info. Args: track_id (int): track id. Returns: Response: on successful, 200 status with JSON body """ result = track_crop_info.get_track_crop_info(track_id) if not result: return result result.message['created_timestamp'] = \ result.message['created_timestamp'].strftime('%Y-%m-%d') result.message['updated_timestamp'] = \ result.message['updated_timestamp'].strftime('%Y-%m-%d') return result def add_track_crop_info(crop_info, track_id): """Add/Edit Track Crop Info. Args: crop_info (dict): track crop info. track_id (int): track id. Returns: Response: on successful, 200 status with JSON body """ if not crop_info: return response.create_error_response( code=error.BAD_REQUEST_CODE, message='Bad Request') result = track_crop_info.add_track_crop_info( track_id, crop_info.get('left', 0), crop_info.get('right', 0), crop_info.get('top', 0), crop_info.get('bottom', 0), crop_info.get('orchard_user_id')) if not result: return result result.message['created_timestamp'] = \ result.message['created_timestamp'].strftime('%Y-%m-%d') result.message['updated_timestamp'] = \ result.message['updated_timestamp'].strftime('%Y-%m-%d') return result