-
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.
Merge pull request #67 from APP-Android2/44-feature-자유게시판-데이터-적용
44 feature 자유게시판 데이터 적용
- Loading branch information
Showing
31 changed files
with
723 additions
and
186 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
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
16 changes: 15 additions & 1 deletion
16
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,22 @@ | ||
package kr.co.lion.mungnolza.data.repository | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import android.widget.ImageView | ||
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 updateBoard(boardModel:BoardModel, isRemoveImage:Boolean) | ||
|
||
suspend fun getBoardImageUri(boardIdx:Int,imageFilePath: String):Uri? | ||
|
||
suspend fun getBoardImageUriList(boardModel:BoardModel): MutableList<Uri?> | ||
} |
89 changes: 79 additions & 10 deletions
89
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,97 @@ | ||
package kr.co.lion.mungnolza.data.repository | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import android.util.Log | ||
import android.widget.ImageView | ||
import com.bumptech.glide.Glide | ||
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 getBoardImageUri(boardIdx:Int,imageFilePath: String):Uri?{ | ||
var response:Uri? = null | ||
val path = "board/${boardIdx}/${imageFilePath}" | ||
try{ | ||
response = storage.child(path).downloadUrl.await() | ||
}catch (e:Exception){ | ||
Log.e("FirebaseResult", | ||
"Error Get BoardImageListPath : ${storage.child(path)}") | ||
} | ||
return response | ||
} | ||
|
||
override suspend fun getBoardImageUriList(boardModel:BoardModel): MutableList<Uri?> { | ||
var imageUriList:MutableList<Uri?> = mutableListOf() | ||
|
||
boardModel.boardImagePathList.forEach { | ||
imageUriList.add(getBoardImageUri(boardModel.boardIdx,it!!)!!) | ||
} | ||
return imageUriList | ||
} | ||
|
||
} |
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
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.