-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
490 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 11 additions & 1 deletion
12
MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/BoardRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
package kr.co.lion.mungnolza.data.repository | ||
|
||
import android.net.Uri | ||
import kr.co.lion.mungnolza.model.BoardModel | ||
|
||
|
||
interface BoardRepository { | ||
suspend fun getBoardData(boardIdx: Int): BoardModel? | ||
suspend fun getBoardList():ArrayList<BoardModel> | ||
|
||
suspend fun insertBoard(boardModel:BoardModel) | ||
|
||
suspend fun deleteBoard(boardModel: BoardModel) | ||
|
||
suspend fun getBoardImageListPath(boardModel: BoardModel):Uri? | ||
|
||
suspend fun updateBoard(boardModel:BoardModel, isRemoveImage:Boolean) | ||
|
||
} |
79 changes: 69 additions & 10 deletions
79
MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/BoardRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,87 @@ | ||
package kr.co.lion.mungnolza.data.repository | ||
|
||
import android.net.Uri | ||
import android.util.Log | ||
import com.google.firebase.Firebase | ||
import com.google.firebase.firestore.Query | ||
import com.google.firebase.firestore.firestore | ||
import com.google.firebase.storage.storage | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.tasks.await | ||
import kr.co.lion.mungnolza.model.BoardModel | ||
import kr.co.lion.mungnolza.model.UserModel | ||
import kr.co.lion.mungnolza.util.ContentState | ||
|
||
class BoardRepositoryImpl : BoardRepository{ | ||
class BoardRepositoryImpl() : BoardRepository { | ||
|
||
override suspend fun getBoardData(boardIdx: Int): BoardModel? { | ||
var boardModel: BoardModel? = null | ||
private val boardStore = Firebase.firestore.collection("Board") | ||
private val storage = Firebase.storage.reference | ||
|
||
val job = CoroutineScope(Dispatchers.IO).launch { | ||
val collectionReference = Firebase.firestore.collection("Board") | ||
val querySnapshot = | ||
collectionReference.whereEqualTo("boardIdx", boardIdx).get().await() | ||
override suspend fun getBoardList(): ArrayList<BoardModel> { | ||
val boardList = arrayListOf<BoardModel>() | ||
|
||
if (querySnapshot.isEmpty == false) { | ||
boardModel = querySnapshot.documents[0].toObject(BoardModel::class.java) | ||
try { | ||
var query = | ||
boardStore.whereEqualTo("boardState", ContentState.CONTENT_STATE_NORMAL.number) | ||
query = query.orderBy("boardIdx", Query.Direction.DESCENDING) | ||
val querySnapShot = query.get().await() | ||
|
||
querySnapShot.forEach { | ||
val boardModel = it.toObject(BoardModel::class.java) | ||
boardList.add(boardModel) | ||
} | ||
|
||
} catch (e: Exception) { | ||
Log.e("FirebaseResult", "Error Get Board Data: ${e.message}") | ||
} | ||
return boardModel | ||
return boardList | ||
} | ||
|
||
override suspend fun insertBoard(boardModel: BoardModel) { | ||
boardStore.add(boardModel) | ||
} | ||
|
||
override suspend fun updateBoard(boardModel: BoardModel, isRemoveImage: Boolean) { | ||
try{ | ||
val query = boardStore.whereEqualTo("boardIdx",boardModel.boardIdx).get().await() | ||
|
||
// 저장 데이터를 HashMap으로 만든다. | ||
val map = mutableMapOf<String, Any?>() | ||
map["boardTitle"] = boardModel.boardTitle | ||
map["boardContent"] = boardModel.boardContent | ||
|
||
if(boardModel.boardImagePathList.isNotEmpty()){ | ||
map["boardImagePathList"] = boardModel.boardImagePathList | ||
} | ||
if(isRemoveImage == true){ | ||
map["boardImagePathList"] = null | ||
} | ||
|
||
query.documents[0].reference.update(map) | ||
}catch (e: Exception) { | ||
Log.e("FirebaseResult", "Error Update Board Data: ${e.message}") | ||
} | ||
|
||
} | ||
|
||
override suspend fun deleteBoard(boardModel: BoardModel) { | ||
// 삭제가 아닌 BoardState 변경 | ||
} | ||
|
||
override suspend fun getBoardImageListPath(boardModel: BoardModel):Uri?{ | ||
var response:Uri? = null | ||
val path = "board/${boardModel.boardIdx}/${boardModel.boardImagePathList}" | ||
try{ | ||
response = storage.child(path).downloadUrl.await() | ||
}catch (e:Exception){ | ||
Log.e("FirebaseResult", | ||
"Error Get BoardImageListPath : ${storage.child(path)}") | ||
} | ||
return response | ||
|
||
} | ||
|
||
|
||
} |
7 changes: 0 additions & 7 deletions
7
MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/UserRepository.kt
This file was deleted.
Oops, something went wrong.
28 changes: 0 additions & 28 deletions
28
MungNolZa/app/src/main/java/kr/co/lion/mungnolza/data/repository/UserRepositoryImpl.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.