Skip to content

Commit

Permalink
Merge pull request #57 from Fill-ENERGY/Feature/#4-community
Browse files Browse the repository at this point in the history
Feature/#4 community
  • Loading branch information
seohyeon121 authored Aug 18, 2024
2 parents a699a61 + 6fd7220 commit 1755ee9
Show file tree
Hide file tree
Showing 12 changed files with 407 additions and 296 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Multipart
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path
Expand Down Expand Up @@ -86,4 +87,13 @@ interface CommunityInterface {
@Path("boardId") boardId: Int,
@Body request: WriteCommentRequest,
): Call<CommentResponse>


//도와줘요 상태 변경 api
@PATCH("/api/v1/boards/{boardId}/status")
fun helpStatus(
@Header("Authorization") accessToken: String,
@Path("boardId") boardId: Int,
@Body request: HelpStatusRequest
): Call<HelpStatusResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class CommunityRepository {
}

// 커뮤니티 상세 조회
fun getDetailCommunity(accessToken: String, boardId: Int, callback: (DetailModel?)-> Unit){
fun getDetailCommunity(accessToken: String, boardId: Int, callback: (BoardModel?)-> Unit){
val communityService = getRetrofit().create(CommunityInterface::class.java)
val call = communityService.getDetailCommunity(accessToken, boardId)

Expand Down Expand Up @@ -236,20 +236,20 @@ class CommunityRepository {
) {
if(response.isSuccessful){
//통신 성공
Log.d("전체커뮤니티api테스트", "통신 성공 ${response.code()}, ${response.body()?.result}")
val commentModel = response.body()?.result
Log.d("커뮤니티댓글조회api테스트", "통신 성공 ${response.code()}, ${response.body()?.result}")
val commentModel = response.body()?.result!!.comments
callback(commentModel)
} else {
//통신 실패
val error = response.errorBody()?.toString()
Log.e("전체커뮤니티api테스트", "통신 실패 $error")
Log.e("커뮤니티댓글조회api테스트", "통신 실패 $error")
callback(null)
}
}

override fun onFailure(call: Call<CommentListResponse>, t: Throwable) {
// 통신 실패
Log.w("전체커뮤니티api테스트", "통신 실패: ${t.message}")
Log.w("커뮤니티댓글조회api테스트", "통신 실패: ${t.message}")
callback(null)
}
})
Expand Down Expand Up @@ -284,5 +284,37 @@ class CommunityRepository {
}
)
}



// 도와줘요 상태 변경
fun helpStatus(accessToken: String, boardId: Int, request: HelpStatusRequest, callback: (HelpStatusModel?)-> Unit){
val communityService = getRetrofit().create(CommunityInterface::class.java)
val call = communityService.helpStatus(accessToken, boardId, request)

call.enqueue(object : Callback<HelpStatusResponse> {
override fun onResponse(call: Call<HelpStatusResponse>, response: Response<HelpStatusResponse>
) {
if(response.isSuccessful){
//통신 성공
Log.d("도와줘요상태변경api테스트", "통신 성공 ${response.code()}, ${response.body()?.result}")
val writeCommentBoardModel = response.body()?.result
callback(writeCommentBoardModel)
} else {
//통신 실패
val error = response.errorBody()?.toString()
Log.e("도와줘요상태변경api테스트", "통신 실패 $error")
callback(null)
}
}

override fun onFailure(call: Call<HelpStatusResponse>, t: Throwable) {
// 통신 실패
Log.w("도와줘요상태변경api테스트", "통신 실패: ${t.message}")
callback(null)
}
}
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ data class UploadImagesRequest(
data class WriteCommentRequest(
val content: String,
val secret: Boolean,
val parentCommentId: Int,
val parentCommentId: Int? = null,
val images: List<String>,
)


// 도와줘요 상태 변경 요청
data class HelpStatusRequest(
val helpStatus: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ data class BoardModel(
var content: String,
var category: String,
var helpStatus: String,
var isAuthor: Boolean,
var likeNum: Int,
var commentCount: Int,
var createdAt: String,
var updatedAt: String,
var images: List<String>,
var liked: Boolean,
var author: Boolean,
)


Expand Down Expand Up @@ -64,17 +65,19 @@ data class DeleteCommunityResponse(
data class DetailResponse(
val code: String,
val message: String,
val result: DetailModel
)
data class DetailModel(
var board: BoardModel,
val result: BoardModel
)

// 댓글 조회
data class CommentListResponse(
val code: String,
val message: String,
val result: List<CommentModel>,
val result: CommentResult,
)

// 댓글 리스트를 감싸는 클래스
data class CommentResult(
val comments: List<CommentModel>
)

// 댓글 작성
Expand All @@ -86,16 +89,13 @@ data class CommentResponse(
data class CommentModel(
var id: Int,
var content: String,
var secret: Boolean,
var memberId: Int,
var memberName: String,
var createdAt: String,
var images: List<ImagesModel>,
var deleted: Boolean,
var images: List<String>,
var parentId: Int,
var author: Boolean,
var canViewSecret: Boolean,
var replies: List<String>,
var replies: List<CommentModel>,
)


Expand All @@ -109,4 +109,17 @@ data class LikeModel(
var memberId: Int,
var boardId: Int,
var likeCount: Int,
)
var liked: Boolean,
)


// 도와줘요 상태 변경
data class HelpStatusResponse(
val code: String,
val message: String,
val result: HelpStatusModel,
)
data class HelpStatusModel(
var boardId: Int,
var helpStatus: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ fun makeChildComment(dataSet : List<CommentModel>): List<CommentModel>{

//같은 부모뷰를 가지는 댓글들을 해쉬함수를 통해서 묶어줌
for (data in dataSet){
val parentId = data.parentId ?: -1
val parentId = data.parentId

if (parentId<1){ //부모 뷰
if (parentId > 0){ //부모 뷰
newDataSet.add(data)
}else{ //자식 뷰
if (hashList.containsKey(parentId)) { // 이미 존재
Expand All @@ -27,7 +27,7 @@ fun makeChildComment(dataSet : List<CommentModel>): List<CommentModel>{
while(i < newDataSet.size){
// 자식 댓글 발견 -> 위치에 자식 댓글 리스트 추가
val parentId = newDataSet[i].id
if (parentId != null && hashList.containsKey(parentId)) {
if (parentId != 0 && hashList.containsKey(parentId)) {
val subData = hashList[parentId]!!
newDataSet.addAll(i + 1, subData)
i += subData.size - 1
Expand Down
Loading

0 comments on commit 1755ee9

Please sign in to comment.