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: 컨텐츠 상세 api #48

Merged
merged 1 commit into from
Aug 1, 2023
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
36 changes: 32 additions & 4 deletions lib/repositories/content_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ abstract class IContentRepository {
required ContentModel content,
required String hashTagStringList,
});

Future<ContentModel> getContentDetail({
required String contentId,
});
}

class ContentRepository implements IContentRepository {
Expand All @@ -25,7 +29,7 @@ class ContentRepository implements IContentRepository {
}) async {
var token = await TokenRepository.instance.getToken();

if (contentType.name == AddContentType.image.name) {
if (contentType == AddContentType.image) {
/// 이미지 방식
await dio.post(
'/api/v1/content/create',
Expand All @@ -46,7 +50,7 @@ class ContentRepository implements IContentRepository {
);
}

if (contentType.name == AddContentType.url.name) {
if (contentType == AddContentType.url) {
/// 링크 방식
await dio.post(
'/api/v1/content/create',
Expand All @@ -57,8 +61,8 @@ class ContentRepository implements IContentRepository {
'hashTag': hashTagStringList,
'contentType': 'URL',
'url': content.contentUrl,
// 'originalFileName': '${content.contentName}.png',
// 'image': 'image/png:base64:${content.contentImageUrl}',
'originalFileName': '${content.contentName}.png',
'image': 'image/png:base64:${content.contentImageUrl}',
},
options: Options(
headers: {
Expand All @@ -68,4 +72,28 @@ class ContentRepository implements IContentRepository {
);
}
}

@override
Future<ContentModel> getContentDetail({required String contentId}) async {
var token = await TokenRepository.instance.getToken();

var res = await dio.get(
'/api/v1/content/detail/view?contentId=$contentId',
options: Options(
headers: {
'Authorization': 'Bearer $token',
},
),
);

/// 백엔드 ContentModel 타입이 통일되지 않았으므로 임시로 타입 변환해서 넣어줌
return ContentModel.fromJson({
'contentId': '0',
'contentImageUrl': res.data['data']['thumbnail_image_url'],
'contentUrl': res.data['data']['contentUrl'] ?? '',
'contentMemo': res.data['data']['memo'],
'contentName': res.data['data']['contentName'],
'contentHashTag': res.data['data']['hashTags'],
});
}
}
174 changes: 101 additions & 73 deletions lib/screens/home/content_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ import 'package:go_router/go_router.dart';
import 'package:moa_app/constants/color_constants.dart';
import 'package:moa_app/constants/file_constants.dart';
import 'package:moa_app/constants/font_constants.dart';
import 'package:moa_app/models/content_model.dart';
import 'package:moa_app/repositories/content_repository.dart';
import 'package:moa_app/utils/general.dart';
import 'package:moa_app/widgets/app_bar.dart';
import 'package:moa_app/widgets/button.dart';
import 'package:moa_app/widgets/moa_widgets/bottom_modal_item.dart';

class ContentView extends HookWidget {
const ContentView({super.key, required this.id});
const ContentView({
super.key,
required this.id,
required this.folderName,
});
final String id;
final String folderName;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -69,83 +76,104 @@ class ContentView extends HookWidget {
child: Padding(
padding: const EdgeInsets.only(
left: 15, right: 15, bottom: kBottomNavigationBarHeight),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Image(
image: Assets.smallFolder,
width: 42,
height: 42,
),
const Text(
'요리/레시피',
style: H2TextStyle(),
),
],
),
Wrap(
children: [
Container(
margin: const EdgeInsets.only(top: 30, bottom: 40),
padding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: AppColors.primaryColor,
child: FutureBuilder<ContentModel>(
future: ContentRepository.instance.getContentDetail(contentId: id),
builder: (context, snapshot) {
var content = snapshot.data;

if (snapshot.hasData && content != null) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Image(
image: Assets.smallFolder,
width: 42,
height: 42,
),
Text(
folderName,
style: const H2TextStyle(),
),
],
),
Wrap(
spacing: 10,
runSpacing: 10,
children: [
...content.contentHashTag.map(
(e) => Container(
margin: const EdgeInsets.only(top: 30, bottom: 40),
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 8),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: AppColors.primaryColor,
),
child: Text(
'#${e.hashTag}',
style: const TextStyle(
color: AppColors.whiteColor,
fontSize: 16,
fontWeight: FontWeight.w600,
fontFamily: FontConstants.pretendard,
),
),
),
),
],
),
child: const Text(
'#자취레시피',
style: TextStyle(
color: AppColors.whiteColor,
fontSize: 16,
fontWeight: FontWeight.w600,
fontFamily: FontConstants.pretendard,
Container(
height: 225,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: AppColors.grayBackground,
width: 1,
),
image: DecorationImage(
image: NetworkImage(content.contentImageUrl),
fit: BoxFit.contain,
),
),
),
),
],
),
Container(
height: 225,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: AppColors.primaryColor,
),
),
const SizedBox(height: 10),
const Text(
'1인가구 제철채소 레시피',
style: H2TextStyle(),
),
const SizedBox(height: 30),
Text(
'요즘 유행인 다이어트 간식 #그릭요거트바크 만들기! 너무 초간단해보여서 저도 요가 후 후다닥 만들어보았는데~만들고 보니 아쉬웠던 점들도 있어서잇님들은 저처럼 시행착오 없이 바로 완벽 성공하길 바라며!',
style: const Hash1TextStyle().merge(
const TextStyle(height: 1.4),
),
),
const SizedBox(height: 80),
Row(
children: [
Expanded(
child: Button(
backgroundColor: AppColors.linkButton,
text: '링크 바로가기',
onPress: pressGoToLink,
const SizedBox(height: 10),
Text(
content.contentName,
style: const H2TextStyle(),
),
const SizedBox(height: 30),
Text(
content.contentMemo ?? '',
style: const Hash1TextStyle().merge(
const TextStyle(height: 1.4),
),
),
),
const SizedBox(width: 15),
Expanded(
child: Button(
text: '확인',
onPress: pressConfirm,
const SizedBox(height: 80),
Row(
children: [
Expanded(
child: Button(
backgroundColor: AppColors.linkButton,
text: '링크 바로가기',
onPress: pressGoToLink,
),
),
const SizedBox(width: 15),
Expanded(
child: Button(
text: '확인',
onPress: pressConfirm,
),
),
],
),
),
],
),
],
],
);
}
return const SizedBox();
},
),
),
),
Expand Down
37 changes: 1 addition & 36 deletions lib/screens/home/folder_detail_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,6 @@ class FolderDetailView extends HookWidget {
);
}

