From 07870891dadc211308de927f04f9fbe8cbd8762d Mon Sep 17 00:00:00 2001 From: tk Date: Sat, 16 Aug 2025 16:13:11 +0200 Subject: [PATCH] rm serverpod templates --- .gitignore | 1 + .../lib/src/protocol/client.dart | 59 +++------- .../lib/src/protocol/greeting.dart | 95 ---------------- .../lib/src/protocol/protocol.dart | 56 ++++------ wien_talks/wien_talks_flutter/lib/main.dart | 69 ------------ .../wien_talks_flutter/lib/news_screen.dart | 15 --- .../Flutter/GeneratedPluginRegistrant.swift | 2 + wien_talks/wien_talks_flutter/pubspec.yaml | 1 + wien_talks/wien_talks_server/lib/server.dart | 24 +--- .../lib/src/birthday_reminder.dart | 18 --- .../lib/src/generated/endpoints.dart | 59 +++------- .../lib/src/generated/greeting.dart | 105 ------------------ .../lib/src/generated/protocol.dart | 52 ++++----- .../lib/src/generated/protocol.yaml | 2 - .../lib/src/greeting.spy.yaml | 24 ---- .../lib/src/greeting_endpoint.dart | 34 ------ .../lib/src/quotes/quotes_endpoint.dart | 13 +-- .../integration/greeting_endpoint_test.dart | 24 ---- .../test_tools/serverpod_test_tools.dart | 71 ++---------- 19 files changed, 92 insertions(+), 632 deletions(-) delete mode 100644 wien_talks/wien_talks_client/lib/src/protocol/greeting.dart delete mode 100644 wien_talks/wien_talks_server/lib/src/birthday_reminder.dart delete mode 100644 wien_talks/wien_talks_server/lib/src/generated/greeting.dart delete mode 100644 wien_talks/wien_talks_server/lib/src/greeting.spy.yaml delete mode 100644 wien_talks/wien_talks_server/lib/src/greeting_endpoint.dart delete mode 100644 wien_talks/wien_talks_server/test/integration/greeting_endpoint_test.dart diff --git a/.gitignore b/.gitignore index fc57b2b..2b377da 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ wien_talks/wien_talks_flutter/pubspec.lock +wien_talks/wien_talks_flutter/android/app/google-services.json diff --git a/wien_talks/wien_talks_client/lib/src/protocol/client.dart b/wien_talks/wien_talks_client/lib/src/protocol/client.dart index 0d92249..3d49693 100644 --- a/wien_talks/wien_talks_client/lib/src/protocol/client.dart +++ b/wien_talks/wien_talks_client/lib/src/protocol/client.dart @@ -11,29 +11,10 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:serverpod_client/serverpod_client.dart' as _i1; import 'dart:async' as _i2; -import 'package:wien_talks_client/src/protocol/greeting.dart' as _i3; -import 'package:wien_talks_client/src/protocol/quotes/quote.dart' as _i4; -import 'package:wien_talks_client/src/protocol/quotes/create_quote.dart' as _i5; -import 'package:serverpod_auth_client/serverpod_auth_client.dart' as _i6; -import 'protocol.dart' as _i7; - -/// This is an example endpoint that returns a greeting message through -/// its [hello] method. -/// {@category Endpoint} -class EndpointGreeting extends _i1.EndpointRef { - EndpointGreeting(_i1.EndpointCaller caller) : super(caller); - - @override - String get name => 'greeting'; - - /// Returns a personalized greeting message: "Hello {name}". - _i2.Future<_i3.Greeting> hello(String name) => - caller.callServerEndpoint<_i3.Greeting>( - 'greeting', - 'hello', - {'name': name}, - ); -} +import 'package:wien_talks_client/src/protocol/quotes/quote.dart' as _i3; +import 'package:wien_talks_client/src/protocol/quotes/create_quote.dart' as _i4; +import 'package:serverpod_auth_client/serverpod_auth_client.dart' as _i5; +import 'protocol.dart' as _i6; /// {@category Endpoint} class EndpointQuote extends _i1.EndpointRef { @@ -42,37 +23,37 @@ class EndpointQuote extends _i1.EndpointRef { @override String get name => 'quote'; - _i2.Future updateQuote(_i4.Quote quote) => + _i2.Future updateQuote(_i3.Quote quote) => caller.callServerEndpoint( 'quote', 'updateQuote', {'quote': quote}, ); - _i2.Stream<_i4.Quote> quoteUpdates() => - caller.callStreamingServerEndpoint<_i2.Stream<_i4.Quote>, _i4.Quote>( + _i2.Stream<_i3.Quote> quoteUpdates() => + caller.callStreamingServerEndpoint<_i2.Stream<_i3.Quote>, _i3.Quote>( 'quote', 'quoteUpdates', {}, {}, ); - _i2.Future<_i4.Quote> createQuote(_i5.CreateQuoteRequest req) => - caller.callServerEndpoint<_i4.Quote>( + _i2.Future<_i3.Quote> createQuote(_i4.CreateQuoteRequest req) => + caller.callServerEndpoint<_i3.Quote>( 'quote', 'createQuote', {'req': req}, ); - _i2.Future<_i4.Quote> getQuoteById(int id) => - caller.callServerEndpoint<_i4.Quote>( + _i2.Future<_i3.Quote> getQuoteById(int id) => + caller.callServerEndpoint<_i3.Quote>( 'quote', 'getQuoteById', {'id': id}, ); - _i2.Future> getAllQuotes() => - caller.callServerEndpoint>( + _i2.Future> getAllQuotes() => + caller.callServerEndpoint>( 'quote', 'getAllQuotes', {}, @@ -81,10 +62,10 @@ class EndpointQuote extends _i1.EndpointRef { class Modules { Modules(Client client) { - auth = _i6.Caller(client); + auth = _i5.Caller(client); } - late final _i6.Caller auth; + late final _i5.Caller auth; } class Client extends _i1.ServerpodClientShared { @@ -103,7 +84,7 @@ class Client extends _i1.ServerpodClientShared { bool? disconnectStreamsOnLostInternetConnection, }) : super( host, - _i7.Protocol(), + _i6.Protocol(), securityContext: securityContext, authenticationKeyManager: authenticationKeyManager, streamingConnectionTimeout: streamingConnectionTimeout, @@ -113,22 +94,16 @@ class Client extends _i1.ServerpodClientShared { disconnectStreamsOnLostInternetConnection: disconnectStreamsOnLostInternetConnection, ) { - greeting = EndpointGreeting(this); quote = EndpointQuote(this); modules = Modules(this); } - late final EndpointGreeting greeting; - late final EndpointQuote quote; late final Modules modules; @override - Map get endpointRefLookup => { - 'greeting': greeting, - 'quote': quote, - }; + Map get endpointRefLookup => {'quote': quote}; @override Map get moduleLookup => diff --git a/wien_talks/wien_talks_client/lib/src/protocol/greeting.dart b/wien_talks/wien_talks_client/lib/src/protocol/greeting.dart deleted file mode 100644 index bb85a81..0000000 --- a/wien_talks/wien_talks_client/lib/src/protocol/greeting.dart +++ /dev/null @@ -1,95 +0,0 @@ -/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */ -/* To generate run: "serverpod generate" */ - -// ignore_for_file: implementation_imports -// ignore_for_file: library_private_types_in_public_api -// ignore_for_file: non_constant_identifier_names -// ignore_for_file: public_member_api_docs -// ignore_for_file: type_literal_in_constant_pattern -// ignore_for_file: use_super_parameters - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'package:serverpod_client/serverpod_client.dart' as _i1; - -/// A greeting message which can be sent to or from the server. -abstract class Greeting implements _i1.SerializableModel { - Greeting._({ - required this.message, - required this.author, - required this.timestamp, - }); - - factory Greeting({ - required String message, - required String author, - required DateTime timestamp, - }) = _GreetingImpl; - - factory Greeting.fromJson(Map jsonSerialization) { - return Greeting( - message: jsonSerialization['message'] as String, - author: jsonSerialization['author'] as String, - timestamp: - _i1.DateTimeJsonExtension.fromJson(jsonSerialization['timestamp']), - ); - } - - /// The greeting message. - String message; - - /// The author of the greeting message. - String author; - - /// The time when the message was created. - DateTime timestamp; - - /// Returns a shallow copy of this [Greeting] - /// with some or all fields replaced by the given arguments. - @_i1.useResult - Greeting copyWith({ - String? message, - String? author, - DateTime? timestamp, - }); - @override - Map toJson() { - return { - 'message': message, - 'author': author, - 'timestamp': timestamp.toJson(), - }; - } - - @override - String toString() { - return _i1.SerializationManager.encode(this); - } -} - -class _GreetingImpl extends Greeting { - _GreetingImpl({ - required String message, - required String author, - required DateTime timestamp, - }) : super._( - message: message, - author: author, - timestamp: timestamp, - ); - - /// Returns a shallow copy of this [Greeting] - /// with some or all fields replaced by the given arguments. - @_i1.useResult - @override - Greeting copyWith({ - String? message, - String? author, - DateTime? timestamp, - }) { - return Greeting( - message: message ?? this.message, - author: author ?? this.author, - timestamp: timestamp ?? this.timestamp, - ); - } -} diff --git a/wien_talks/wien_talks_client/lib/src/protocol/protocol.dart b/wien_talks/wien_talks_client/lib/src/protocol/protocol.dart index f03d13d..9af404c 100644 --- a/wien_talks/wien_talks_client/lib/src/protocol/protocol.dart +++ b/wien_talks/wien_talks_client/lib/src/protocol/protocol.dart @@ -10,12 +10,10 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:serverpod_client/serverpod_client.dart' as _i1; -import 'greeting.dart' as _i2; -import 'quotes/create_quote.dart' as _i3; -import 'quotes/quote.dart' as _i4; -import 'package:wien_talks_client/src/protocol/quotes/quote.dart' as _i5; -import 'package:serverpod_auth_client/serverpod_auth_client.dart' as _i6; -export 'greeting.dart'; +import 'quotes/create_quote.dart' as _i2; +import 'quotes/quote.dart' as _i3; +import 'package:wien_talks_client/src/protocol/quotes/quote.dart' as _i4; +import 'package:serverpod_auth_client/serverpod_auth_client.dart' as _i5; export 'quotes/create_quote.dart'; export 'quotes/quote.dart'; export 'client.dart'; @@ -33,23 +31,17 @@ class Protocol extends _i1.SerializationManager { Type? t, ]) { t ??= T; - if (t == _i2.Greeting) { - return _i2.Greeting.fromJson(data) as T; + if (t == _i2.CreateQuoteRequest) { + return _i2.CreateQuoteRequest.fromJson(data) as T; } - if (t == _i3.CreateQuoteRequest) { - return _i3.CreateQuoteRequest.fromJson(data) as T; + if (t == _i3.Quote) { + return _i3.Quote.fromJson(data) as T; } - if (t == _i4.Quote) { - return _i4.Quote.fromJson(data) as T; + if (t == _i1.getType<_i2.CreateQuoteRequest?>()) { + return (data != null ? _i2.CreateQuoteRequest.fromJson(data) : null) as T; } - if (t == _i1.getType<_i2.Greeting?>()) { - return (data != null ? _i2.Greeting.fromJson(data) : null) as T; - } - if (t == _i1.getType<_i3.CreateQuoteRequest?>()) { - return (data != null ? _i3.CreateQuoteRequest.fromJson(data) : null) as T; - } - if (t == _i1.getType<_i4.Quote?>()) { - return (data != null ? _i4.Quote.fromJson(data) : null) as T; + if (t == _i1.getType<_i3.Quote?>()) { + return (data != null ? _i3.Quote.fromJson(data) : null) as T; } if (t == _i1.getType?>()) { return (data != null @@ -61,11 +53,11 @@ class Protocol extends _i1.SerializationManager { ? (data as List).map((e) => deserialize(e)).toList() : null) as T; } - if (t == List<_i5.Quote>) { - return (data as List).map((e) => deserialize<_i5.Quote>(e)).toList() as T; + if (t == List<_i4.Quote>) { + return (data as List).map((e) => deserialize<_i4.Quote>(e)).toList() as T; } try { - return _i6.Protocol().deserialize(data, t); + return _i5.Protocol().deserialize(data, t); } on _i1.DeserializationTypeNotFoundException catch (_) {} return super.deserialize(data, t); } @@ -74,16 +66,13 @@ class Protocol extends _i1.SerializationManager { String? getClassNameForObject(Object? data) { String? className = super.getClassNameForObject(data); if (className != null) return className; - if (data is _i2.Greeting) { - return 'Greeting'; - } - if (data is _i3.CreateQuoteRequest) { + if (data is _i2.CreateQuoteRequest) { return 'CreateQuoteRequest'; } - if (data is _i4.Quote) { + if (data is _i3.Quote) { return 'Quote'; } - className = _i6.Protocol().getClassNameForObject(data); + className = _i5.Protocol().getClassNameForObject(data); if (className != null) { return 'serverpod_auth.$className'; } @@ -96,18 +85,15 @@ class Protocol extends _i1.SerializationManager { if (dataClassName is! String) { return super.deserializeByClassName(data); } - if (dataClassName == 'Greeting') { - return deserialize<_i2.Greeting>(data['data']); - } if (dataClassName == 'CreateQuoteRequest') { - return deserialize<_i3.CreateQuoteRequest>(data['data']); + return deserialize<_i2.CreateQuoteRequest>(data['data']); } if (dataClassName == 'Quote') { - return deserialize<_i4.Quote>(data['data']); + return deserialize<_i3.Quote>(data['data']); } if (dataClassName.startsWith('serverpod_auth.')) { data['className'] = dataClassName.substring(15); - return _i6.Protocol().deserializeByClassName(data); + return _i5.Protocol().deserializeByClassName(data); } return super.deserializeByClassName(data); } diff --git a/wien_talks/wien_talks_flutter/lib/main.dart b/wien_talks/wien_talks_flutter/lib/main.dart index e898d02..f5a22f0 100644 --- a/wien_talks/wien_talks_flutter/lib/main.dart +++ b/wien_talks/wien_talks_flutter/lib/main.dart @@ -47,75 +47,6 @@ class MyApp extends StatelessWidget { } } -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - - final String title; - - @override - MyHomePageState createState() => MyHomePageState(); -} - -class MyHomePageState extends State { - /// Holds the last result or null if no result exists yet. - String? _resultMessage; - - /// Holds the last error message that we've received from the server or null - /// if no error exists yet. - String? _errorMessage; - - final _textEditingController = TextEditingController(); - - /// Calls the `hello` method of the `greeting` endpoint. Will set either the - /// `_resultMessage` or `_errorMessage` field, depending on if the call - /// is successful. - void _callHello() async { - try { - final result = await client.greeting.hello(_textEditingController.text); - setState(() { - _errorMessage = null; - _resultMessage = result.message; - }); - } catch (e) { - setState(() { - _errorMessage = '$e'; - }); - } - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar(title: Text(widget.title)), - body: Padding( - padding: const EdgeInsets.all(16), - child: Column( - children: [ - Padding( - padding: const EdgeInsets.only(bottom: 16.0), - child: TextField( - controller: _textEditingController, - decoration: const InputDecoration(hintText: 'Enter your name'), - ), - ), - Padding( - padding: const EdgeInsets.only(bottom: 16.0), - child: ElevatedButton( - onPressed: _callHello, - child: const Text('Send to Server'), - ), - ), - ResultDisplay( - resultMessage: _resultMessage, - errorMessage: _errorMessage, - ), - ], - ), - ), - ); - } -} - /// ResultDisplays shows the result of the call. Either the returned result /// from the `example.greeting` endpoint method or an error message. class ResultDisplay extends StatelessWidget { diff --git a/wien_talks/wien_talks_flutter/lib/news_screen.dart b/wien_talks/wien_talks_flutter/lib/news_screen.dart index 93dad3b..84507cb 100644 --- a/wien_talks/wien_talks_flutter/lib/news_screen.dart +++ b/wien_talks/wien_talks_flutter/lib/news_screen.dart @@ -11,21 +11,6 @@ class NewsScreen extends StatelessWidget { @override Widget build(BuildContext context) { - var column = Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - HeadingText(text: "Latest news"), - ...[Text("News 1"), Text("News 2")], - SizedBox( - height: 30, - ), - OutlinedButton( - onPressed: () { - context.pushNamed("create_event"); - }, - child: Text("Submit your own event")), - ], - ); return ScreenWidget( child: SingleChildScrollView( child: Column( diff --git a/wien_talks/wien_talks_flutter/macos/Flutter/GeneratedPluginRegistrant.swift b/wien_talks/wien_talks_flutter/macos/Flutter/GeneratedPluginRegistrant.swift index 407ec0f..19702fe 100644 --- a/wien_talks/wien_talks_flutter/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/wien_talks/wien_talks_flutter/macos/Flutter/GeneratedPluginRegistrant.swift @@ -8,6 +8,7 @@ import Foundation import connectivity_plus import file_picker import file_selector_macos +import google_sign_in_ios import location import path_provider_foundation import shared_preferences_foundation @@ -17,6 +18,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { ConnectivityPlusPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlusPlugin")) FilePickerPlugin.register(with: registry.registrar(forPlugin: "FilePickerPlugin")) FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) + FLTGoogleSignInPlugin.register(with: registry.registrar(forPlugin: "FLTGoogleSignInPlugin")) LocationPlugin.register(with: registry.registrar(forPlugin: "LocationPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) diff --git a/wien_talks/wien_talks_flutter/pubspec.yaml b/wien_talks/wien_talks_flutter/pubspec.yaml index 81a1e48..79bdab6 100644 --- a/wien_talks/wien_talks_flutter/pubspec.yaml +++ b/wien_talks/wien_talks_flutter/pubspec.yaml @@ -45,6 +45,7 @@ dependencies: # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.8 + google_sign_in: ^7.1.1 dev_dependencies: flutter_lints: '>=3.0.0 <7.0.0' diff --git a/wien_talks/wien_talks_server/lib/server.dart b/wien_talks/wien_talks_server/lib/server.dart index ed0e06c..e79820c 100644 --- a/wien_talks/wien_talks_server/lib/server.dart +++ b/wien_talks/wien_talks_server/lib/server.dart @@ -1,10 +1,8 @@ import 'package:serverpod/serverpod.dart'; import 'package:serverpod_auth_server/serverpod_auth_server.dart' as auth; -import 'package:wien_talks_server/src/birthday_reminder.dart'; import 'package:wien_talks_server/src/web/routes/root.dart'; import 'src/generated/endpoints.dart'; -import 'src/generated/protocol.dart'; // This is the starting point of your Serverpod server. In most cases, you will // only need to make additions to this file if you add future calls, are @@ -14,7 +12,7 @@ void run(List args) async { // Initialize Serverpod and connect it with your generated code. final pod = Serverpod( args, - Protocol(), + auth.Protocol(), Endpoints(), authenticationHandler: auth.authenticationHandler, ); @@ -38,28 +36,8 @@ void run(List args) async { // the background. Their schedule is persisted to the database, so you will // not lose them if the server is restarted. - pod.registerFutureCall( - BirthdayReminder(), - FutureCallNames.birthdayReminder.name, - ); - // You can schedule future calls for a later time during startup. But you can // also schedule them in any endpoint or webroute through the session object. // there is also [futureCallAtTime] if you want to schedule a future call at a // specific time. - await pod.futureCallWithDelay( - FutureCallNames.birthdayReminder.name, - Greeting( - message: 'Hello!', - author: 'Serverpod Server', - timestamp: DateTime.now(), - ), - Duration(seconds: 5), - ); } - -/// Names of all future calls in the server. -/// -/// This is better than using a string literal, as it will reduce the risk of -/// typos and make it easier to refactor the code. -enum FutureCallNames { birthdayReminder } diff --git a/wien_talks/wien_talks_server/lib/src/birthday_reminder.dart b/wien_talks/wien_talks_server/lib/src/birthday_reminder.dart deleted file mode 100644 index ef3d8cb..0000000 --- a/wien_talks/wien_talks_server/lib/src/birthday_reminder.dart +++ /dev/null @@ -1,18 +0,0 @@ -import 'package:wien_talks_server/src/generated/protocol.dart'; -import 'package:serverpod/serverpod.dart'; - -/// This is a simple example of a future call that logs a birthday reminder. -/// -/// In a real-world application, you would implement the logic to send a -/// an email or a push notification to the user. -class BirthdayReminder extends FutureCall { - @override - Future invoke(Session session, Greeting? object) async { - // This is where you would implement the logic to send a birthday reminder. - // For example, you could send an email or a notification to the user. - // You can access the user information from the `object` parameter if - // needed. - - session.log('${object?.message} Remember to send a birthday card!'); - } -} diff --git a/wien_talks/wien_talks_server/lib/src/generated/endpoints.dart b/wien_talks/wien_talks_server/lib/src/generated/endpoints.dart index b616e1a..a9cb545 100644 --- a/wien_talks/wien_talks_server/lib/src/generated/endpoints.dart +++ b/wien_talks/wien_talks_server/lib/src/generated/endpoints.dart @@ -10,54 +10,23 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'package:serverpod/serverpod.dart' as _i1; -import '../greeting_endpoint.dart' as _i2; -import '../quotes/quotes_endpoint.dart' as _i3; -import 'package:wien_talks_server/src/generated/quotes/quote.dart' as _i4; +import '../quotes/quotes_endpoint.dart' as _i2; +import 'package:wien_talks_server/src/generated/quotes/quote.dart' as _i3; import 'package:wien_talks_server/src/generated/quotes/create_quote.dart' - as _i5; -import 'package:serverpod_auth_server/serverpod_auth_server.dart' as _i6; + as _i4; +import 'package:serverpod_auth_server/serverpod_auth_server.dart' as _i5; class Endpoints extends _i1.EndpointDispatch { @override void initializeEndpoints(_i1.Server server) { var endpoints = { - 'greeting': _i2.GreetingEndpoint() - ..initialize( - server, - 'greeting', - null, - ), - 'quote': _i3.QuoteEndpoint() + 'quote': _i2.QuoteEndpoint() ..initialize( server, 'quote', null, - ), - }; - connectors['greeting'] = _i1.EndpointConnector( - name: 'greeting', - endpoint: endpoints['greeting']!, - methodConnectors: { - 'hello': _i1.MethodConnector( - name: 'hello', - params: { - 'name': _i1.ParameterDescription( - name: 'name', - type: _i1.getType(), - nullable: false, - ) - }, - call: ( - _i1.Session session, - Map params, - ) async => - (endpoints['greeting'] as _i2.GreetingEndpoint).hello( - session, - params['name'], - ), ) - }, - ); + }; connectors['quote'] = _i1.EndpointConnector( name: 'quote', endpoint: endpoints['quote']!, @@ -67,7 +36,7 @@ class Endpoints extends _i1.EndpointDispatch { params: { 'quote': _i1.ParameterDescription( name: 'quote', - type: _i1.getType<_i4.Quote>(), + type: _i1.getType<_i3.Quote>(), nullable: false, ) }, @@ -75,7 +44,7 @@ class Endpoints extends _i1.EndpointDispatch { _i1.Session session, Map params, ) async => - (endpoints['quote'] as _i3.QuoteEndpoint).updateQuote( + (endpoints['quote'] as _i2.QuoteEndpoint).updateQuote( session, params['quote'], ), @@ -85,7 +54,7 @@ class Endpoints extends _i1.EndpointDispatch { params: { 'req': _i1.ParameterDescription( name: 'req', - type: _i1.getType<_i5.CreateQuoteRequest>(), + type: _i1.getType<_i4.CreateQuoteRequest>(), nullable: false, ) }, @@ -93,7 +62,7 @@ class Endpoints extends _i1.EndpointDispatch { _i1.Session session, Map params, ) async => - (endpoints['quote'] as _i3.QuoteEndpoint).createQuote( + (endpoints['quote'] as _i2.QuoteEndpoint).createQuote( session, params['req'], ), @@ -111,7 +80,7 @@ class Endpoints extends _i1.EndpointDispatch { _i1.Session session, Map params, ) async => - (endpoints['quote'] as _i3.QuoteEndpoint).getQuoteById( + (endpoints['quote'] as _i2.QuoteEndpoint).getQuoteById( session, params['id'], ), @@ -123,7 +92,7 @@ class Endpoints extends _i1.EndpointDispatch { _i1.Session session, Map params, ) async => - (endpoints['quote'] as _i3.QuoteEndpoint).getAllQuotes(session), + (endpoints['quote'] as _i2.QuoteEndpoint).getAllQuotes(session), ), 'quoteUpdates': _i1.MethodStreamConnector( name: 'quoteUpdates', @@ -135,10 +104,10 @@ class Endpoints extends _i1.EndpointDispatch { Map params, Map streamParams, ) => - (endpoints['quote'] as _i3.QuoteEndpoint).quoteUpdates(session), + (endpoints['quote'] as _i2.QuoteEndpoint).quoteUpdates(session), ), }, ); - modules['serverpod_auth'] = _i6.Endpoints()..initializeEndpoints(server); + modules['serverpod_auth'] = _i5.Endpoints()..initializeEndpoints(server); } } diff --git a/wien_talks/wien_talks_server/lib/src/generated/greeting.dart b/wien_talks/wien_talks_server/lib/src/generated/greeting.dart deleted file mode 100644 index 005a7be..0000000 --- a/wien_talks/wien_talks_server/lib/src/generated/greeting.dart +++ /dev/null @@ -1,105 +0,0 @@ -/* AUTOMATICALLY GENERATED CODE DO NOT MODIFY */ -/* To generate run: "serverpod generate" */ - -// ignore_for_file: implementation_imports -// ignore_for_file: library_private_types_in_public_api -// ignore_for_file: non_constant_identifier_names -// ignore_for_file: public_member_api_docs -// ignore_for_file: type_literal_in_constant_pattern -// ignore_for_file: use_super_parameters - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'package:serverpod/serverpod.dart' as _i1; - -/// A greeting message which can be sent to or from the server. -abstract class Greeting - implements _i1.SerializableModel, _i1.ProtocolSerialization { - Greeting._({ - required this.message, - required this.author, - required this.timestamp, - }); - - factory Greeting({ - required String message, - required String author, - required DateTime timestamp, - }) = _GreetingImpl; - - factory Greeting.fromJson(Map jsonSerialization) { - return Greeting( - message: jsonSerialization['message'] as String, - author: jsonSerialization['author'] as String, - timestamp: - _i1.DateTimeJsonExtension.fromJson(jsonSerialization['timestamp']), - ); - } - - /// The greeting message. - String message; - - /// The author of the greeting message. - String author; - - /// The time when the message was created. - DateTime timestamp; - - /// Returns a shallow copy of this [Greeting] - /// with some or all fields replaced by the given arguments. - @_i1.useResult - Greeting copyWith({ - String? message, - String? author, - DateTime? timestamp, - }); - @override - Map toJson() { - return { - 'message': message, - 'author': author, - 'timestamp': timestamp.toJson(), - }; - } - - @override - Map toJsonForProtocol() { - return { - 'message': message, - 'author': author, - 'timestamp': timestamp.toJson(), - }; - } - - @override - String toString() { - return _i1.SerializationManager.encode(this); - } -} - -class _GreetingImpl extends Greeting { - _GreetingImpl({ - required String message, - required String author, - required DateTime timestamp, - }) : super._( - message: message, - author: author, - timestamp: timestamp, - ); - - /// Returns a shallow copy of this [Greeting] - /// with some or all fields replaced by the given arguments. - @_i1.useResult - @override - Greeting copyWith({ - String? message, - String? author, - DateTime? timestamp, - }) { - return Greeting( - message: message ?? this.message, - author: author ?? this.author, - timestamp: timestamp ?? this.timestamp, - ); - } -} diff --git a/wien_talks/wien_talks_server/lib/src/generated/protocol.dart b/wien_talks/wien_talks_server/lib/src/generated/protocol.dart index 8a3b130..681724b 100644 --- a/wien_talks/wien_talks_server/lib/src/generated/protocol.dart +++ b/wien_talks/wien_talks_server/lib/src/generated/protocol.dart @@ -12,11 +12,9 @@ import 'package:serverpod/serverpod.dart' as _i1; import 'package:serverpod/protocol.dart' as _i2; import 'package:serverpod_auth_server/serverpod_auth_server.dart' as _i3; -import 'greeting.dart' as _i4; -import 'quotes/create_quote.dart' as _i5; -import 'quotes/quote.dart' as _i6; -import 'package:wien_talks_server/src/generated/quotes/quote.dart' as _i7; -export 'greeting.dart'; +import 'quotes/create_quote.dart' as _i4; +import 'quotes/quote.dart' as _i5; +import 'package:wien_talks_server/src/generated/quotes/quote.dart' as _i6; export 'quotes/create_quote.dart'; export 'quotes/quote.dart'; @@ -130,23 +128,17 @@ class Protocol extends _i1.SerializationManagerServer { Type? t, ]) { t ??= T; - if (t == _i4.Greeting) { - return _i4.Greeting.fromJson(data) as T; + if (t == _i4.CreateQuoteRequest) { + return _i4.CreateQuoteRequest.fromJson(data) as T; } - if (t == _i5.CreateQuoteRequest) { - return _i5.CreateQuoteRequest.fromJson(data) as T; + if (t == _i5.Quote) { + return _i5.Quote.fromJson(data) as T; } - if (t == _i6.Quote) { - return _i6.Quote.fromJson(data) as T; + if (t == _i1.getType<_i4.CreateQuoteRequest?>()) { + return (data != null ? _i4.CreateQuoteRequest.fromJson(data) : null) as T; } - if (t == _i1.getType<_i4.Greeting?>()) { - return (data != null ? _i4.Greeting.fromJson(data) : null) as T; - } - if (t == _i1.getType<_i5.CreateQuoteRequest?>()) { - return (data != null ? _i5.CreateQuoteRequest.fromJson(data) : null) as T; - } - if (t == _i1.getType<_i6.Quote?>()) { - return (data != null ? _i6.Quote.fromJson(data) : null) as T; + if (t == _i1.getType<_i5.Quote?>()) { + return (data != null ? _i5.Quote.fromJson(data) : null) as T; } if (t == _i1.getType?>()) { return (data != null @@ -158,8 +150,8 @@ class Protocol extends _i1.SerializationManagerServer { ? (data as List).map((e) => deserialize(e)).toList() : null) as T; } - if (t == List<_i7.Quote>) { - return (data as List).map((e) => deserialize<_i7.Quote>(e)).toList() as T; + if (t == List<_i6.Quote>) { + return (data as List).map((e) => deserialize<_i6.Quote>(e)).toList() as T; } try { return _i3.Protocol().deserialize(data, t); @@ -174,13 +166,10 @@ class Protocol extends _i1.SerializationManagerServer { String? getClassNameForObject(Object? data) { String? className = super.getClassNameForObject(data); if (className != null) return className; - if (data is _i4.Greeting) { - return 'Greeting'; - } - if (data is _i5.CreateQuoteRequest) { + if (data is _i4.CreateQuoteRequest) { return 'CreateQuoteRequest'; } - if (data is _i6.Quote) { + if (data is _i5.Quote) { return 'Quote'; } className = _i2.Protocol().getClassNameForObject(data); @@ -200,14 +189,11 @@ class Protocol extends _i1.SerializationManagerServer { if (dataClassName is! String) { return super.deserializeByClassName(data); } - if (dataClassName == 'Greeting') { - return deserialize<_i4.Greeting>(data['data']); - } if (dataClassName == 'CreateQuoteRequest') { - return deserialize<_i5.CreateQuoteRequest>(data['data']); + return deserialize<_i4.CreateQuoteRequest>(data['data']); } if (dataClassName == 'Quote') { - return deserialize<_i6.Quote>(data['data']); + return deserialize<_i5.Quote>(data['data']); } if (dataClassName.startsWith('serverpod.')) { data['className'] = dataClassName.substring(10); @@ -235,8 +221,8 @@ class Protocol extends _i1.SerializationManagerServer { } } switch (t) { - case _i6.Quote: - return _i6.Quote.t; + case _i5.Quote: + return _i5.Quote.t; } return null; } diff --git a/wien_talks/wien_talks_server/lib/src/generated/protocol.yaml b/wien_talks/wien_talks_server/lib/src/generated/protocol.yaml index 160b550..fd8118a 100644 --- a/wien_talks/wien_talks_server/lib/src/generated/protocol.yaml +++ b/wien_talks/wien_talks_server/lib/src/generated/protocol.yaml @@ -1,5 +1,3 @@ -greeting: - - hello: quote: - updateQuote: - quoteUpdates: diff --git a/wien_talks/wien_talks_server/lib/src/greeting.spy.yaml b/wien_talks/wien_talks_server/lib/src/greeting.spy.yaml deleted file mode 100644 index 3d08c8b..0000000 --- a/wien_talks/wien_talks_server/lib/src/greeting.spy.yaml +++ /dev/null @@ -1,24 +0,0 @@ -# Yaml-files in the `models` directory specify which serializable objects -# should be generated. When you add or modify a file, you will need to run -# `serverpod generate` to make the generated classes available in the server and -# client. -# -# Please consult the documentation for more information on what you can add to -# your yaml-files. - -### A greeting message which can be sent to or from the server. -class: Greeting - -# Add the table key, if this class represents a row in the database. -#table: greeting - -# The fields (and columns if connected to the database) of the class. -# For a list of supported types, please see the documentation. -# https://docs.serverpod.dev/concepts/working-with-endpoints -fields: - ### The greeting message. - message: String - ### The author of the greeting message. - author: String - ### The time when the message was created. - timestamp: DateTime diff --git a/wien_talks/wien_talks_server/lib/src/greeting_endpoint.dart b/wien_talks/wien_talks_server/lib/src/greeting_endpoint.dart deleted file mode 100644 index 9faab19..0000000 --- a/wien_talks/wien_talks_server/lib/src/greeting_endpoint.dart +++ /dev/null @@ -1,34 +0,0 @@ -import 'generated/protocol.dart'; -import 'package:serverpod/serverpod.dart'; - -// This is an example endpoint of your server. It's best practice to use the -// `Endpoint` ending of the class name, but it will be removed when accessing -// the endpoint from the client. I.e., this endpoint can be accessed through -// `client.greeting` on the client side. - -// After adding or modifying an endpoint, you will need to run -// `serverpod generate` to update the server and client code. - -/// This is an example endpoint that returns a greeting message through -/// its [hello] method. -class GreetingEndpoint extends Endpoint { - // This method is called when the client calls the `hello` method on the - // `greeting` endpoint. - // - // The `Session` parameter contains the context of the client request. - // It provides access to the database and other server-side resources like - // secrets from your password file, the cache, storage, and server-event - // messaging. - // - // You can use any serializable type as a parameter or return type, read more - // in the [docs](https://docs.serverpod.dev/concepts/working-with-endpoints). - - /// Returns a personalized greeting message: "Hello {name}". - Future hello(Session session, String name) async { - return Greeting( - message: 'Hello $name', - author: 'Serverpod', - timestamp: DateTime.now(), - ); - } -} diff --git a/wien_talks/wien_talks_server/lib/src/quotes/quotes_endpoint.dart b/wien_talks/wien_talks_server/lib/src/quotes/quotes_endpoint.dart index 6108211..d45d704 100644 --- a/wien_talks/wien_talks_server/lib/src/quotes/quotes_endpoint.dart +++ b/wien_talks/wien_talks_server/lib/src/quotes/quotes_endpoint.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:serverpod/serverpod.dart'; import 'package:wien_talks_server/src/generated/protocol.dart'; import 'package:wien_talks_server/src/quotes/quote_util.dart'; @@ -21,21 +23,14 @@ class QuoteEndpoint extends Endpoint { Future createQuote(Session session, CreateQuoteRequest req) async { final authInfo = await session.authenticated; - final userId = authInfo?.userId; - - if (userId == null) { - throw Exception('Not signed in'); - } + final userId = Random().nextInt(100); String text = validateQuote(req); final quote = Quote( - id: 0, userId: userId, text: text, - authorName: req.authorName?.trim().isEmpty == true - ? null - : req.authorName!.trim(), + authorName: req.authorName, lat: req.lat, long: req.lng, createdAt: DateTime.now().toUtc(), diff --git a/wien_talks/wien_talks_server/test/integration/greeting_endpoint_test.dart b/wien_talks/wien_talks_server/test/integration/greeting_endpoint_test.dart deleted file mode 100644 index 5049049..0000000 --- a/wien_talks/wien_talks_server/test/integration/greeting_endpoint_test.dart +++ /dev/null @@ -1,24 +0,0 @@ -import 'package:test/test.dart'; - -// Import the generated test helper file, it contains everything you need. -import 'test_tools/serverpod_test_tools.dart'; - -void main() { - // This is an example test that uses the `withServerpod` test helper. - // `withServerpod` enables you to call your endpoints directly from the test like regular functions. - // Note that after adding or modifying an endpoint, you will need to run - // `serverpod generate` to update the test tools code. - // Refer to the docs for more information on how to use the test helper. - withServerpod('Given Greeting endpoint', (sessionBuilder, endpoints) { - test( - 'when calling `hello` with name then returned greeting includes name', - () async { - // Call the endpoint method by using the `endpoints` parameter and - // pass `sessionBuilder` as a first argument. Refer to the docs on - // how to use the `sessionBuilder` to set up different test scenarios. - final greeting = await endpoints.greeting.hello(sessionBuilder, 'Bob'); - expect(greeting.message, 'Hello Bob'); - }, - ); - }); -} diff --git a/wien_talks/wien_talks_server/test/integration/test_tools/serverpod_test_tools.dart b/wien_talks/wien_talks_server/test/integration/test_tools/serverpod_test_tools.dart index 6c77e53..aa1b0e9 100644 --- a/wien_talks/wien_talks_server/test/integration/test_tools/serverpod_test_tools.dart +++ b/wien_talks/wien_talks_server/test/integration/test_tools/serverpod_test_tools.dart @@ -14,10 +14,9 @@ import 'package:serverpod_test/serverpod_test.dart' as _i1; import 'package:serverpod/serverpod.dart' as _i2; import 'dart:async' as _i3; -import 'package:wien_talks_server/src/generated/greeting.dart' as _i4; -import 'package:wien_talks_server/src/generated/quotes/quote.dart' as _i5; +import 'package:wien_talks_server/src/generated/quotes/quote.dart' as _i4; import 'package:wien_talks_server/src/generated/quotes/create_quote.dart' - as _i6; + as _i5; import 'package:wien_talks_server/src/generated/protocol.dart'; import 'package:wien_talks_server/src/generated/endpoints.dart'; export 'package:serverpod_test/serverpod_test_public_exports.dart'; @@ -104,8 +103,6 @@ void withServerpod( } class TestEndpoints { - late final _GreetingEndpoint greeting; - late final _QuoteEndpoint quote; } @@ -116,10 +113,6 @@ class _InternalTestEndpoints extends TestEndpoints _i2.SerializationManager serializationManager, _i2.EndpointDispatch endpoints, ) { - greeting = _GreetingEndpoint( - endpoints, - serializationManager, - ); quote = _QuoteEndpoint( endpoints, serializationManager, @@ -127,46 +120,6 @@ class _InternalTestEndpoints extends TestEndpoints } } -class _GreetingEndpoint { - _GreetingEndpoint( - this._endpointDispatch, - this._serializationManager, - ); - - final _i2.EndpointDispatch _endpointDispatch; - - final _i2.SerializationManager _serializationManager; - - _i3.Future<_i4.Greeting> hello( - _i1.TestSessionBuilder sessionBuilder, - String name, - ) async { - return _i1.callAwaitableFunctionAndHandleExceptions(() async { - var _localUniqueSession = - (sessionBuilder as _i1.InternalTestSessionBuilder).internalBuild( - endpoint: 'greeting', - method: 'hello', - ); - try { - var _localCallContext = await _endpointDispatch.getMethodCallContext( - createSessionCallback: (_) => _localUniqueSession, - endpointPath: 'greeting', - methodName: 'hello', - parameters: _i1.testObjectToJson({'name': name}), - serializationManager: _serializationManager, - ); - var _localReturnValue = await (_localCallContext.method.call( - _localUniqueSession, - _localCallContext.arguments, - ) as _i3.Future<_i4.Greeting>); - return _localReturnValue; - } finally { - await _localUniqueSession.close(); - } - }); - } -} - class _QuoteEndpoint { _QuoteEndpoint( this._endpointDispatch, @@ -179,7 +132,7 @@ class _QuoteEndpoint { _i3.Future updateQuote( _i1.TestSessionBuilder sessionBuilder, - _i5.Quote quote, + _i4.Quote quote, ) async { return _i1.callAwaitableFunctionAndHandleExceptions(() async { var _localUniqueSession = @@ -206,8 +159,8 @@ class _QuoteEndpoint { }); } - _i3.Stream<_i5.Quote> quoteUpdates(_i1.TestSessionBuilder sessionBuilder) { - var _localTestStreamManager = _i1.TestStreamManager<_i5.Quote>(); + _i3.Stream<_i4.Quote> quoteUpdates(_i1.TestSessionBuilder sessionBuilder) { + var _localTestStreamManager = _i1.TestStreamManager<_i4.Quote>(); _i1.callStreamFunctionAndHandleExceptions( () async { var _localUniqueSession = @@ -235,9 +188,9 @@ class _QuoteEndpoint { return _localTestStreamManager.outputStreamController.stream; } - _i3.Future<_i5.Quote> createQuote( + _i3.Future<_i4.Quote> createQuote( _i1.TestSessionBuilder sessionBuilder, - _i6.CreateQuoteRequest req, + _i5.CreateQuoteRequest req, ) async { return _i1.callAwaitableFunctionAndHandleExceptions(() async { var _localUniqueSession = @@ -256,7 +209,7 @@ class _QuoteEndpoint { var _localReturnValue = await (_localCallContext.method.call( _localUniqueSession, _localCallContext.arguments, - ) as _i3.Future<_i5.Quote>); + ) as _i3.Future<_i4.Quote>); return _localReturnValue; } finally { await _localUniqueSession.close(); @@ -264,7 +217,7 @@ class _QuoteEndpoint { }); } - _i3.Future<_i5.Quote> getQuoteById( + _i3.Future<_i4.Quote> getQuoteById( _i1.TestSessionBuilder sessionBuilder, int id, ) async { @@ -285,7 +238,7 @@ class _QuoteEndpoint { var _localReturnValue = await (_localCallContext.method.call( _localUniqueSession, _localCallContext.arguments, - ) as _i3.Future<_i5.Quote>); + ) as _i3.Future<_i4.Quote>); return _localReturnValue; } finally { await _localUniqueSession.close(); @@ -293,7 +246,7 @@ class _QuoteEndpoint { }); } - _i3.Future> getAllQuotes( + _i3.Future> getAllQuotes( _i1.TestSessionBuilder sessionBuilder) async { return _i1.callAwaitableFunctionAndHandleExceptions(() async { var _localUniqueSession = @@ -312,7 +265,7 @@ class _QuoteEndpoint { var _localReturnValue = await (_localCallContext.method.call( _localUniqueSession, _localCallContext.arguments, - ) as _i3.Future>); + ) as _i3.Future>); return _localReturnValue; } finally { await _localUniqueSession.close();