Skip to content

Commit

Permalink
feat: 컨텐츠 추가시 해시태그 추가 구현 (#46)
Browse files Browse the repository at this point in the history
* feat: 컨텐츠 생성시 해시태그 추가
  • Loading branch information
nain93 authored Jul 28, 2023
1 parent 8271c8c commit 35bb394
Show file tree
Hide file tree
Showing 13 changed files with 617 additions and 508 deletions.
36 changes: 36 additions & 0 deletions lib/providers/hashtag_provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import 'dart:async';

import 'package:moa_app/models/hashtag_model.dart';
import 'package:moa_app/repositories/hashtag_repository.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'hashtag_provider.g.dart';

/// AsyncNotifierProvider
// @Riverpod(keepAlive: true)
@riverpod
class Hashtag extends _$Hashtag {
Future<List<HashtagModel>> fetchItem() async {
var data = HashtagRepository.instance.getHashtagList();
return data;
}

@override
Future<List<HashtagModel>> build() async {
return fetchItem();
}

Future<List<HashtagModel>?> addHashtag({
required HashtagModel hashtag,
}) async {
state = const AsyncValue.loading();

state = await AsyncValue.guard(() async {
// await ItemRepository.instance.addItem(item: item);
var data = await fetchItem();
return [hashtag, ...data];
});

return state.value;
}
}
13 changes: 7 additions & 6 deletions lib/repositories/content_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import 'package:moa_app/utils/api.dart';
enum AddContentType { image, url }

abstract class IContentRepository {
Future<void> addContent(
{required AddContentType contentType, required ContentModel content});
Future<void> addContent({
required AddContentType contentType,
required ContentModel content,
required String hashTagStringList,
});
}

class ContentRepository implements IContentRepository {
Expand All @@ -18,6 +21,7 @@ class ContentRepository implements IContentRepository {
Future<void> addContent({
required AddContentType contentType,
required ContentModel content,
required String hashTagStringList,
}) async {
var token = await TokenRepository.instance.getToken();

Expand All @@ -28,7 +32,7 @@ class ContentRepository implements IContentRepository {
'folderId': content.contentId,
'name': content.contentName,
'memo': content.contentMemo,
'hashTag': '임시, 어드민',
'hashTag': hashTagStringList,
'contentType': 'IMAGE',
'originalFileName': '${content.contentName}.png',
'image': 'image/png:base64:${content.contentImageUrl}',
Expand All @@ -46,6 +50,3 @@ class ContentRepository implements IContentRepository {
}
}
}


// 'Content-type': 'multipart/form-data',
36 changes: 19 additions & 17 deletions lib/repositories/token_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ class TokenRepository implements ITokenRepository {
@override
Future<void> setToken({required String token}) async {
try {
if (kIsWeb) {
SharedPreferences prefs = await _prefs;
await prefs.setString('token', token);
return;
SharedPreferences prefs = await _prefs;
await prefs.setString('token', token);
if (!kIsWeb) {
await storage.write(key: key, value: token);
}
await storage.write(key: key, value: token);
} catch (e) {
logger.d(e);
}
Expand All @@ -36,12 +35,11 @@ class TokenRepository implements ITokenRepository {
@override
Future<void> removeToken() async {
try {
if (kIsWeb) {
SharedPreferences prefs = await _prefs;
await prefs.remove('token');
return;
SharedPreferences prefs = await _prefs;
await prefs.remove('token');
if (!kIsWeb) {
await storage.delete(key: key);
}
await storage.delete(key: key);
} catch (e) {
logger.d(e);
}
Expand All @@ -50,18 +48,22 @@ class TokenRepository implements ITokenRepository {
@override
Future<Object?> getToken() async {
try {
if (kIsWeb) {
SharedPreferences prefs = await _prefs;
var token = prefs.getString('token');
SharedPreferences prefs = await _prefs;
var token = prefs.getString('token');
if (token == null) {
FlutterSecureStorage storage = const FlutterSecureStorage();
await storage.deleteAll();

return null;
}

if (!kIsWeb) {
var token = await storage.read(key: key);
return token;
}
var token = await storage.read(key: key);
return token;

// todo refresh token 구현
// var testAdminToken =
// 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbkBnbWFpbC5jb20iLCJpZCI6IjUyNThkYzA3LWMxMDItNDg0NC04Yzk1LWM3ODY4YWYzY2M2YiIsImV4cCI6MzE1NTY5MDY3NDE4NDI3MiwiaWF0IjoxNjg3NzQzOTUzfQ.rZtKeIymBoDd9Z2iLMEuQrTUeCmgZyKwlYU5imxVdpo';
// return testAdminToken;
} catch (e) {
logger.d(e);
}
Expand Down
Loading

0 comments on commit 35bb394

Please sign in to comment.