Skip to content

Commit

Permalink
Merge pull request #64 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 20, 2024
2 parents a46855f + 54ecce3 commit 1d01008
Show file tree
Hide file tree
Showing 24 changed files with 943 additions and 526 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import retrofit2.http.Header
import retrofit2.http.Multipart
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Part
import retrofit2.http.Path
import retrofit2.http.Query
Expand Down Expand Up @@ -43,12 +44,21 @@ interface CommunityInterface {
): Call<UploadResponse>


// //게시글 삭제 api
// @DELETE("/api/v1/boards/{boardId}")
// fun deleteBoard(
// @Header("Authorization") accessToken: String,
// @Path("boardId") boardId: Int,
// )
//게시글 수정 api
@PUT("/api/v1/boards/{boardId}")
fun updateBoard(
@Header("Authorization") accessToken: String,
@Path("boardId") boardId: Int,
@Body request: PostBoardRequest,
): Call<UploadResponse>


//게시글 삭제 api
@DELETE("/api/v1/boards/{boardId}")
fun deleteBoard(
@Header("Authorization") accessToken: String,
@Path("boardId") boardId: Int,
): Call<DeleteCommunityResponse>


//이미지 업로드 api
Expand All @@ -73,7 +83,7 @@ interface CommunityInterface {
@Path("boardId") boardId: Int,
): Call<LikeResponse>