// void showFolderDetailModal() {
// General.instance.showBottomSheet(
// context: context,
// padding:
// const EdgeInsets.only(left: 15, right: 15, top: 15, bottom: 30),
// height: 225,
// child: Column(
// children: [
// BottomModalItem(
// icon: Assets.share,
// title: '공유하기',
// onPressed: () {
// // Todo url링크복사후 snackbar 알림
// },
// ),
// BottomModalItem(
// icon: Assets.pencil,
// title: '폴더명 수정',
// onPressed: () {
// context.pop();
// showEditFolderModal();
// },
// ),
// BottomModalItem(
// icon: Assets.trash,
// title: '폴더 삭제',
// onPressed: () {
// context.pop();
// showDeleteFolderModal();
// },
// ),
// ],
// ),
// );
// }

return Scaffold(
appBar: AppBarBack(
isBottomBorderDisplayed: false,
Expand Down Expand Up @@ -108,6 +72,7 @@ class FolderDetailView extends HookWidget {
child: DynamicGridList(
contentList: contentList,
pullToRefresh: pullToRefresh,
folderName: folderName,
),
),
],
Expand Down
1 change: 1 addition & 0 deletions lib/screens/home/hashtag_detail_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class HashtagDetailView extends HookWidget {
child: DynamicGridList(
contentList: const [],
pullToRefresh: pullToRefresh,
folderName: 'folderName',
)),
],
),
Expand Down
1 change: 1 addition & 0 deletions lib/screens/setting/edit_my_type_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class EditMyTypeView extends HookWidget {
child: DynamicGridList(
contentList: const [],
pullToRefresh: hashtagPullToRefresh,
folderName: 'folderName',
),
),
],
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/router_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,13 @@ final routeProvider = Provider(
name: GoRoutes.content.name,
path: '${GoRoutes.content.path}/:id',
pageBuilder: (context, state) {
var contentView = state.extra as ContentView;
return buildIosPageTransitions<void>(
context: context,
state: state,
child: ContentView(
id: state.pathParameters['id']!,
id: contentView.id,
folderName: contentView.folderName,
),
);
},
Expand Down
Loading
Loading