You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I already succeeded to import trips from a file using the rails runner (see script below). An API call would be a much better solution.
Proposal for the api call (copied from the create area call). The call should return the ID of the new trip:
"/api/v1/trips":
post:
summary: Creates a triptags:
- Tripsparameters:
- name: api_keyin: queryrequired: truedescription: API Keyschema:
type: stringresponses:
'201':
description: trip createdcontent:
application/json:
schema:
type: numberproperties:
id:
type: integerexample: 14description: The ID of trip created'422':
description: invalid requestrequestBody:
content:
application/json:
schema:
type: objectproperties:
name:
type: stringexample: One week in Londondescription: The name of the tripdescription:
type: stringexample: Visited my friend in Englanddescription: The name of the tripstart_at:
type: date-timeexample: '2023-01-01'description: The start time of the tripend_at:
type: date-timeexample: '2023-01-07'description: The start time of the triprequired:
- name
- start_at
- end_atexamples:
'0':
summary: Creates a tripvalue:
name: One week in Londonstart_at: '2023-01-01'end_at: '2023-01-07'
Example script to create trips from a csv file:
# Zähler für erfolgreiche und fehlgeschlagene Importesuccess_count=0failure_count=0# CSV-Datei lesenCSV.foreach(csv_file_path,headers: true,encoding: 'UTF-8')do |row|
name=row['title']started_at=row['start_date']ended_at=row['end_date']# Konvertiere Datum in das richtige Formatbeginstarted_at=Time.zone.parse(started_at)ended_at=Time.zone.parse(ended_at)rescueArgumentError=>eputs"Fehler beim Parsen der Daten für Trip '#{name}': #{e.message}"failure_count += 1nextend# Erstelle und speichere den Triptrip=Trip.new(name: name,started_at: started_at,ended_at: ended_at,user_id: user_id)iftrip.savesuccess_count += 1puts"Trip '#{name}' erfolgreich gespeichert."elsefailure_count += 1puts"Fehler beim Speichern des Trips '#{name}': #{trip.errors.full_messages.join(', ')}"endendputs"Import abgeschlossen: #{success_count} erfolgreich, #{failure_count} fehlgeschlagen."
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I already succeeded to import trips from a file using the rails runner (see script below). An API call would be a much better solution.
Proposal for the api call (copied from the create area call). The call should return the ID of the new trip:
Example script to create trips from a csv file:
Beta Was this translation helpful? Give feedback.
All reactions