Skip to content

Commit

Permalink
[#44] 중간 커밋
Browse files Browse the repository at this point in the history
  • Loading branch information
ayz1070 committed Apr 16, 2024
1 parent 6622302 commit ae94ff0
Show file tree
Hide file tree
Showing 21 changed files with 490 additions and 161 deletions.
18 changes: 10 additions & 8 deletions MungNolZa/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
android:supportsRtl="true"
android:theme="@style/Theme.MungNolZa"
tools:targetApi="31">
<activity
android:name=".ui.freeboard.AddBoardActivity"
android:exported="false" />
<activity
android:name=".ui.TestActivity"
android:exported="true" />

<activity
android:name=".ui.dialog.DialogSampleActivity"
android:exported="true" />
Expand All @@ -47,19 +49,19 @@
<activity
android:name=".ui.main.MainActivity"
android:exported="true"
android:windowSoftInputMode="adjustPan" />
<activity
android:name=".ui.intro.activity.JoinActivity"
android:exported="true" />
<activity
android:name=".ui.intro.activity.StartActivity"
android:exported="true">
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.intro.activity.JoinActivity"
android:exported="true" />
<activity
android:name=".ui.intro.activity.StartActivity"
android:exported="true"></activity>
<activity
android:name=".ui.intro.activity.OnBoardingActivity"
android:exported="true" />
Expand Down
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)

}
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

}


}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ import kr.co.lion.mungnolza.model.BoardModel
interface FreeBoardRepository {
suspend fun fetchAllBoardData(): ArrayList<BoardModel>
suspend fun fetchAllBoardImage(boardIdx: String, imgName: String): Uri?

suspend fun insertBoardData(boardModel: BoardModel)

suspend fun updateBoardData(boardModel:BoardModel, isRemoveImage:Boolean)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import com.google.firebase.firestore.Query
import com.google.firebase.firestore.firestore
import com.google.firebase.storage.StorageReference
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.util.ContentState
Expand Down Expand Up @@ -46,4 +49,36 @@ class FreeBoardRepositoryImpl : FreeBoardRepository {
}
return response
}

// insert
override suspend fun insertBoardData(boardModel: BoardModel){
val job = CoroutineScope(Dispatchers.IO).launch {
boardStore.add(boardModel)
}
job.join()
}

// update
override suspend fun updateBoardData(boardModel:BoardModel, isRemoveImage:Boolean){
val job = CoroutineScope(Dispatchers.IO).launch {
val query = boardStore.whereEqualTo("boardIdx", boardModel.boardIdx).get().await()

val map = mutableMapOf<String, Any?>()
map["boardTitle"] = boardModel.boardTitle
map["boardContent"] = boardModel.boardContent
map["boardWriteDate"] = boardModel.boardWriteDate

if(boardModel.boardImagePathList.isNotEmpty()){
map["boardImagePathList"] = boardModel.boardImagePathList
}

if(isRemoveImage == true){
map["boardImagePathList"] = null
}

query.documents[0].reference.update(map)
}

job.join()
}
}
Loading

0 comments on commit ae94ff0

Please sign in to comment.