| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- // Automatic FlutterFlow imports
- import '/backend/schema/structs/index.dart';
- import '/flutter_flow/flutter_flow_theme.dart';
- import '/flutter_flow/flutter_flow_util.dart';
- import 'index.dart'; // Imports other custom actions
- import '/flutter_flow/custom_functions.dart'; // Imports custom functions
- import 'package:flutter/material.dart';
- // Begin custom action code
- // DO NOT REMOVE OR MODIFY THE CODE ABOVE!
- import 'dart:async';
- import 'dart:convert';
- import 'package:http/http.dart' as http;
- Future<dynamic> stadsactiviteitCreate(
- String sessionName,
- String sessionId,
- String token,
- String titel,
- String plaatsTid,
- String datumStart,
- String? datumEind,
- String? omschrijving,
- String? organisator,
- String? contact,
- String? adresStraat,
- String? adresPlaats,
- String? adresPostcode,
- String? entreePrijs,
- String? toelichtingEntree,
- List<String>? categorieTids,
- String? websiteUrl,
- String? logoFid,
- List<String>? fotosFids,
- String? entreeTid,
- ) async {
- if (titel.trim().isEmpty) {
- return {'success': false, 'error': 'Titel is verplicht'};
- }
- final plaatsTidInt = int.tryParse(plaatsTid.trim());
- if (plaatsTidInt == null) {
- return {'success': false, 'error': 'Ongeldige plaats'};
- }
- if (datumStart.trim().isEmpty) {
- return {'success': false, 'error': 'Datum is verplicht'};
- }
- final body = <String, dynamic>{
- 'titel': titel.trim(),
- 'plaats_tid': plaatsTidInt,
- 'datum_start': datumStart.trim(),
- };
- if ((datumEind ?? '').trim().isNotEmpty) {
- body['datum_eind'] = datumEind!.trim();
- }
- if ((omschrijving ?? '').trim().isNotEmpty) {
- body['omschrijving'] = omschrijving!.trim();
- }
- if ((organisator ?? '').trim().isNotEmpty) {
- body['organisator'] = organisator!.trim();
- }
- if ((contact ?? '').trim().isNotEmpty) {
- body['contact'] = contact!.trim();
- }
- if ((adresStraat ?? '').trim().isNotEmpty ||
- (adresPlaats ?? '').trim().isNotEmpty ||
- (adresPostcode ?? '').trim().isNotEmpty) {
- body['adres'] = {
- if ((adresStraat ?? '').trim().isNotEmpty)
- 'thoroughfare': adresStraat!.trim(),
- if ((adresPlaats ?? '').trim().isNotEmpty)
- 'locality': adresPlaats!.trim(),
- if ((adresPostcode ?? '').trim().isNotEmpty)
- 'postal_code': adresPostcode!.trim(),
- 'country': 'NL',
- };
- }
- if ((entreePrijs ?? '').trim().isNotEmpty) {
- body['entree_prijs'] = entreePrijs!.trim();
- }
- if ((toelichtingEntree ?? '').trim().isNotEmpty) {
- body['toelichting_entree'] = toelichtingEntree!.trim();
- }
- if (categorieTids != null && categorieTids.isNotEmpty) {
- final tids = categorieTids
- .map((e) => int.tryParse(e.trim()))
- .whereType<int>()
- .toList();
- if (tids.isNotEmpty) body['categorie_tids'] = tids;
- }
- if ((websiteUrl ?? '').trim().isNotEmpty) {
- body['website_url'] = websiteUrl!.trim();
- }
- if ((logoFid ?? '').trim().isNotEmpty) {
- final fid = int.tryParse(logoFid!.trim());
- if (fid != null) body['logo_fid'] = fid;
- }
- if (fotosFids != null && fotosFids.isNotEmpty) {
- final fids =
- fotosFids.map((e) => int.tryParse(e.trim())).whereType<int>().toList();
- if (fids.isNotEmpty) body['fotos_fids'] = fids;
- }
- if ((entreeTid ?? '').trim().isNotEmpty) {
- final tid = int.tryParse(entreeTid!.trim());
- if (tid != null) body['entree_tid'] = tid;
- }
- final headers = <String, String>{
- 'Accept': 'application/json',
- 'Content-Type': 'application/json',
- };
- if (sessionName.trim().isNotEmpty && sessionId.trim().isNotEmpty) {
- headers['Cookie'] = '$sessionName=$sessionId';
- }
- if (token.trim().isNotEmpty) {
- headers['X-CSRF-Token'] = token;
- }
- final base = FFAppState().apiBaseUrl.trim().isEmpty
- ? 'https://uitgaanskrant.com'
- : FFAppState().apiBaseUrl.trim();
- final url = '$base/en/flutterdrup/stadsactiviteiten/create.json';
- print('========================================');
- print('STADSACTIVITEIT CREATE');
- print('URL : $url');
- print('BODY : ${jsonEncode(body)}');
- print('========================================');
- try {
- final response = await http
- .post(Uri.parse(url), headers: headers, body: jsonEncode(body))
- .timeout(const Duration(seconds: 30));
- print('========================================');
- print('STATUS : ${response.statusCode}');
- print('BODY');
- print(response.body);
- print('========================================');
- dynamic data;
- try {
- data = jsonDecode(response.body);
- } catch (_) {
- data = response.body;
- }
- if (response.statusCode >= 200 && response.statusCode < 300) {
- return {
- 'success': true,
- 'nid': data is Map ? (data['nid']?.toString() ?? '') : '',
- 'status': data is Map ? (data['status']?.toString() ?? '') : '',
- };
- }
- return {
- 'success': false,
- 'statusCode': response.statusCode,
- 'error':
- data is Map ? (data['message'] ?? data.toString()) : data.toString(),
- };
- } on TimeoutException {
- return {'success': false, 'error': 'Timeout'};
- } catch (e, stack) {
- print(e);
- print(stack);
- return {'success': false, 'error': e.toString()};
- }
- }
|