introduce quote models

This commit is contained in:
tk 2025-08-16 13:08:10 +02:00
parent 6fd404fc88
commit 6e78ac2665
13 changed files with 862 additions and 2 deletions

View file

@ -32,6 +32,21 @@ class EndpointGreeting extends _i1.EndpointRef {
); );
} }
/// {@category Endpoint}
class EndpointRecipe extends _i1.EndpointRef {
EndpointRecipe(_i1.EndpointCaller caller) : super(caller);
@override
String get name => 'recipe';
_i2.Future<String> postQuote(String quote) =>
caller.callServerEndpoint<String>(
'recipe',
'postQuote',
{'quote': quote},
);
}
class Client extends _i1.ServerpodClientShared { class Client extends _i1.ServerpodClientShared {
Client( Client(
String host, { String host, {
@ -59,12 +74,18 @@ class Client extends _i1.ServerpodClientShared {
disconnectStreamsOnLostInternetConnection, disconnectStreamsOnLostInternetConnection,
) { ) {
greeting = EndpointGreeting(this); greeting = EndpointGreeting(this);
recipe = EndpointRecipe(this);
} }
late final EndpointGreeting greeting; late final EndpointGreeting greeting;
late final EndpointRecipe recipe;
@override @override
Map<String, _i1.EndpointRef> get endpointRefLookup => {'greeting': greeting}; Map<String, _i1.EndpointRef> get endpointRefLookup => {
'greeting': greeting,
'recipe': recipe,
};
@override @override
Map<String, _i1.ModuleEndpointCaller> get moduleLookup => {}; Map<String, _i1.ModuleEndpointCaller> get moduleLookup => {};

View file

@ -11,7 +11,11 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes // ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:serverpod_client/serverpod_client.dart' as _i1; import 'package:serverpod_client/serverpod_client.dart' as _i1;
import 'greeting.dart' as _i2; import 'greeting.dart' as _i2;
import 'quotes/create_quote.dart' as _i3;
import 'quotes/quote.dart' as _i4;
export 'greeting.dart'; export 'greeting.dart';
export 'quotes/create_quote.dart';
export 'quotes/quote.dart';
export 'client.dart'; export 'client.dart';
class Protocol extends _i1.SerializationManager { class Protocol extends _i1.SerializationManager {
@ -30,9 +34,31 @@ class Protocol extends _i1.SerializationManager {
if (t == _i2.Greeting) { if (t == _i2.Greeting) {
return _i2.Greeting.fromJson(data) as T; return _i2.Greeting.fromJson(data) as T;
} }
if (t == _i3.CreateQuoteRequest) {
return _i3.CreateQuoteRequest.fromJson(data) as T;
}
if (t == _i4.Quote) {
return _i4.Quote.fromJson(data) as T;
}
if (t == _i1.getType<_i2.Greeting?>()) { if (t == _i1.getType<_i2.Greeting?>()) {
return (data != null ? _i2.Greeting.fromJson(data) : null) as T; 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<List<String>?>()) {
return (data != null
? (data as List).map((e) => deserialize<String>(e)).toList()
: null) as T;
}
if (t == _i1.getType<List<String>?>()) {
return (data != null
? (data as List).map((e) => deserialize<String>(e)).toList()
: null) as T;
}
return super.deserialize<T>(data, t); return super.deserialize<T>(data, t);
} }
@ -43,6 +69,12 @@ class Protocol extends _i1.SerializationManager {
if (data is _i2.Greeting) { if (data is _i2.Greeting) {
return 'Greeting'; return 'Greeting';
} }
if (data is _i3.CreateQuoteRequest) {
return 'CreateQuoteRequest';
}
if (data is _i4.Quote) {
return 'Quote';
}
return null; return null;
} }
@ -55,6 +87,12 @@ class Protocol extends _i1.SerializationManager {
if (dataClassName == 'Greeting') { if (dataClassName == 'Greeting') {
return deserialize<_i2.Greeting>(data['data']); return deserialize<_i2.Greeting>(data['data']);
} }
if (dataClassName == 'CreateQuoteRequest') {
return deserialize<_i3.CreateQuoteRequest>(data['data']);
}
if (dataClassName == 'Quote') {
return deserialize<_i4.Quote>(data['data']);
}
return super.deserializeByClassName(data); return super.deserializeByClassName(data);
} }
} }

View file

@ -0,0 +1,116 @@
/* 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;
abstract class CreateQuoteRequest implements _i1.SerializableModel {
CreateQuoteRequest._({
required this.text,
this.authorName,
required this.lat,
required this.lng,
this.tags,
});
factory CreateQuoteRequest({
required String text,
String? authorName,
required double lat,
required double lng,
List<String>? tags,
}) = _CreateQuoteRequestImpl;
factory CreateQuoteRequest.fromJson(Map<String, dynamic> jsonSerialization) {
return CreateQuoteRequest(
text: jsonSerialization['text'] as String,
authorName: jsonSerialization['authorName'] as String?,
lat: (jsonSerialization['lat'] as num).toDouble(),
lng: (jsonSerialization['lng'] as num).toDouble(),
tags: (jsonSerialization['tags'] as List?)
?.map((e) => e as String)
.toList(),
);
}
String text;
String? authorName;
double lat;
double lng;
List<String>? tags;
/// Returns a shallow copy of this [CreateQuoteRequest]
/// with some or all fields replaced by the given arguments.
@_i1.useResult
CreateQuoteRequest copyWith({
String? text,
String? authorName,
double? lat,
double? lng,
List<String>? tags,
});
@override
Map<String, dynamic> toJson() {
return {
'text': text,
if (authorName != null) 'authorName': authorName,
'lat': lat,
'lng': lng,
if (tags != null) 'tags': tags?.toJson(),
};
}
@override
String toString() {
return _i1.SerializationManager.encode(this);
}
}
class _Undefined {}
class _CreateQuoteRequestImpl extends CreateQuoteRequest {
_CreateQuoteRequestImpl({
required String text,
String? authorName,
required double lat,
required double lng,
List<String>? tags,
}) : super._(
text: text,
authorName: authorName,
lat: lat,
lng: lng,
tags: tags,
);
/// Returns a shallow copy of this [CreateQuoteRequest]
/// with some or all fields replaced by the given arguments.
@_i1.useResult
@override
CreateQuoteRequest copyWith({
String? text,
Object? authorName = _Undefined,
double? lat,
double? lng,
Object? tags = _Undefined,
}) {
return CreateQuoteRequest(
text: text ?? this.text,
authorName: authorName is String? ? authorName : this.authorName,
lat: lat ?? this.lat,
lng: lng ?? this.lng,
tags: tags is List<String>? ? tags : this.tags?.map((e0) => e0).toList(),
);
}
}

View file

@ -0,0 +1,194 @@
/* 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;
abstract class Quote implements _i1.SerializableModel {
Quote._({
required this.id,
required this.userId,
required this.text,
this.authorName,
required this.lat,
required this.lng,
required this.geohash,
required this.createdAt,
required this.visibility,
required this.upvotes,
required this.downvotes,
this.tags,
});
factory Quote({
required int id,
required int userId,
required String text,
String? authorName,
required double lat,
required double lng,
required String geohash,
required DateTime createdAt,
required int visibility,
required int upvotes,
required int downvotes,
List<String>? tags,
}) = _QuoteImpl;
factory Quote.fromJson(Map<String, dynamic> jsonSerialization) {
return Quote(
id: jsonSerialization['id'] as int,
userId: jsonSerialization['userId'] as int,
text: jsonSerialization['text'] as String,
authorName: jsonSerialization['authorName'] as String?,
lat: (jsonSerialization['lat'] as num).toDouble(),
lng: (jsonSerialization['lng'] as num).toDouble(),
geohash: jsonSerialization['geohash'] as String,
createdAt:
_i1.DateTimeJsonExtension.fromJson(jsonSerialization['createdAt']),
visibility: jsonSerialization['visibility'] as int,
upvotes: jsonSerialization['upvotes'] as int,
downvotes: jsonSerialization['downvotes'] as int,
tags: (jsonSerialization['tags'] as List?)
?.map((e) => e as String)
.toList(),
);
}
int id;
int userId;
String text;
String? authorName;
double lat;
double lng;
String geohash;
DateTime createdAt;
int visibility;
int upvotes;
int downvotes;
List<String>? tags;
/// Returns a shallow copy of this [Quote]
/// with some or all fields replaced by the given arguments.
@_i1.useResult
Quote copyWith({
int? id,
int? userId,
String? text,
String? authorName,
double? lat,
double? lng,
String? geohash,
DateTime? createdAt,
int? visibility,
int? upvotes,
int? downvotes,
List<String>? tags,
});
@override
Map<String, dynamic> toJson() {
return {
'id': id,
'userId': userId,
'text': text,
if (authorName != null) 'authorName': authorName,
'lat': lat,
'lng': lng,
'geohash': geohash,
'createdAt': createdAt.toJson(),
'visibility': visibility,
'upvotes': upvotes,
'downvotes': downvotes,
if (tags != null) 'tags': tags?.toJson(),
};
}
@override
String toString() {
return _i1.SerializationManager.encode(this);
}
}
class _Undefined {}
class _QuoteImpl extends Quote {
_QuoteImpl({
required int id,
required int userId,
required String text,
String? authorName,
required double lat,
required double lng,
required String geohash,
required DateTime createdAt,
required int visibility,
required int upvotes,
required int downvotes,
List<String>? tags,
}) : super._(
id: id,
userId: userId,
text: text,
authorName: authorName,
lat: lat,
lng: lng,
geohash: geohash,
createdAt: createdAt,
visibility: visibility,
upvotes: upvotes,
downvotes: downvotes,
tags: tags,
);
/// Returns a shallow copy of this [Quote]
/// with some or all fields replaced by the given arguments.
@_i1.useResult
@override
Quote copyWith({
int? id,
int? userId,
String? text,
Object? authorName = _Undefined,
double? lat,
double? lng,
String? geohash,
DateTime? createdAt,
int? visibility,
int? upvotes,
int? downvotes,
Object? tags = _Undefined,
}) {
return Quote(
id: id ?? this.id,
userId: userId ?? this.userId,
text: text ?? this.text,
authorName: authorName is String? ? authorName : this.authorName,
lat: lat ?? this.lat,
lng: lng ?? this.lng,
geohash: geohash ?? this.geohash,
createdAt: createdAt ?? this.createdAt,
visibility: visibility ?? this.visibility,
upvotes: upvotes ?? this.upvotes,
downvotes: downvotes ?? this.downvotes,
tags: tags is List<String>? ? tags : this.tags?.map((e0) => e0).toList(),
);
}
}

View file

@ -11,6 +11,7 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes // ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:serverpod/serverpod.dart' as _i1; import 'package:serverpod/serverpod.dart' as _i1;
import '../greeting_endpoint.dart' as _i2; import '../greeting_endpoint.dart' as _i2;
import '../quotes/location_endpoint.dart' as _i3;
class Endpoints extends _i1.EndpointDispatch { class Endpoints extends _i1.EndpointDispatch {
@override @override
@ -21,7 +22,13 @@ class Endpoints extends _i1.EndpointDispatch {
server, server,
'greeting', 'greeting',
null, null,
) ),
'recipe': _i3.RecipeEndpoint()
..initialize(
server,
'recipe',
null,
),
}; };
connectors['greeting'] = _i1.EndpointConnector( connectors['greeting'] = _i1.EndpointConnector(
name: 'greeting', name: 'greeting',
@ -47,5 +54,29 @@ class Endpoints extends _i1.EndpointDispatch {
) )
}, },
); );
connectors['recipe'] = _i1.EndpointConnector(
name: 'recipe',
endpoint: endpoints['recipe']!,
methodConnectors: {
'postQuote': _i1.MethodConnector(
name: 'postQuote',
params: {
'quote': _i1.ParameterDescription(
name: 'quote',
type: _i1.getType<String>(),
nullable: false,
)
},
call: (
_i1.Session session,
Map<String, dynamic> params,
) async =>
(endpoints['recipe'] as _i3.RecipeEndpoint).postQuote(
session,
params['quote'],
),
)
},
);
} }
} }

View file

@ -12,7 +12,11 @@
import 'package:serverpod/serverpod.dart' as _i1; import 'package:serverpod/serverpod.dart' as _i1;
import 'package:serverpod/protocol.dart' as _i2; import 'package:serverpod/protocol.dart' as _i2;
import 'greeting.dart' as _i3; import 'greeting.dart' as _i3;
import 'quotes/create_quote.dart' as _i4;
import 'quotes/quote.dart' as _i5;
export 'greeting.dart'; export 'greeting.dart';
export 'quotes/create_quote.dart';
export 'quotes/quote.dart';
class Protocol extends _i1.SerializationManagerServer { class Protocol extends _i1.SerializationManagerServer {
Protocol._(); Protocol._();
@ -34,9 +38,31 @@ class Protocol extends _i1.SerializationManagerServer {
if (t == _i3.Greeting) { if (t == _i3.Greeting) {
return _i3.Greeting.fromJson(data) as T; return _i3.Greeting.fromJson(data) as T;
} }
if (t == _i4.CreateQuoteRequest) {
return _i4.CreateQuoteRequest.fromJson(data) as T;
}
if (t == _i5.Quote) {
return _i5.Quote.fromJson(data) as T;
}
if (t == _i1.getType<_i3.Greeting?>()) { if (t == _i1.getType<_i3.Greeting?>()) {
return (data != null ? _i3.Greeting.fromJson(data) : null) as T; return (data != null ? _i3.Greeting.fromJson(data) : null) 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<List<String>?>()) {
return (data != null
? (data as List).map((e) => deserialize<String>(e)).toList()
: null) as T;
}
if (t == _i1.getType<List<String>?>()) {
return (data != null
? (data as List).map((e) => deserialize<String>(e)).toList()
: null) as T;
}
try { try {
return _i2.Protocol().deserialize<T>(data, t); return _i2.Protocol().deserialize<T>(data, t);
} on _i1.DeserializationTypeNotFoundException catch (_) {} } on _i1.DeserializationTypeNotFoundException catch (_) {}
@ -50,6 +76,12 @@ class Protocol extends _i1.SerializationManagerServer {
if (data is _i3.Greeting) { if (data is _i3.Greeting) {
return 'Greeting'; return 'Greeting';
} }
if (data is _i4.CreateQuoteRequest) {
return 'CreateQuoteRequest';
}
if (data is _i5.Quote) {
return 'Quote';
}
className = _i2.Protocol().getClassNameForObject(data); className = _i2.Protocol().getClassNameForObject(data);
if (className != null) { if (className != null) {
return 'serverpod.$className'; return 'serverpod.$className';
@ -66,6 +98,12 @@ class Protocol extends _i1.SerializationManagerServer {
if (dataClassName == 'Greeting') { if (dataClassName == 'Greeting') {
return deserialize<_i3.Greeting>(data['data']); return deserialize<_i3.Greeting>(data['data']);
} }
if (dataClassName == 'CreateQuoteRequest') {
return deserialize<_i4.CreateQuoteRequest>(data['data']);
}
if (dataClassName == 'Quote') {
return deserialize<_i5.Quote>(data['data']);
}
if (dataClassName.startsWith('serverpod.')) { if (dataClassName.startsWith('serverpod.')) {
data['className'] = dataClassName.substring(10); data['className'] = dataClassName.substring(10);
return _i2.Protocol().deserializeByClassName(data); return _i2.Protocol().deserializeByClassName(data);

View file

@ -1,2 +1,4 @@
greeting: greeting:
- hello: - hello:
recipe:
- postQuote:

View file

@ -0,0 +1,128 @@
/* 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;
abstract class CreateQuoteRequest
implements _i1.SerializableModel, _i1.ProtocolSerialization {
CreateQuoteRequest._({
required this.text,
this.authorName,
required this.lat,
required this.lng,
this.tags,
});
factory CreateQuoteRequest({
required String text,
String? authorName,
required double lat,
required double lng,
List<String>? tags,
}) = _CreateQuoteRequestImpl;
factory CreateQuoteRequest.fromJson(Map<String, dynamic> jsonSerialization) {
return CreateQuoteRequest(
text: jsonSerialization['text'] as String,
authorName: jsonSerialization['authorName'] as String?,
lat: (jsonSerialization['lat'] as num).toDouble(),
lng: (jsonSerialization['lng'] as num).toDouble(),
tags: (jsonSerialization['tags'] as List?)
?.map((e) => e as String)
.toList(),
);
}
String text;
String? authorName;
double lat;
double lng;
List<String>? tags;
/// Returns a shallow copy of this [CreateQuoteRequest]
/// with some or all fields replaced by the given arguments.
@_i1.useResult
CreateQuoteRequest copyWith({
String? text,
String? authorName,
double? lat,
double? lng,
List<String>? tags,
});
@override
Map<String, dynamic> toJson() {
return {
'text': text,
if (authorName != null) 'authorName': authorName,
'lat': lat,
'lng': lng,
if (tags != null) 'tags': tags?.toJson(),
};
}
@override
Map<String, dynamic> toJsonForProtocol() {
return {
'text': text,
if (authorName != null) 'authorName': authorName,
'lat': lat,
'lng': lng,
if (tags != null) 'tags': tags?.toJson(),
};
}
@override
String toString() {
return _i1.SerializationManager.encode(this);
}
}
class _Undefined {}
class _CreateQuoteRequestImpl extends CreateQuoteRequest {
_CreateQuoteRequestImpl({
required String text,
String? authorName,
required double lat,
required double lng,
List<String>? tags,
}) : super._(
text: text,
authorName: authorName,
lat: lat,
lng: lng,
tags: tags,
);
/// Returns a shallow copy of this [CreateQuoteRequest]
/// with some or all fields replaced by the given arguments.
@_i1.useResult
@override
CreateQuoteRequest copyWith({
String? text,
Object? authorName = _Undefined,
double? lat,
double? lng,
Object? tags = _Undefined,
}) {
return CreateQuoteRequest(
text: text ?? this.text,
authorName: authorName is String? ? authorName : this.authorName,
lat: lat ?? this.lat,
lng: lng ?? this.lng,
tags: tags is List<String>? ? tags : this.tags?.map((e0) => e0).toList(),
);
}
}

View file

@ -0,0 +1,213 @@
/* 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;
abstract class Quote
implements _i1.SerializableModel, _i1.ProtocolSerialization {
Quote._({
required this.id,
required this.userId,
required this.text,
this.authorName,
required this.lat,
required this.lng,
required this.geohash,
required this.createdAt,
required this.visibility,
required this.upvotes,
required this.downvotes,
this.tags,
});
factory Quote({
required int id,
required int userId,
required String text,
String? authorName,
required double lat,
required double lng,
required String geohash,
required DateTime createdAt,
required int visibility,
required int upvotes,
required int downvotes,
List<String>? tags,
}) = _QuoteImpl;
factory Quote.fromJson(Map<String, dynamic> jsonSerialization) {
return Quote(
id: jsonSerialization['id'] as int,
userId: jsonSerialization['userId'] as int,
text: jsonSerialization['text'] as String,
authorName: jsonSerialization['authorName'] as String?,
lat: (jsonSerialization['lat'] as num).toDouble(),
lng: (jsonSerialization['lng'] as num).toDouble(),
geohash: jsonSerialization['geohash'] as String,
createdAt:
_i1.DateTimeJsonExtension.fromJson(jsonSerialization['createdAt']),
visibility: jsonSerialization['visibility'] as int,
upvotes: jsonSerialization['upvotes'] as int,
downvotes: jsonSerialization['downvotes'] as int,
tags: (jsonSerialization['tags'] as List?)
?.map((e) => e as String)
.toList(),
);
}
int id;
int userId;
String text;
String? authorName;
double lat;
double lng;
String geohash;
DateTime createdAt;
int visibility;
int upvotes;
int downvotes;
List<String>? tags;
/// Returns a shallow copy of this [Quote]
/// with some or all fields replaced by the given arguments.
@_i1.useResult
Quote copyWith({
int? id,
int? userId,
String? text,
String? authorName,
double? lat,
double? lng,
String? geohash,
DateTime? createdAt,
int? visibility,
int? upvotes,
int? downvotes,
List<String>? tags,
});
@override
Map<String, dynamic> toJson() {
return {
'id': id,
'userId': userId,
'text': text,
if (authorName != null) 'authorName': authorName,
'lat': lat,
'lng': lng,
'geohash': geohash,
'createdAt': createdAt.toJson(),
'visibility': visibility,
'upvotes': upvotes,
'downvotes': downvotes,
if (tags != null) 'tags': tags?.toJson(),
};
}
@override
Map<String, dynamic> toJsonForProtocol() {
return {
'id': id,
'userId': userId,
'text': text,
if (authorName != null) 'authorName': authorName,
'lat': lat,
'lng': lng,
'geohash': geohash,
'createdAt': createdAt.toJson(),
'visibility': visibility,
'upvotes': upvotes,
'downvotes': downvotes,
if (tags != null) 'tags': tags?.toJson(),
};
}
@override
String toString() {
return _i1.SerializationManager.encode(this);
}
}
class _Undefined {}
class _QuoteImpl extends Quote {
_QuoteImpl({
required int id,
required int userId,
required String text,
String? authorName,
required double lat,
required double lng,
required String geohash,
required DateTime createdAt,
required int visibility,
required int upvotes,
required int downvotes,
List<String>? tags,
}) : super._(
id: id,
userId: userId,
text: text,
authorName: authorName,
lat: lat,
lng: lng,
geohash: geohash,
createdAt: createdAt,
visibility: visibility,
upvotes: upvotes,
downvotes: downvotes,
tags: tags,
);
/// Returns a shallow copy of this [Quote]
/// with some or all fields replaced by the given arguments.
@_i1.useResult
@override
Quote copyWith({
int? id,
int? userId,
String? text,
Object? authorName = _Undefined,
double? lat,
double? lng,
String? geohash,
DateTime? createdAt,
int? visibility,
int? upvotes,
int? downvotes,
Object? tags = _Undefined,
}) {
return Quote(
id: id ?? this.id,
userId: userId ?? this.userId,
text: text ?? this.text,
authorName: authorName is String? ? authorName : this.authorName,
lat: lat ?? this.lat,
lng: lng ?? this.lng,
geohash: geohash ?? this.geohash,
createdAt: createdAt ?? this.createdAt,
visibility: visibility ?? this.visibility,
upvotes: upvotes ?? this.upvotes,
downvotes: downvotes ?? this.downvotes,
tags: tags is List<String>? ? tags : this.tags?.map((e0) => e0).toList(),
);
}
}

View file

@ -0,0 +1,7 @@
class: CreateQuoteRequest
fields:
text: String
authorName: String?
lat: double
lng: double
tags: List<String>?

View file

@ -0,0 +1,12 @@
import 'dart:async';
import 'package:serverpod/serverpod.dart';
class RecipeEndpoint extends Endpoint {
Future<String> postQuote(Session session, String quote) async {
// validate content
// persist quote
return Future.value('none');
}
}

View file

@ -0,0 +1,14 @@
class: Quote
fields:
id: int
userId: int
text: String
authorName: String?
lat: double
lng: double
geohash: String
createdAt: DateTime
visibility: int
upvotes: int
downvotes: int
tags: List<String>?

View file

@ -102,6 +102,8 @@ void withServerpod(
class TestEndpoints { class TestEndpoints {
late final _GreetingEndpoint greeting; late final _GreetingEndpoint greeting;
late final _RecipeEndpoint recipe;
} }
class _InternalTestEndpoints extends TestEndpoints class _InternalTestEndpoints extends TestEndpoints
@ -115,6 +117,10 @@ class _InternalTestEndpoints extends TestEndpoints
endpoints, endpoints,
serializationManager, serializationManager,
); );
recipe = _RecipeEndpoint(
endpoints,
serializationManager,
);
} }
} }
@ -157,3 +163,43 @@ class _GreetingEndpoint {
}); });
} }
} }
class _RecipeEndpoint {
_RecipeEndpoint(
this._endpointDispatch,
this._serializationManager,
);
final _i2.EndpointDispatch _endpointDispatch;
final _i2.SerializationManager _serializationManager;
_i3.Future<String> postQuote(
_i1.TestSessionBuilder sessionBuilder,
String quote,
) async {
return _i1.callAwaitableFunctionAndHandleExceptions(() async {
var _localUniqueSession =
(sessionBuilder as _i1.InternalTestSessionBuilder).internalBuild(
endpoint: 'recipe',
method: 'postQuote',
);
try {
var _localCallContext = await _endpointDispatch.getMethodCallContext(
createSessionCallback: (_) => _localUniqueSession,
endpointPath: 'recipe',
methodName: 'postQuote',
parameters: _i1.testObjectToJson({'quote': quote}),
serializationManager: _serializationManager,
);
var _localReturnValue = await (_localCallContext.method.call(
_localUniqueSession,
_localCallContext.arguments,
) as _i3.Future<String>);
return _localReturnValue;
} finally {
await _localUniqueSession.close();
}
});
}
}