mirror of
https://github.com/timokz/flutter-vienna-hackathon-25.git
synced 2025-11-08 19:04:20 +01:00
merge generated jank
This commit is contained in:
parent
c64fa677ac
commit
be2a58cbd9
9 changed files with 347 additions and 129 deletions
|
|
@ -13,8 +13,10 @@ import 'package:serverpod_client/serverpod_client.dart' as _i1;
|
|||
import 'dart:async' as _i2;
|
||||
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;
|
||||
import 'package:wien_talks_client/src/protocol/votes/vote.dart' as _i5;
|
||||
import 'package:wien_talks_client/src/protocol/votes/vote_request.dart' as _i6;
|
||||
import 'package:serverpod_auth_client/serverpod_auth_client.dart' as _i7;
|
||||
import 'protocol.dart' as _i8;
|
||||
|
||||
/// {@category Endpoint}
|
||||
class EndpointShowLatestNewsWidget extends _i1.EndpointRef {
|
||||
|
|
@ -37,20 +39,42 @@ class EndpointShowLatestNewsWidget extends _i1.EndpointRef {
|
|||
{'quote': quote},
|
||||
);
|
||||
|
||||
_i2.Future<List<_i3.Quote>> getAllQuotes({required int limit}) =>
|
||||
_i2.Future<List<_i3.Quote>> getAllQuotes() =>
|
||||
caller.callServerEndpoint<List<_i3.Quote>>(
|
||||
'showLatestNewsWidget',
|
||||
'getAllQuotes',
|
||||
{'limit': limit},
|
||||
{},
|
||||
);
|
||||
}
|
||||
|
||||
/// {@category Endpoint}
|
||||
class EndpointVotes extends _i1.EndpointRef {
|
||||
EndpointVotes(_i1.EndpointCaller caller) : super(caller);
|
||||
|
||||
@override
|
||||
String get name => 'votes';
|
||||
|
||||
_i2.Future<_i5.Vote> postVote(_i6.VoteRequest voteRequest) =>
|
||||
caller.callServerEndpoint<_i5.Vote>(
|
||||
'votes',
|
||||
'postVote',
|
||||
{'voteRequest': voteRequest},
|
||||
);
|
||||
|
||||
_i2.Future<List<_i5.Vote>> getAllVotes() =>
|
||||
caller.callServerEndpoint<List<_i5.Vote>>(
|
||||
'votes',
|
||||
'getAllVotes',
|
||||
{},
|
||||
);
|
||||
}
|
||||
|
||||
class Modules {
|
||||
Modules(Client client) {
|
||||
auth = _i5.Caller(client);
|
||||
auth = _i7.Caller(client);
|
||||
}
|
||||
|
||||
late final _i5.Caller auth;
|
||||
late final _i7.Caller auth;
|
||||
}
|
||||
|
||||
class Client extends _i1.ServerpodClientShared {
|
||||
|
|
@ -69,7 +93,7 @@ class Client extends _i1.ServerpodClientShared {
|
|||
bool? disconnectStreamsOnLostInternetConnection,
|
||||
}) : super(
|
||||
host,
|
||||
_i6.Protocol(),
|
||||
_i8.Protocol(),
|
||||
securityContext: securityContext,
|
||||
authenticationKeyManager: authenticationKeyManager,
|
||||
streamingConnectionTimeout: streamingConnectionTimeout,
|
||||
|
|
@ -85,6 +109,8 @@ class Client extends _i1.ServerpodClientShared {
|
|||
|
||||
late final EndpointShowLatestNewsWidget showLatestNewsWidget;
|
||||
|
||||
late final EndpointVotes votes;
|
||||
|
||||
late final Modules modules;
|
||||
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -12,10 +12,15 @@
|
|||
import 'package:serverpod_client/serverpod_client.dart' as _i1;
|
||||
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;
|
||||
import 'votes/vote.dart' as _i4;
|
||||
import 'votes/vote_request.dart' as _i5;
|
||||
import 'package:wien_talks_client/src/protocol/quotes/quote.dart' as _i6;
|
||||
import 'package:wien_talks_client/src/protocol/votes/vote.dart' as _i7;
|
||||
import 'package:serverpod_auth_client/serverpod_auth_client.dart' as _i8;
|
||||
export 'quotes/create_quote.dart';
|
||||
export 'quotes/quote.dart';
|
||||
export 'votes/vote.dart';
|
||||
export 'votes/vote_request.dart';
|
||||
export 'client.dart';
|
||||
|
||||
class Protocol extends _i1.SerializationManager {
|
||||
|
|
@ -37,12 +42,24 @@ class Protocol extends _i1.SerializationManager {
|
|||
if (t == _i3.Quote) {
|
||||
return _i3.Quote.fromJson(data) as T;
|
||||
}
|
||||
if (t == _i4.Vote) {
|
||||
return _i4.Vote.fromJson(data) as T;
|
||||
}
|
||||
if (t == _i5.VoteRequest) {
|
||||
return _i5.VoteRequest.fromJson(data) as T;
|
||||
}
|
||||
if (t == _i1.getType<_i2.CreateQuoteRequest?>()) {
|
||||
return (data != null ? _i2.CreateQuoteRequest.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<_i4.Vote?>()) {
|
||||
return (data != null ? _i4.Vote.fromJson(data) : null) as T;
|
||||
}
|
||||
if (t == _i1.getType<_i5.VoteRequest?>()) {
|
||||
return (data != null ? _i5.VoteRequest.fromJson(data) : null) as T;
|
||||
}
|
||||
if (t == _i1.getType<List<String>?>()) {
|
||||
return (data != null
|
||||
? (data as List).map((e) => deserialize<String>(e)).toList()
|
||||
|
|
@ -53,11 +70,14 @@ class Protocol extends _i1.SerializationManager {
|
|||
? (data as List).map((e) => deserialize<String>(e)).toList()
|
||||
: null) as T;
|
||||
}
|
||||
if (t == List<_i4.Quote>) {
|
||||
return (data as List).map((e) => deserialize<_i4.Quote>(e)).toList() as T;
|
||||
if (t == List<_i6.Quote>) {
|
||||
return (data as List).map((e) => deserialize<_i6.Quote>(e)).toList() as T;
|
||||
}
|
||||
if (t == List<_i7.Vote>) {
|
||||
return (data as List).map((e) => deserialize<_i7.Vote>(e)).toList() as T;
|
||||
}
|
||||
try {
|
||||
return _i5.Protocol().deserialize<T>(data, t);
|
||||
return _i8.Protocol().deserialize<T>(data, t);
|
||||
} on _i1.DeserializationTypeNotFoundException catch (_) {}
|
||||
return super.deserialize<T>(data, t);
|
||||
}
|
||||
|
|
@ -72,7 +92,13 @@ class Protocol extends _i1.SerializationManager {
|
|||
if (data is _i3.Quote) {
|
||||
return 'Quote';
|
||||
}
|
||||
className = _i5.Protocol().getClassNameForObject(data);
|
||||
if (data is _i4.Vote) {
|
||||
return 'Vote';
|
||||
}
|
||||
if (data is _i5.VoteRequest) {
|
||||
return 'VoteRequest';
|
||||
}
|
||||
className = _i8.Protocol().getClassNameForObject(data);
|
||||
if (className != null) {
|
||||
return 'serverpod_auth.$className';
|
||||
}
|
||||
|
|
@ -91,9 +117,15 @@ class Protocol extends _i1.SerializationManager {
|
|||
if (dataClassName == 'Quote') {
|
||||
return deserialize<_i3.Quote>(data['data']);
|
||||
}
|
||||
if (dataClassName == 'Vote') {
|
||||
return deserialize<_i4.Vote>(data['data']);
|
||||
}
|
||||
if (dataClassName == 'VoteRequest') {
|
||||
return deserialize<_i5.VoteRequest>(data['data']);
|
||||
}
|
||||
if (dataClassName.startsWith('serverpod_auth.')) {
|
||||
data['className'] = dataClassName.substring(15);
|
||||
return _i5.Protocol().deserializeByClassName(data);
|
||||
return _i8.Protocol().deserializeByClassName(data);
|
||||
}
|
||||
return super.deserializeByClassName(data);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,84 +4,54 @@ import 'package:flutter/material.dart';
|
|||
import 'package:wien_talks_client/wien_talks_client.dart';
|
||||
import 'package:wien_talks_flutter/helper/funmap_mgr.dart';
|
||||
|
||||
class ShowLatestNewsWidget extends StatefulWidget {
|
||||
class ShowLatestNewsWidget extends StatelessWidget {
|
||||
const ShowLatestNewsWidget({super.key});
|
||||
@override
|
||||
State<ShowLatestNewsWidget> createState() => _ShowLatestNewsWidgetState();
|
||||
}
|
||||
|
||||
class _ShowLatestNewsWidgetState extends State<ShowLatestNewsWidget> {
|
||||
final _controller = StreamController<List<Quote>>.broadcast();
|
||||
Timer? _timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_reload();
|
||||
_timer = Timer.periodic(const Duration(seconds: 30), (_) => _reload());
|
||||
}
|
||||
|
||||
Future<void> _reload() async {
|
||||
try {
|
||||
final quotes = await FunmapMgr().client.quote.getAllQuotes(limit: 200);
|
||||
_controller.add(quotes);
|
||||
} catch (e, st) {
|
||||
_controller.addError(e, st);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
_controller.close();
|
||||
super.dispose();
|
||||
Future<List<Quote>> _load() async {
|
||||
final list = await FunmapMgr().client.quote.getAllQuotes();
|
||||
return list.whereType<Quote>().toList(growable: false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: _reload,
|
||||
child: StreamBuilder<List<Quote>>(
|
||||
stream: _controller.stream,
|
||||
initialData: const <Quote>[],
|
||||
builder: (context, snap) {
|
||||
if (snap.hasError) {
|
||||
return ListView(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text('Error: ${snap.error}'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
final quotes = snap.data ?? const <Quote>[];
|
||||
if (quotes.isEmpty) {
|
||||
return ListView(
|
||||
children: const [
|
||||
Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Text('No quotes yet. Pull to refresh.'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return ListView.separated(
|
||||
itemCount: quotes.length,
|
||||
separatorBuilder: (_, __) => const Divider(height: 1),
|
||||
itemBuilder: (context, i) {
|
||||
final q = quotes[i];
|
||||
return ListTile(
|
||||
title: Text(q.text),
|
||||
subtitle: Text([
|
||||
if ((q.authorName ?? '').isNotEmpty) q.authorName!,
|
||||
q.createdAt.toLocal().toString(),
|
||||
].where((e) => e.isNotEmpty).join(' · ')),
|
||||
);
|
||||
},
|
||||
return FutureBuilder<List<Quote>>(
|
||||
future: _load(),
|
||||
builder: (context, snap) {
|
||||
if (snap.connectionState != ConnectionState.done) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
if (snap.hasError) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text('Error: ${snap.error}'),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
}
|
||||
final quotes = snap.data ?? const <Quote>[];
|
||||
if (quotes.isEmpty) {
|
||||
return const Center(child: Text('No quotes yet.'));
|
||||
}
|
||||
|
||||
return ListView.separated(
|
||||
itemCount: quotes.length,
|
||||
separatorBuilder: (_, __) => const Divider(height: 1),
|
||||
itemBuilder: (context, i) {
|
||||
final q = quotes[i];
|
||||
final author = (q.authorName ?? '').trim();
|
||||
final when = (q.createdAt ?? DateTime.fromMillisecondsSinceEpoch(0))
|
||||
.toLocal()
|
||||
.toString();
|
||||
return ListTile(
|
||||
title: Text(q.text),
|
||||
subtitle: Text([
|
||||
if (author.isNotEmpty) author,
|
||||
when,
|
||||
].join(' · ')),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,10 +11,12 @@
|
|||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'package:serverpod/serverpod.dart' as _i1;
|
||||
import '../quotes/quotes_endpoint.dart' as _i2;
|
||||
import '../votes/votes_endpoint.dart' as _i3;
|
||||
import 'package:wien_talks_server/src/generated/quotes/create_quote.dart'
|
||||
as _i3;
|
||||
import 'package:wien_talks_server/src/generated/quotes/quote.dart' as _i4;
|
||||
import 'package:serverpod_auth_server/serverpod_auth_server.dart' as _i5;
|
||||
as _i4;
|
||||
import 'package:wien_talks_server/src/generated/quotes/quote.dart' as _i5;
|
||||
import 'package:wien_talks_server/src/generated/votes/vote_request.dart' as _i6;
|
||||
import 'package:serverpod_auth_server/serverpod_auth_server.dart' as _i7;
|
||||
|
||||
class Endpoints extends _i1.EndpointDispatch {
|
||||
@override
|
||||
|
|
@ -36,7 +38,7 @@ class Endpoints extends _i1.EndpointDispatch {
|
|||
params: {
|
||||
'req': _i1.ParameterDescription(
|
||||
name: 'req',
|
||||
type: _i1.getType<_i3.CreateQuoteRequest>(),
|
||||
type: _i1.getType<_i4.CreateQuoteRequest>(),
|
||||
nullable: false,
|
||||
)
|
||||
},
|
||||
|
|
@ -55,7 +57,7 @@ class Endpoints extends _i1.EndpointDispatch {
|
|||
params: {
|
||||
'quote': _i1.ParameterDescription(
|
||||
name: 'quote',
|
||||
type: _i1.getType<_i4.Quote>(),
|
||||
type: _i1.getType<_i5.Quote>(),
|
||||
nullable: false,
|
||||
)
|
||||
},
|
||||
|
|
@ -71,10 +73,25 @@ class Endpoints extends _i1.EndpointDispatch {
|
|||
),
|
||||
'getAllQuotes': _i1.MethodConnector(
|
||||
name: 'getAllQuotes',
|
||||
params: {},
|
||||
call: (
|
||||
_i1.Session session,
|
||||
Map<String, dynamic> params,
|
||||
) async =>
|
||||
(endpoints['quote'] as _i2.QuoteEndpoint).getAllQuotes(session),
|
||||
),
|
||||
},
|
||||
);
|
||||
connectors['votes'] = _i1.EndpointConnector(
|
||||
name: 'votes',
|
||||
endpoint: endpoints['votes']!,
|
||||
methodConnectors: {
|
||||
'postVote': _i1.MethodConnector(
|
||||
name: 'postVote',
|
||||
params: {
|
||||
'limit': _i1.ParameterDescription(
|
||||
name: 'limit',
|
||||
type: _i1.getType<int>(),
|
||||
'voteRequest': _i1.ParameterDescription(
|
||||
name: 'voteRequest',
|
||||
type: _i1.getType<_i6.VoteRequest>(),
|
||||
nullable: false,
|
||||
)
|
||||
},
|
||||
|
|
@ -85,11 +102,20 @@ class Endpoints extends _i1.EndpointDispatch {
|
|||
(endpoints['showLatestNewsWidget'] as _i2.ShowLatestNewsWidget)
|
||||
.getAllQuotes(
|
||||
session,
|
||||
limit: params['limit'],
|
||||
params['voteRequest'],
|
||||
),
|
||||
),
|
||||
'getAllVotes': _i1.MethodConnector(
|
||||
name: 'getAllVotes',
|
||||
params: {},
|
||||
call: (
|
||||
_i1.Session session,
|
||||
Map<String, dynamic> params,
|
||||
) async =>
|
||||
(endpoints['votes'] as _i3.VotesEndpoint).getAllVotes(session),
|
||||
),
|
||||
},
|
||||
);
|
||||
modules['serverpod_auth'] = _i5.Endpoints()..initializeEndpoints(server);
|
||||
modules['serverpod_auth'] = _i7.Endpoints()..initializeEndpoints(server);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,14 @@ import 'package:serverpod/protocol.dart' as _i2;
|
|||
import 'package:serverpod_auth_server/serverpod_auth_server.dart' as _i3;
|
||||
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;
|
||||
import 'votes/vote.dart' as _i6;
|
||||
import 'votes/vote_request.dart' as _i7;
|
||||
import 'package:wien_talks_server/src/generated/quotes/quote.dart' as _i8;
|
||||
import 'package:wien_talks_server/src/generated/votes/vote.dart' as _i9;
|
||||
export 'quotes/create_quote.dart';
|
||||
export 'quotes/quote.dart';
|
||||
export 'votes/vote.dart';
|
||||
export 'votes/vote_request.dart';
|
||||
|
||||
class Protocol extends _i1.SerializationManagerServer {
|
||||
Protocol._();
|
||||
|
|
@ -118,6 +123,112 @@ class Protocol extends _i1.SerializationManagerServer {
|
|||
],
|
||||
managed: true,
|
||||
),
|
||||
_i2.TableDefinition(
|
||||
name: 'vote',
|
||||
dartName: 'Vote',
|
||||
schema: 'public',
|
||||
module: 'wien_talks',
|
||||
columns: [
|
||||
_i2.ColumnDefinition(
|
||||
name: 'id',
|
||||
columnType: _i2.ColumnType.bigint,
|
||||
isNullable: false,
|
||||
dartType: 'int?',
|
||||
columnDefault: 'nextval(\'vote_id_seq\'::regclass)',
|
||||
),
|
||||
_i2.ColumnDefinition(
|
||||
name: 'userId',
|
||||
columnType: _i2.ColumnType.bigint,
|
||||
isNullable: false,
|
||||
dartType: 'int',
|
||||
),
|
||||
_i2.ColumnDefinition(
|
||||
name: 'createdAt',
|
||||
columnType: _i2.ColumnType.timestampWithoutTimeZone,
|
||||
isNullable: false,
|
||||
dartType: 'DateTime',
|
||||
),
|
||||
_i2.ColumnDefinition(
|
||||
name: 'quote',
|
||||
columnType: _i2.ColumnType.json,
|
||||
isNullable: false,
|
||||
dartType: 'protocol:Quote',
|
||||
),
|
||||
_i2.ColumnDefinition(
|
||||
name: 'upvote',
|
||||
columnType: _i2.ColumnType.boolean,
|
||||
isNullable: false,
|
||||
dartType: 'bool',
|
||||
),
|
||||
],
|
||||
foreignKeys: [],
|
||||
indexes: [
|
||||
_i2.IndexDefinition(
|
||||
indexName: 'vote_pkey',
|
||||
tableSpace: null,
|
||||
elements: [
|
||||
_i2.IndexElementDefinition(
|
||||
type: _i2.IndexElementDefinitionType.column,
|
||||
definition: 'id',
|
||||
)
|
||||
],
|
||||
type: 'btree',
|
||||
isUnique: true,
|
||||
isPrimary: true,
|
||||
)
|
||||
],
|
||||
managed: true,
|
||||
),
|
||||
_i2.TableDefinition(
|
||||
name: 'vote_request',
|
||||
dartName: 'VoteRequest',
|
||||
schema: 'public',
|
||||
module: 'wien_talks',
|
||||
columns: [
|
||||
_i2.ColumnDefinition(
|
||||
name: 'id',
|
||||
columnType: _i2.ColumnType.bigint,
|
||||
isNullable: false,
|
||||
dartType: 'int?',
|
||||
columnDefault: 'nextval(\'vote_request_id_seq\'::regclass)',
|
||||
),
|
||||
_i2.ColumnDefinition(
|
||||
name: 'userId',
|
||||
columnType: _i2.ColumnType.bigint,
|
||||
isNullable: false,
|
||||
dartType: 'int',
|
||||
),
|
||||
_i2.ColumnDefinition(
|
||||
name: 'quote',
|
||||
columnType: _i2.ColumnType.json,
|
||||
isNullable: false,
|
||||
dartType: 'protocol:Quote',
|
||||
),
|
||||
_i2.ColumnDefinition(
|
||||
name: 'upvote',
|
||||
columnType: _i2.ColumnType.boolean,
|
||||
isNullable: false,
|
||||
dartType: 'bool',
|
||||
),
|
||||
],
|
||||
foreignKeys: [],
|
||||
indexes: [
|
||||
_i2.IndexDefinition(
|
||||
indexName: 'vote_request_pkey',
|
||||
tableSpace: null,
|
||||
elements: [
|
||||
_i2.IndexElementDefinition(
|
||||
type: _i2.IndexElementDefinitionType.column,
|
||||
definition: 'id',
|
||||
)
|
||||
],
|
||||
type: 'btree',
|
||||
isUnique: true,
|
||||
isPrimary: true,
|
||||
)
|
||||
],
|
||||
managed: true,
|
||||
),
|
||||
..._i3.Protocol.targetTableDefinitions,
|
||||
..._i2.Protocol.targetTableDefinitions,
|
||||
];
|
||||
|
|
@ -134,12 +245,24 @@ class Protocol extends _i1.SerializationManagerServer {
|
|||
if (t == _i5.Quote) {
|
||||
return _i5.Quote.fromJson(data) as T;
|
||||
}
|
||||
if (t == _i6.Vote) {
|
||||
return _i6.Vote.fromJson(data) as T;
|
||||
}
|
||||
if (t == _i7.VoteRequest) {
|
||||
return _i7.VoteRequest.fromJson(data) as T;
|
||||
}
|
||||
if (t == _i1.getType<_i4.CreateQuoteRequest?>()) {
|
||||
return (data != null ? _i4.CreateQuoteRequest.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<_i6.Vote?>()) {
|
||||
return (data != null ? _i6.Vote.fromJson(data) : null) as T;
|
||||
}
|
||||
if (t == _i1.getType<_i7.VoteRequest?>()) {
|
||||
return (data != null ? _i7.VoteRequest.fromJson(data) : null) as T;
|
||||
}
|
||||
if (t == _i1.getType<List<String>?>()) {
|
||||
return (data != null
|
||||
? (data as List).map((e) => deserialize<String>(e)).toList()
|
||||
|
|
@ -150,8 +273,11 @@ class Protocol extends _i1.SerializationManagerServer {
|
|||
? (data as List).map((e) => deserialize<String>(e)).toList()
|
||||
: null) as T;
|
||||
}
|
||||
if (t == List<_i6.Quote>) {
|
||||
return (data as List).map((e) => deserialize<_i6.Quote>(e)).toList() as T;
|
||||
if (t == List<_i8.Quote>) {
|
||||
return (data as List).map((e) => deserialize<_i8.Quote>(e)).toList() as T;
|
||||
}
|
||||
if (t == List<_i9.Vote>) {
|
||||
return (data as List).map((e) => deserialize<_i9.Vote>(e)).toList() as T;
|
||||
}
|
||||
try {
|
||||
return _i3.Protocol().deserialize<T>(data, t);
|
||||
|
|
@ -172,6 +298,12 @@ class Protocol extends _i1.SerializationManagerServer {
|
|||
if (data is _i5.Quote) {
|
||||
return 'Quote';
|
||||
}
|
||||
if (data is _i6.Vote) {
|
||||
return 'Vote';
|
||||
}
|
||||
if (data is _i7.VoteRequest) {
|
||||
return 'VoteRequest';
|
||||
}
|
||||
className = _i2.Protocol().getClassNameForObject(data);
|
||||
if (className != null) {
|
||||
return 'serverpod.$className';
|
||||
|
|
@ -195,6 +327,12 @@ class Protocol extends _i1.SerializationManagerServer {
|
|||
if (dataClassName == 'Quote') {
|
||||
return deserialize<_i5.Quote>(data['data']);
|
||||
}
|
||||
if (dataClassName == 'Vote') {
|
||||
return deserialize<_i6.Vote>(data['data']);
|
||||
}
|
||||
if (dataClassName == 'VoteRequest') {
|
||||
return deserialize<_i7.VoteRequest>(data['data']);
|
||||
}
|
||||
if (dataClassName.startsWith('serverpod.')) {
|
||||
data['className'] = dataClassName.substring(10);
|
||||
return _i2.Protocol().deserializeByClassName(data);
|
||||
|
|
@ -223,6 +361,10 @@ class Protocol extends _i1.SerializationManagerServer {
|
|||
switch (t) {
|
||||
case _i5.Quote:
|
||||
return _i5.Quote.t;
|
||||
case _i6.Vote:
|
||||
return _i6.Vote.t;
|
||||
case _i7.VoteRequest:
|
||||
return _i7.VoteRequest.t;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,3 +2,6 @@ quote:
|
|||
- createQuote:
|
||||
- updateQuote:
|
||||
- getAllQuotes:
|
||||
votes:
|
||||
- postVote:
|
||||
- getAllVotes:
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
// lib/src/endpoints/quote_endpoint.dart
|
||||
import 'dart:async';
|
||||
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';
|
||||
|
||||
class ShowLatestNewsWidget extends Endpoint {
|
||||
class QuoteEndpoint extends Endpoint {
|
||||
static const _channelQuoteUpdates = 'quote-updates';
|
||||
|
||||
Future<Quote> createQuote(Session session, CreateQuoteRequest req) async {
|
||||
|
|
@ -15,8 +15,7 @@ class ShowLatestNewsWidget extends Endpoint {
|
|||
final text = validateQuote(req);
|
||||
|
||||
final toInsert = Quote(
|
||||
id: 0,
|
||||
userId: userId ?? 12,
|
||||
userId: userId ?? Random().nextInt(1200),
|
||||
text: text,
|
||||
authorName: req.authorName,
|
||||
lat: req.lat,
|
||||
|
|
@ -37,8 +36,22 @@ class ShowLatestNewsWidget extends Endpoint {
|
|||
await session.messages.postMessage(_channelQuoteUpdates, quote);
|
||||
}
|
||||
|
||||
Future<List<Quote>> getAllQuotes(Session session, {int limit = 200}) async {
|
||||
final quoteList = await Quote.db.find(session);
|
||||
Future<List<Quote>> getAllQuotes(
|
||||
Session session,
|
||||
) async {
|
||||
session.log('$session');
|
||||
|
||||
final quoteList = await Quote.db.find(
|
||||
session,
|
||||
// where: (t) => t.visibility.equals(0),
|
||||
// orderBy: (t) => t.createdAt,
|
||||
// orderDescending: true,
|
||||
);
|
||||
|
||||
for (var element in quoteList) {
|
||||
session.log(element.text);
|
||||
}
|
||||
|
||||
return quoteList;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,3 +6,4 @@
|
|||
|
||||
20250816095813247
|
||||
20250816122625449
|
||||
20250816171653001
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ import 'dart:async' as _i3;
|
|||
import 'package:wien_talks_server/src/generated/quotes/quote.dart' as _i4;
|
||||
import 'package:wien_talks_server/src/generated/quotes/create_quote.dart'
|
||||
as _i5;
|
||||
import 'package:wien_talks_server/src/generated/votes/vote.dart' as _i6;
|
||||
import 'package:wien_talks_server/src/generated/votes/vote_request.dart' as _i7;
|
||||
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';
|
||||
|
|
@ -121,10 +123,7 @@ class _InternalTestEndpoints extends TestEndpoints
|
|||
}
|
||||
|
||||
class _ShowLatestNewsWidget {
|
||||
_ShowLatestNewsWidget(
|
||||
this._endpointDispatch,
|
||||
this._serializationManager,
|
||||
);
|
||||
_ShowLatestNewsWidget(this._endpointDispatch, this._serializationManager);
|
||||
|
||||
final _i2.EndpointDispatch _endpointDispatch;
|
||||
|
||||
|
|
@ -137,9 +136,9 @@ class _ShowLatestNewsWidget {
|
|||
return _i1.callAwaitableFunctionAndHandleExceptions(() async {
|
||||
var _localUniqueSession =
|
||||
(sessionBuilder as _i1.InternalTestSessionBuilder).internalBuild(
|
||||
endpoint: 'showLatestNewsWidget',
|
||||
method: 'createQuote',
|
||||
);
|
||||
endpoint: 'showLatestNewsWidget',
|
||||
method: 'createQuote',
|
||||
);
|
||||
try {
|
||||
var _localCallContext = await _endpointDispatch.getMethodCallContext(
|
||||
createSessionCallback: (_) => _localUniqueSession,
|
||||
|
|
@ -148,10 +147,12 @@ class _ShowLatestNewsWidget {
|
|||
parameters: _i1.testObjectToJson({'req': req}),
|
||||
serializationManager: _serializationManager,
|
||||
);
|
||||
var _localReturnValue = await (_localCallContext.method.call(
|
||||
_localUniqueSession,
|
||||
_localCallContext.arguments,
|
||||
) as _i3.Future<_i4.Quote>);
|
||||
var _localReturnValue =
|
||||
await (_localCallContext.method.call(
|
||||
_localUniqueSession,
|
||||
_localCallContext.arguments,
|
||||
)
|
||||
as _i3.Future<_i4.Quote>);
|
||||
return _localReturnValue;
|
||||
} finally {
|
||||
await _localUniqueSession.close();
|
||||
|
|
@ -166,9 +167,9 @@ class _ShowLatestNewsWidget {
|
|||
return _i1.callAwaitableFunctionAndHandleExceptions(() async {
|
||||
var _localUniqueSession =
|
||||
(sessionBuilder as _i1.InternalTestSessionBuilder).internalBuild(
|
||||
endpoint: 'showLatestNewsWidget',
|
||||
method: 'updateQuote',
|
||||
);
|
||||
endpoint: 'showLatestNewsWidget',
|
||||
method: 'updateQuote',
|
||||
);
|
||||
try {
|
||||
var _localCallContext = await _endpointDispatch.getMethodCallContext(
|
||||
createSessionCallback: (_) => _localUniqueSession,
|
||||
|
|
@ -177,10 +178,12 @@ class _ShowLatestNewsWidget {
|
|||
parameters: _i1.testObjectToJson({'quote': quote}),
|
||||
serializationManager: _serializationManager,
|
||||
);
|
||||
var _localReturnValue = await (_localCallContext.method.call(
|
||||
_localUniqueSession,
|
||||
_localCallContext.arguments,
|
||||
) as _i3.Future<void>);
|
||||
var _localReturnValue =
|
||||
await (_localCallContext.method.call(
|
||||
_localUniqueSession,
|
||||
_localCallContext.arguments,
|
||||
)
|
||||
as _i3.Future<void>);
|
||||
return _localReturnValue;
|
||||
} finally {
|
||||
await _localUniqueSession.close();
|
||||
|
|
@ -195,9 +198,9 @@ class _ShowLatestNewsWidget {
|
|||
return _i1.callAwaitableFunctionAndHandleExceptions(() async {
|
||||
var _localUniqueSession =
|
||||
(sessionBuilder as _i1.InternalTestSessionBuilder).internalBuild(
|
||||
endpoint: 'showLatestNewsWidget',
|
||||
method: 'getAllQuotes',
|
||||
);
|
||||
endpoint: 'showLatestNewsWidget',
|
||||
method: 'getAllQuotes',
|
||||
);
|
||||
try {
|
||||
var _localCallContext = await _endpointDispatch.getMethodCallContext(
|
||||
createSessionCallback: (_) => _localUniqueSession,
|
||||
|
|
@ -206,10 +209,12 @@ class _ShowLatestNewsWidget {
|
|||
parameters: _i1.testObjectToJson({'limit': limit}),
|
||||
serializationManager: _serializationManager,
|
||||
);
|
||||
var _localReturnValue = await (_localCallContext.method.call(
|
||||
_localUniqueSession,
|
||||
_localCallContext.arguments,
|
||||
) as _i3.Future<List<_i4.Quote>>);
|
||||
var _localReturnValue =
|
||||
await (_localCallContext.method.call(
|
||||
_localUniqueSession,
|
||||
_localCallContext.arguments,
|
||||
)
|
||||
as _i3.Future<List<_i6.Vote>>);
|
||||
return _localReturnValue;
|
||||
} finally {
|
||||
await _localUniqueSession.close();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue