Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated sponsors #5

Merged
merged 6 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/app.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:method_conf_app/providers/conference_provider.dart';
import 'package:method_conf_app/providers/sponsor_provider_v2.dart';
import 'package:provider/provider.dart';

import 'package:method_conf_app/providers/session_provider.dart';
Expand All @@ -14,12 +16,17 @@ class App extends StatelessWidget {
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => ConferenceProvider()),
ChangeNotifierProvider(create: (context) => SpeakerProvider()),
ChangeNotifierProvider(create: (context) {
var s = Provider.of<SpeakerProvider>(context, listen: false);
return SessionProvider(speakerProvider: s);
}),
ChangeNotifierProvider(create: (context) => SponsorProvider()),
ChangeNotifierProvider(create: (context) {
var c = Provider.of<ConferenceProvider>(context, listen: false);
return SponsorProviderV2(conferenceProvider: c);
})
],
child: MaterialApp(
debugShowCheckedModeBanner: false,
Expand Down
27 changes: 27 additions & 0 deletions lib/data/get_default_conference.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:method_conf_app/data/umbraco/get_items.dart';
import 'package:method_conf_app/data/umbraco/models/conference.dart';

Future<Conference?> getDefaultConference() async {
var response = await getItems(filter: ['contentType:conference']);

Conference? latestConference;

for (final conference in response.items) {
if (conference is! Conference) {
continue;
}

final date = conference.properties?.date;

if (date == null) {
continue;
}

if (latestConference == null ||
(latestConference.properties?.date?.isBefore(date) ?? true)) {
latestConference = conference;
}
}

return latestConference;
}
25 changes: 25 additions & 0 deletions lib/data/umbraco/get_child_nodes_of_type.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:method_conf_app/data/umbraco/get_items.dart';
import 'package:method_conf_app/data/umbraco/models/api_content_response_model_base.dart';

Future<List<ApiContentResponseModelBase>> getChildNodesOfType({
required String nodeId,
required String type,
int take = 10,
}) async {
var res = await getItems(
filter: ['contentType:$type'],
fetch: 'descendants:$nodeId',
take: take,
);

return res.items;
}

Future<ApiContentResponseModelBase> getFirstChildNodeOfType({
required String nodeId,
required String type,
}) async {
var items = await getChildNodesOfType(nodeId: nodeId, type: type);

return items.first;
}
30 changes: 30 additions & 0 deletions lib/data/umbraco/get_items.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:method_conf_app/data/umbraco/models/paged_api_content_response_model.dart';

import 'package:method_conf_app/env.dart';

Future<PagedApiContentResponseModel> getItems(
{List<String> filter = const [], String? fetch, int? take}) async {
var url = Uri.parse('${Env.umbracoBaseUrl}/umbraco/delivery/api/v2/content');

if (filter.isNotEmpty) {
url = url
.replace(queryParameters: {...url.queryParameters, 'filter': filter});
}

if (fetch != null) {
url =
url.replace(queryParameters: {...url.queryParameters, 'fetch': fetch});
}

if (take != null) {
url = url.replace(
queryParameters: {...url.queryParameters, 'take': take.toString()});
}

var res = await http.get(url);

return PagedApiContentResponseModel.fromJson(json.decode(res.body));
}
16 changes: 16 additions & 0 deletions lib/data/umbraco/image_url.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:method_conf_app/env.dart';

String imageUrl(String url, {int? width, int? height}) {
var parsedUrl = Uri.parse(Env.umbracoBaseUrl).replace(path: url);

if (width != null) {
parsedUrl = parsedUrl.replace(queryParameters: {'width': width.toString()});
}

if (height != null) {
parsedUrl =
parsedUrl.replace(queryParameters: {'height': height.toString()});
}

return parsedUrl.toString();
}
59 changes: 59 additions & 0 deletions lib/data/umbraco/models/api_block_list_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:method_conf_app/data/umbraco/models/sponsor.dart';
import 'package:method_conf_app/data/umbraco/models/sponsor_tier.dart';

part 'api_block_list_model.g.dart';

@JsonSerializable()
class ApiBlockListModel {
List<ApiBlockItemModel> items;

ApiBlockListModel({this.items = const []});

factory ApiBlockListModel.fromJson(Map<String, dynamic> json) =>
_$ApiBlockListModelFromJson(json);

Map<String, dynamic> toJson() => _$ApiBlockListModelToJson(this);
}

@JsonSerializable()
class ApiBlockItemModel {
ApiElementModel content;
ApiElementModel? settings;

ApiBlockItemModel({required this.content, this.settings});

factory ApiBlockItemModel.fromJson(Map<String, dynamic> json) =>
_$ApiBlockItemModelFromJson(json);

Map<String, dynamic> toJson() => _$ApiBlockItemModelToJson(this);
}

@JsonSerializable()
class ApiElementModel {
String id;
String contentType;
@JsonKey(includeFromJson: false, includeToJson: false)
Map<String, dynamic>? unParsedProperties;

ApiElementModel({
required this.id,
required this.contentType,
this.unParsedProperties,
});

factory ApiElementModel.fromJson(Map<String, dynamic> json) =>
switch (json['contentType'] as String) {
'sponsorTier' => SponsorTier.fromJson(json),
'sponsor' => Sponsor.fromJson(json),
_ => _fromJson(json),
};

static ApiElementModel _fromJson(Map<String, dynamic> json) {
var obj = _$ApiElementModelFromJson(json);
obj.unParsedProperties = json['properties'] as Map<String, dynamic>?;
return obj;
}

Map<String, dynamic> toJson() => _$ApiElementModelToJson(this);
}
75 changes: 75 additions & 0 deletions lib/data/umbraco/models/api_content_response_model_base.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:method_conf_app/data/umbraco/models/conference.dart';
import 'package:method_conf_app/data/umbraco/models/sponsors.dart';

part 'api_content_response_model_base.g.dart';

@JsonSerializable()
class ApiContentResponseModelBase {
String contentType;
String name;
DateTime createDate;
DateTime updateDate;
ApiContentRouteModel route;
String id;
Map<String, ApiContentRouteModel> cultures;
@JsonKey(includeFromJson: false, includeToJson: false)
Map<String, dynamic>? unParsedProperties;

ApiContentResponseModelBase(
{required this.contentType,
required this.name,
required this.createDate,
required this.updateDate,
required this.route,
required this.id,
required this.cultures,
this.unParsedProperties});

factory ApiContentResponseModelBase.fromJson(Map<String, dynamic> json) =>
switch (json['contentType'] as String) {
'conference' => Conference.fromJson(json),
'sponsors' => Sponsors.fromJson(json),
_ => _fromJson(json),
};

static ApiContentResponseModelBase _fromJson(Map<String, dynamic> json) {
var obj = _$ApiContentResponseModelBaseFromJson(json);
obj.unParsedProperties = json['properties'] as Map<String, dynamic>?;
return obj;
}

Map<String, dynamic> toJson() => _$ApiContentResponseModelBaseToJson(this);
}

@JsonSerializable()
class ApiContentRouteModel {
String path;
ApiContentStartItemModel startItem;

ApiContentRouteModel({
required this.path,
required this.startItem,
});

factory ApiContentRouteModel.fromJson(Map<String, dynamic> json) =>
_$ApiContentRouteModelFromJson(json);

Map<String, dynamic> toJson() => _$ApiContentRouteModelToJson(this);
}

@JsonSerializable()
class ApiContentStartItemModel {
String id;
String path;

ApiContentStartItemModel({
required this.id,
required this.path,
});

factory ApiContentStartItemModel.fromJson(Map<String, dynamic> json) =>
_$ApiContentStartItemModelFromJson(json);

Map<String, dynamic> toJson() => _$ApiContentStartItemModelToJson(this);
}
33 changes: 33 additions & 0 deletions lib/data/umbraco/models/api_media_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import 'package:json_annotation/json_annotation.dart';

part 'api_media_model.g.dart';

@JsonSerializable()
class ApiMediaModel {
String id;
String name;
String mediaType;
String url;
String? extension;
int? width;
int? height;
int? bytes;
Map<String, dynamic> properties;

ApiMediaModel({
required this.id,
required this.name,
required this.mediaType,
required this.url,
required this.extension,
required this.width,
required this.height,
required this.bytes,
required this.properties,
});

factory ApiMediaModel.fromJson(Map<String, dynamic> json) =>
_$ApiMediaModelFromJson(json);

Map<String, dynamic> toJson() => _$ApiMediaModelToJson(this);
}
51 changes: 51 additions & 0 deletions lib/data/umbraco/models/conference.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:method_conf_app/utils/cst_utils.dart';

import 'package:method_conf_app/data/umbraco/models/api_content_response_model_base.dart';

part 'conference.g.dart';

@JsonSerializable()
class Conference extends ApiContentResponseModelBase {
ConferenceProperties? properties;

Conference({
required super.contentType,
required super.name,
required super.createDate,
required super.updateDate,
required super.route,
required super.id,
required super.cultures,
required this.properties,
});

factory Conference.fromJson(Map<String, dynamic> json) =>
_$ConferenceFromJson(json);

@override
Map<String, dynamic> toJson() => _$ConferenceToJson(this);
}

@JsonSerializable()
class ConferenceProperties {
@JsonKey(fromJson: utcStringToCst, toJson: cstToUtcString)
DateTime? date;
String? registerUrl;
String? callForSpeakersUrl;
String? tagline;
String? location;

ConferenceProperties({
required this.date,
required this.registerUrl,
required this.callForSpeakersUrl,
required this.tagline,
required this.location,
});

factory ConferenceProperties.fromJson(Map<String, dynamic> json) =>
_$ConferencePropertiesFromJson(json);

Map<String, dynamic> toJson() => _$ConferencePropertiesToJson(this);
}
21 changes: 21 additions & 0 deletions lib/data/umbraco/models/paged_api_content_response_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:json_annotation/json_annotation.dart';

import 'api_content_response_model_base.dart';

part 'paged_api_content_response_model.g.dart';

@JsonSerializable()
class PagedApiContentResponseModel {
int total;
List<ApiContentResponseModelBase> items;

PagedApiContentResponseModel({
required this.total,
required this.items,
});

factory PagedApiContentResponseModel.fromJson(Map<String, dynamic> json) =>
_$PagedApiContentResponseModelFromJson(json);

Map<String, dynamic> toJson() => _$PagedApiContentResponseModelToJson(this);
}
Loading