Skip to content

Commit

Permalink
Feat: 향후 계획/시간표 과목, 트랙 검색 구현 #50
Browse files Browse the repository at this point in the history
  • Loading branch information
dkyuuum committed Feb 19, 2024
1 parent 1623cec commit e86564d
Show file tree
Hide file tree
Showing 28 changed files with 983 additions and 380 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package umc.com.mobile.project.data.model.plan

data class AddTimeRequest(
val semesterDto: SemesterDto,
val subjectDtoList: List<SubjectDtoList>,
)

data class SemesterDto(
val grade: Long,
val semester: Long,
)

data class SubjectDtoList(
val type: String,
val name: String,
val credit: String,
)

Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package umc.com.mobile.project.data.model.plan

data class AddTimeResponse(
val semesterDto: SemesterDto,
val subjectDtoList: List<SubjectDtoList>,
val isSuccess: Boolean,
val code: String,
val message: String,
val result: AddResponseResult
)

data class SemesterDto(
val grade: Long,
val semester: Long,
data class AddResponseResult(
val addResponseDtos: List<AddResponseDto>
)

data class SubjectDtoList(
val type: String,
val name: String,
val credit: Long,
data class AddResponseDto(
val subjectId: Long,
val createdAt: String
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package umc.com.mobile.project.data.model.plan

data class CertificateLicenseRequest(
val certificateId: Long,
val name: String,
val date: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package umc.com.mobile.project.data.model.plan

data class EditMemoRequest(
val memo: String
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package umc.com.mobile.project.data.model.plan

data class PlanFreeRequest(
val memo: String,
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package umc.com.mobile.project.data.model.plan

data class PlanFreeResponse(
val isSuccess: Boolean,
val code: String,
val message: String,
val result: FreeInfo,
)

data class FreeInfo(
val memo: String,
)

Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,56 @@ package umc.com.mobile.project.data.network.api
import retrofit2.http.GET
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.Query
import umc.com.mobile.project.data.model.plan.AddTimeRequest
import umc.com.mobile.project.data.model.plan.AddTimeResponse
import umc.com.mobile.project.data.model.plan.BringlicenseResponse
import umc.com.mobile.project.data.model.plan.ListTimeResponse
import umc.com.mobile.project.data.model.plan.PlanFreeRequest
import umc.com.mobile.project.data.model.plan.PlanFreeResponse
import umc.com.mobile.project.data.model.plan.PlanTrackResponse
import umc.com.mobile.project.data.model.plan.SaveInfo
import umc.com.mobile.project.data.model.plan.SemesterTimeResponse
import umc.com.mobile.project.data.model.plan.UPlicenseResponse
import umc.com.mobile.project.data.model.plan.EditMemoRequest


interface PlanApi {
@GET("plans/certifications")
fun getUPlicense(): Call<UPlicenseResponse>
@GET("plans/certifications")
fun getUPlicense(): Call<UPlicenseResponse>


@POST("plans/certifications")
fun saveLicense(@Body request: List<SaveInfo>): Call<BringlicenseResponse>
@POST("plans/certifications")
fun saveLicense(@Body request: List<SaveInfo>): Call<BringlicenseResponse>




@GET("/plans/timetable/searchSubject")
fun getListTime(@Query("hakki") hakki:String, @Query("track") track : String) : Call<ListTimeResponse>
@GET("/plans/timetable/searchSubject")
fun getListTime(@Query("hakki") hakki:String, @Query("track") track : String) : Call<ListTimeResponse>

@GET("/plans/timetable/searchTrack")
fun getTrackInfo(@Query("hakki") hakki: String) : Call<PlanTrackResponse>

@GET("/plans/timetable/searchHakki")
fun getSemesterInfo():Call<SemesterTimeResponse>

@POST("/plans/timetable")
fun addTime(@Body addTimeRequest: AddTimeRequest): Call<AddTimeResponse>

@GET("/plans/memo")
fun getFreeInfo() : Call<PlanFreeResponse>

@POST("/plans/memo")
fun postFreeMemo(@Body request: PlanFreeRequest): Call<PlanFreeResponse>

@PATCH("/plans/memo")
fun editMemo(@Body editMemoRequest: EditMemoRequest) : Call<PlanFreeResponse>


@GET("/plans/timetable/searchTrack")
fun getTrackInfo(@Query("hakki") hakki: String) : Call<PlanTrackResponse>

@GET("/plans/timetable/searchHakki")
fun getSemesterInfo():Call<SemesterTimeResponse>



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,57 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import umc.com.mobile.project.data.model.plan.PlanFreeRequest
import umc.com.mobile.project.databinding.FragmentPlanFreeBinding
import umc.com.mobile.project.ui.plan.PlanViewModel

class PlanFreeFragment : Fragment() {
private var _binding: FragmentPlanFreeBinding? = null
private val viewModel: PlanViewModel by viewModels()
private val viewModel: PlanViewModel by activityViewModels()
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
_binding = FragmentPlanFreeBinding.inflate(inflater, container, false)

viewModel.text.observe(viewLifecycleOwner) { text ->
// Update your UI here with the LiveData update
// Make sure 'textViewExample' matches the ID of the TextView in your layout
// binding.textViewExample.text = text
// 버튼 클릭 이벤트 설정
binding.freeStoreButton.setOnClickListener {
val memoText = binding.planFreeMemo.text.toString()
if (memoText.isNotEmpty()) {
viewModel.postMemo(PlanFreeRequest(memo = memoText))
}
}

// 메모 저장 결과 관찰
viewModel.postMemoResult.observe(viewLifecycleOwner) { isSuccess ->
if (isSuccess) {
Toast.makeText(context, "메모가 성공적으로 저장되었습니다.", Toast.LENGTH_SHORT).show()
viewModel.getFreeInfo() // 저장 후 메모 정보 다시 불러오기
} else {
Toast.makeText(context, "메모 저장에 실패했습니다.", Toast.LENGTH_SHORT).show()
}
}

// 저장된 메모 정보를 불러와서 EditText에 표시
viewModel.planFreeInfo.observe(viewLifecycleOwner) { planFreeResponse ->
planFreeResponse?.result?.memo?.let {
binding.planFreeMemo.setText(it)
}
}

binding.editMemo.setOnClickListener {
val memoText = binding.planFreeMemo.text.toString()
if (memoText.isNotEmpty()) {
viewModel.editMemo(memoText) // 수정된 메모를 서버에 전송
}
}


return binding.root
}

Expand All @@ -32,3 +63,4 @@ class PlanFreeFragment : Fragment() {
_binding = null
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,39 @@ import umc.com.mobile.project.data.model.plan.TimeResult
import umc.com.mobile.project.databinding.ItemCertificateBinding
import umc.com.mobile.project.databinding.ItemTimeSubjectBinding

class PlanRecyclerAdapter( timeList: List<TimeResult?>): RecyclerView.Adapter<PlanRecyclerAdapter.NonSubjectViewHolder>(){
var timeList: List<TimeResult?> = timeList
set(value) {
field = value
notifyDataSetChanged()
//데이터가 바뀌었다 알려줌.
}

class PlanRecyclerAdapter(
private var timeList: List<TimeResult?>,
private val onAddButtonClicked: ((TimeResult?) -> Unit)? = null
) : RecyclerView.Adapter<PlanRecyclerAdapter.NonSubjectViewHolder>() {

override fun getItemCount(): Int {
return timeList?.size ?: 0
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NonSubjectViewHolder {
val itemBinding = ItemTimeSubjectBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return NonSubjectViewHolder(itemBinding)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlanRecyclerAdapter.NonSubjectViewHolder {
val itemBinding = ItemTimeSubjectBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return PlanRecyclerAdapter.NonSubjectViewHolder(itemBinding)
override fun onBindViewHolder(holder: NonSubjectViewHolder, position: Int) {
val timeResult = timeList[position]
holder.bind(timeResult, onAddButtonClicked)
}

override fun onBindViewHolder(holder: PlanRecyclerAdapter.NonSubjectViewHolder, position: Int) {
override fun getItemCount(): Int = timeList.size

holder.itemBinding.timeItemScore.text =timeList[position]?.searchCredit.toString()
holder.itemBinding.timeItemSemester.text =timeList[position]?.searchGrade.toString()
holder.itemBinding.timeItemSubject.text = timeList[position]?.searchName.toString()
fun updateTimeList(newTimeList: List<TimeResult?>) {
this.timeList = newTimeList
notifyDataSetChanged() // 데이터가 변경되었음을 알리고 UI를 갱신
}

class NonSubjectViewHolder(val itemBinding: ItemTimeSubjectBinding) : RecyclerView.ViewHolder(itemBinding.root)
}
class NonSubjectViewHolder(private val itemBinding: ItemTimeSubjectBinding) : RecyclerView.ViewHolder(itemBinding.root) {
fun bind(timeResult: TimeResult?, onAddButtonClicked: ((TimeResult?) -> Unit)?) {
itemBinding.timeItemSubject.text=timeResult?.searchName.toString()
itemBinding.timeItemSemester.text = timeResult?.searchGrade.toString()
val divisionAndCredit = "${timeResult?.searchType} / ${timeResult?.searchCredit}"
itemBinding.timeItemScore.text = divisionAndCredit

// 버튼 클릭 이벤트 설정
itemBinding.planTimeAddButton.setOnClickListener {
onAddButtonClicked?.invoke(timeResult)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
package umc.com.mobile.project.ui.plan

import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import umc.com.mobile.project.data.model.plan.semesterResult
import umc.com.mobile.project.databinding.ItemChooseSemesterBinding

class PlanSemesterAdapter( semesterList: List<semesterResult?>): RecyclerView.Adapter<PlanSemesterAdapter.NonSubjectViewHolder>(){
class PlanSemesterAdapter(semesterList: List<semesterResult?>, private val onItemClick: (semesterResult) -> Unit): RecyclerView.Adapter<PlanSemesterAdapter.NonSubjectViewHolder>() {
var semesterList: List<semesterResult?> = semesterList
set(value) {
field = value
notifyDataSetChanged()
//데이터가 바뀌었다 알려줌.
}


override fun getItemCount(): Int {
return semesterList?.size ?: 0
return semesterList.size
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlanSemesterAdapter.NonSubjectViewHolder {
val itemBinding = ItemChooseSemesterBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return PlanSemesterAdapter.NonSubjectViewHolder(itemBinding)
return NonSubjectViewHolder(itemBinding)
}

override fun onBindViewHolder(holder: PlanSemesterAdapter.NonSubjectViewHolder, position: Int) {

val semesterInfo = semesterList[position]
if (semesterInfo != null) {
holder.itemBinding.planTimeSemesterItem.text = semesterInfo.hakkiText
}

holder.itemBinding.root.setOnClickListener {
if (semesterInfo != null) {
onItemClick(semesterInfo)
}
}
}


class NonSubjectViewHolder(val itemBinding: ItemChooseSemesterBinding) : RecyclerView.ViewHolder(itemBinding.root)
}
}
Loading

0 comments on commit e86564d

Please sign in to comment.