feat(profile): Описание профиля (статус)

This commit is contained in:
Alex
2024-12-02 17:24:09 +03:00
parent 92a3a60636
commit 66f6f0ed91
4 changed files with 63 additions and 12 deletions

View File

@@ -18,11 +18,13 @@ class ProfileCubit extends Cubit<ProfileState> {
getProfileBySlug(String slug) async {
try {
emit(ProfileState.loaded(
profile: await profileRepository.getProfileBySlug(slug),
profileDetails: await profileRepository.getMyProfileDetails(),
blogPosts: await profileRepository.getBlogPostsByAuthorSlug(slug: slug),
),);
emit(
ProfileState.loaded(
profile: await profileRepository.getProfileBySlug(slug),
profileDetails: await profileRepository.getProfileDetailsBySlug(slug),
blogPosts: await profileRepository.getBlogPostsByAuthorSlug(slug: slug),
),
);
} catch (e) {
emit(ProfileState.error(errorMessage: e.toString()));
}
@@ -34,13 +36,15 @@ class ProfileCubit extends Cubit<ProfileState> {
_currentPeriod = period;
try {
final profile = await profileRepository.getMyProfile();
emit(ProfileState.loaded(
profile: profile,
profileDetails: await profileRepository.getMyProfileDetails(),
blogPosts: await profileRepository.getBlogPostsByAuthorSlug(slug: profile.slug),
weightPoints: await profileRepository.getWeight(period: period),
circumferencePoints: await profileRepository.getCircumferences(period: period),
),);
emit(
ProfileState.loaded(
profile: profile,
profileDetails: await profileRepository.getMyProfileDetails(),
blogPosts: await profileRepository.getBlogPostsByAuthorSlug(slug: profile.slug),
weightPoints: await profileRepository.getWeight(period: period),
circumferencePoints: await profileRepository.getCircumferences(period: period),
),
);
} catch (e) {
emit(ProfileState.error(errorMessage: e.toString()));
}

View File

@@ -22,6 +22,14 @@ class ProfileRepository {
}
}
Future<ProfileDetailsModel> getProfileDetailsBySlug(String slug) async {
try {
return await profileService.getProfileDetailsBySlug(slug: slug);
} catch (e) {
rethrow;
}
}
Future<ProfileModel> getMyProfile() async {
try {
return await profileService.getMyProfile();

View File

@@ -25,6 +25,11 @@ abstract class ProfileService {
@GET('/api/profile/detailz')
Future<ProfileDetailsModel> getMyProfileDetails();
@GET('/api/profile/detailz/{slug}')
Future<ProfileDetailsModel> getProfileDetailsBySlug({
@Path() required String slug,
});
@POST('/api/profile/addCircumference')
Future<void> addCircumference({
@Part(name: 'chest_circumference') required int chestCircumference,

View File

@@ -120,6 +120,40 @@ class _ProfileService implements ProfileService {
return _value;
}
@override
Future<ProfileDetailsModel> getProfileDetailsBySlug(
{required String slug}) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
const Map<String, dynamic>? _data = null;
final _options = _setStreamType<ProfileDetailsModel>(Options(
method: 'GET',
headers: _headers,
extra: _extra,
)
.compose(
_dio.options,
'/api/profile/detailz/${slug}',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
)));
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
late ProfileDetailsModel _value;
try {
_value = ProfileDetailsModel.fromJson(_result.data!);
} on Object catch (e, s) {
errorLogger?.logError(e, s, _options);
rethrow;
}
return _value;
}
@override
Future<void> addCircumference({
required int chestCircumference,