-
Notifications
You must be signed in to change notification settings - Fork 0
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 #38 from SujungVillage/feature/noticeDetail
- Loading branch information
Showing
12 changed files
with
306 additions
and
5 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
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
44 changes: 44 additions & 0 deletions
44
app/src/main/java/kr/co/sujungvillage_admin/adapter/NoticeAdapter.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package kr.co.sujungvillage_admin.adapter | ||
|
||
import android.content.Intent | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.core.content.ContextCompat.startActivity | ||
import androidx.recyclerview.widget.RecyclerView | ||
import kr.co.sujungvillage_admin.NoticeDetailActivity | ||
import kr.co.sujungvillage_admin.data.NoticeRequestResultDTO | ||
import kr.co.sujungvillage_admin.databinding.ListitemNoticePostBinding | ||
|
||
class NoticeAdapter : RecyclerView.Adapter<NoticeHolder>() { | ||
var noticeList = mutableListOf<NoticeRequestResultDTO>() | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NoticeHolder { | ||
val binding = ListitemNoticePostBinding.inflate(LayoutInflater.from(parent.context), parent, false) | ||
return NoticeHolder(binding) | ||
} | ||
|
||
override fun onBindViewHolder(holder: NoticeHolder, position: Int) { | ||
val notice = noticeList.get(position) | ||
holder.setNotice(notice) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return noticeList.size | ||
} | ||
} | ||
|
||
class NoticeHolder(val binding: ListitemNoticePostBinding): RecyclerView.ViewHolder(binding.root) { | ||
fun setNotice(notice: NoticeRequestResultDTO) { | ||
binding.textId.text = "${notice.id}" | ||
binding.textDormitory.text = "${notice.dormitory}" | ||
binding.textTitle.text = "${notice.title}" | ||
binding.textDate.text = "${notice.date.subSequence(0, 4)}.${notice.date.subSequence(5, 7)}.${notice.date.subSequence(8, 10)}" | ||
|
||
// 공지사항 클릭 시 상세 액티비티 생성 | ||
binding.root.setOnClickListener { | ||
val intent = Intent(binding.root.context, NoticeDetailActivity::class.java) | ||
intent.putExtra("noticeId", notice.id) | ||
startActivity(binding.root.context, intent, null) | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/kr/co/sujungvillage_admin/api/NoticeService.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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package kr.co.sujungvillage_admin.api | ||
|
||
import kr.co.sujungvillage_admin.data.NoticeCreateDTO | ||
import kr.co.sujungvillage_admin.data.NoticeCreateResultDTO | ||
import kr.co.sujungvillage_admin.data.NoticeDetailResultDTO | ||
import kr.co.sujungvillage_admin.data.NoticeRequestResultDTO | ||
import retrofit2.Call | ||
import retrofit2.http.* | ||
|
||
interface NoticeService { | ||
// 공지사항 리스트 조회 | ||
@GET("/api/common/getAnnouncementList") | ||
fun noticeRequest( | ||
@Header("user_id") userId: String, | ||
): Call<List<NoticeRequestResultDTO>> | ||
|
||
// 공지사항 상세 조회 | ||
@GET("/api/common/getDetailedAnnouncement") | ||
fun noticeDetailRequest( | ||
@Header("user_id") userId: String, | ||
@Query("notice_id") noticeId: Long, | ||
): Call<NoticeDetailResultDTO> | ||
|
||
// 공지사항 작성 | ||
@POST("/api/admin/writeAnnouncement") | ||
fun noticeCreate( | ||
@Header("user_id") userId: String, | ||
@Body noticeInfo: NoticeCreateDTO, | ||
): Call<NoticeCreateResultDTO> | ||
} |
58 changes: 58 additions & 0 deletions
58
app/src/main/java/kr/co/sujungvillage_admin/data/Notice.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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package kr.co.sujungvillage_admin.data | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import java.io.Serializable | ||
|
||
data class NoticeRequestResultDTO( | ||
@SerializedName("id") | ||
val id: Long, | ||
@SerializedName("title") | ||
val title: String, | ||
@SerializedName("dormitoryName") | ||
val dormitory: String, | ||
@SerializedName("regDate") | ||
val date: String, | ||
): Serializable {} | ||
|
||
data class NoticeDetailResultDTO( | ||
@SerializedName("id") | ||
val id: Long, | ||
@SerializedName("writerName") | ||
val name: String, | ||
@SerializedName("title") | ||
val title: String, | ||
@SerializedName("content") | ||
val content: String, | ||
@SerializedName("dormitoryName") | ||
val dormitory: String, | ||
@SerializedName("regDate") | ||
val regDate: String, | ||
@SerializedName("modDate") | ||
val modDate: String, | ||
): Serializable {} | ||
|
||
data class NoticeCreateDTO( | ||
@SerializedName("title") | ||
val title: String, | ||
@SerializedName("content") | ||
val content: String, | ||
@SerializedName("dormitoryName") | ||
val dormitory: String, | ||
): Serializable {} | ||
|
||
data class NoticeCreateResultDTO( | ||
@SerializedName("id") | ||
val id: Long, | ||
@SerializedName("writerId") | ||
val writer: String, | ||
@SerializedName("title") | ||
val title: String, | ||
@SerializedName("content") | ||
val content: String, | ||
@SerializedName("regDate") | ||
val regDate: String, | ||
@SerializedName("modDate") | ||
val modDate: String, | ||
@SerializedName("dormitoryName") | ||
val dormitory: String, | ||
): Serializable {} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/kr/co/sujungvillage_admin/retrofit/RetrofitBuilder.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package kr.co.sujungvillage_admin.retrofit | ||
|
||
import com.google.gson.GsonBuilder | ||
import kr.co.sujungvillage_admin.BuildConfig.BASE_URL | ||
import kr.co.sujungvillage_admin.api.NoticeService | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
object RetrofitBuilder { | ||
// 사용할 API 인터페이스 선언 | ||
var noticeApi: NoticeService | ||
|
||
val gson = GsonBuilder().setLenient().create() | ||
|
||
init { | ||
// API 서버 연결 | ||
val retrofit = Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create(gson)) | ||
.build() | ||
|
||
noticeApi = retrofit.create(NoticeService::class.java) | ||
} | ||
} |
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.