//커뮤니티 댓글 조회 api
//댓글 조회 api
@GET("/api/v1/boards/{boardId}/comments")
fun getListComment(
@Header("Authorization") accessToken: String,
Expand All @@ -88,6 +98,23 @@ interface CommunityInterface {
@Body request: WriteCommentRequest,
): Call<CommentResponse>

//댓글 수정 api
@PUT("/api/v1/boards/{boardId}/comments/{commentId}")
fun updateComment(
@Header("Authorization") accessToken: String,
@Path("boardId") boardId: Int,
@Path("commentId") commentId: Int,
@Body request: UpdateCommentRequest,
): Call<CommentResponse>

//댓글 삭제 api
@DELETE("/api/v1/boards/{boardId}/comments/{commentId}")
fun deleteComment(
@Header("Authorization") accessToken: String,
@Path("boardId") boardId: Int,
@Path("commentId") commentId: Int,
): Call<DeleteCommentResponse>


//도와줘요 상태 변경 api
@PATCH("/api/v1/boards/{boardId}/status")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,35 +106,66 @@ class CommunityRepository {
}


// // 커뮤니티 글 삭제
// fun deleteBoard(accessToken: String, boardId: Int, callback: (BoardModel?)-> Unit){
// val communityService = getRetrofit().create(CommunityInterface::class.java)
// val call = communityService.DeleteCommunityResponse(accessToken, request)
//
// call.enqueue(object : Callback<UploadResponse> {
// override fun onResponse(call: Call<UploadResponse>, response: Response<UploadResponse>
// ) {
// if(response.isSuccessful){
// //통신 성공
// Log.d("커뮤니티작성api테스트", "통신 성공 ${response.code()}, ${response.body()?.result}")
// val postBoardModel = response.body()?.result
// callback(postBoardModel)
// } else {
// //통신 실패
// val error = response.errorBody()?.toString()
// Log.e("커뮤니티작성api테스트", "통신 실패 $error")
// callback(null)
// }
// }
//
// override fun onFailure(call: Call<UploadResponse>, t: Throwable) {
// // 통신 실패
// Log.w("커뮤니티작성api테스트", "통신 실패: ${t.message}")
// callback(null)
// }
// }
// )
// }
// 커뮤니티 글 수정
fun updateBoard(accessToken: String, boardId: Int, request: PostBoardRequest, callback: (BoardModel?)-> Unit){
val communityService = getRetrofit().create(CommunityInterface::class.java)
val call = communityService.updateBoard(accessToken, boardId, request)

call.enqueue(object : Callback<UploadResponse> {
override fun onResponse(call: Call<UploadResponse>, response: Response<UploadResponse>
) {
if(response.isSuccessful){
//통신 성공
Log.d("커뮤니티수정api테스트", "통신 성공 ${response.code()}, ${response.body()?.result}")
val postBoardModel = response.body()?.result
callback(postBoardModel)
} else {
//통신 실패
val error = response.errorBody()?.toString()
Log.e("커뮤니티수정api테스트", "통신 실패 $error")
callback(null)
}
}

override fun onFailure(call: Call<UploadResponse>, t: Throwable) {
// 통신 실패
Log.w("커뮤니티수정api테스트", "통신 실패: ${t.message}")
callback(null)
}
}
)
}


// 커뮤니티 글 삭제
fun deleteBoard(accessToken: String, boardId: Int, callback: (DeleteCommunityResponse?)-> Unit){
val communityService = getRetrofit().create(CommunityInterface::class.java)
val call = communityService.deleteBoard(accessToken, boardId)

call.enqueue(object : Callback<DeleteCommunityResponse> {
override fun onResponse(call: Call<DeleteCommunityResponse>, response: Response<DeleteCommunityResponse>
) {
if(response.isSuccessful){
//통신 성공
Log.d("커뮤니티삭제api테스트", "통신 성공 ${response.code()}, ${response.body()?.result}")
val postBoardModel = response.body()
callback(postBoardModel)
} else {
//통신 실패
val error = response.errorBody()?.toString()
Log.e("커뮤니티삭제api테스트", "통신 실패 $error")
callback(null)
}
}

override fun onFailure(call: Call<DeleteCommunityResponse>, t: Throwable) {
// 통신 실패
Log.w("커뮤니티삭제api테스트", "통신 실패: ${t.message}")
callback(null)
}
}
)
}

// 이미지 업로드
fun uploadImages(accessToken: String, request: UploadImagesRequest, callback: (ImagesModel?)-> Unit){
Expand Down Expand Up @@ -286,6 +317,68 @@ class CommunityRepository {
}


// 커뮤니티 댓글 수정
fun updateComment(accessToken: String, boardId: Int, commentId: Int, request: UpdateCommentRequest, callback: (CommentModel?)-> Unit){
val communityService = getRetrofit().create(CommunityInterface::class.java)
val call = communityService.updateComment(accessToken, boardId, commentId, request)

call.enqueue(object : Callback<CommentResponse> {
override fun onResponse(call: Call<CommentResponse>, response: Response<CommentResponse>
) {
if(response.isSuccessful){
//통신 성공
Log.d("댓글수정api테스트", "통신 성공 ${response.code()}, ${response.body()?.result}")
val postBoardModel = response.body()?.result
callback(postBoardModel)
} else {
//통신 실패
val error = response.errorBody()?.toString()
Log.e("댓글수정api테스트", "통신 실패 $error")
callback(null)
}
}

override fun onFailure(call: Call<CommentResponse>, t: Throwable) {
// 통신 실패
Log.w("댓글수정api테스트", "통신 실패: ${t.message}")
callback(null)
}
}
)
}


// 커뮤니티 댓글 삭제
fun deleteComment(accessToken: String, boardId: Int, commentId: Int, callback: (DeleteCommentResponse?)-> Unit){
val communityService = getRetrofit().create(CommunityInterface::class.java)
val call = communityService.deleteComment(accessToken, boardId, commentId)

call.enqueue(object : Callback<DeleteCommentResponse> {
override fun onResponse(call: Call<DeleteCommentResponse>, response: Response<DeleteCommentResponse>
) {
if(response.isSuccessful){
//통신 성공
Log.d("커뮤니티댓글삭제api테스트", "통신 성공 ${response.code()}, ${response.body()?.result}")
val postBoardModel = response.body()
callback(postBoardModel)
} else {
//통신 실패
val error = response.errorBody()?.toString()
Log.e("커뮤니티댓글삭제api테스트", "통신 실패 $error")
callback(null)
}
}

override fun onFailure(call: Call<DeleteCommentResponse>, t: Throwable) {
// 통신 실패
Log.w("커뮤니티댓글삭제api테스트", "통신 실패: ${t.message}")
callback(null)
}
}
)
}



// 도와줘요 상태 변경
fun helpStatus(accessToken: String, boardId: Int, request: HelpStatusRequest, callback: (HelpStatusModel?)-> Unit){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.example.energy.data.repository.community
import okhttp3.MultipartBody
import retrofit2.http.Multipart

// 게시글 작성 요청 데이터
// 게시글 작성 요청 데이터 / 수정 요청 데이터
data class PostBoardRequest(
val title: String,
val content: String,
Expand All @@ -12,6 +12,7 @@ data class PostBoardRequest(
)



// 이미지 업로드 요청
data class UploadImagesRequest(
val images: List<MultipartBody.Part>,
Expand All @@ -24,6 +25,12 @@ data class WriteCommentRequest(
val parentCommentId: Int? = null,
val images: List<String>,
)
// 댓글 수정 요청
data class UpdateCommentRequest(
val content: String,
val images: List<String>,
val secret: Boolean,
)


// 도와줘요 상태 변경 요청
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ data class ImagesModel (
)


// 게시글 작성
// 게시글 작성 / 게시글 수정
data class UploadResponse (
val code: String,
val message: String,
Expand Down Expand Up @@ -80,7 +80,7 @@ data class CommentResult(
val comments: List<CommentModel>
)

// 댓글 작성
// 댓글 작성 / 댓글 수정
data class CommentResponse(
val code: String,
val message: String,
Expand All @@ -99,6 +99,14 @@ data class CommentModel(
)


// 댓글 삭제
data class DeleteCommentResponse(
val code: String,
val message: String,
val result: Int,
)


// 좋아요 추가
data class LikeResponse(
val code: String,
Expand Down

This file was deleted.

Loading

0 comments on commit 1d01008

Please sign in to comment.