Skip to content

Commit

Permalink
[feat] #103 Project Search Server Connection
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-j0y committed Mar 20, 2022
1 parent f6cbf08 commit 41b2aeb
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 161 deletions.
12 changes: 6 additions & 6 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ interface ProjectService {
fun postApplyProject(
@Body body : RequestApplyProjectData
): Call<ResponseApplyProjectData>

@GET("/project/contact")
fun viewProject(
@Header("X-ACCESS-TOKEN") jwt: String,
@Header("X-REFRESH-TOKEN") refreshToken: String,
@Query("pj_num") projectNum : Int,
@Query("user_id") userId : String
): Call<ResponseViewIdeaData>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.infraandroid.category.model

data class ResponseViewIdeaData(
val code: Int,
val isSuccess: Boolean,
val message: String,
val result: Result
){
data class Result(
val hashtag: List<String>,
val pjLikeCount: Int,
val pj_categoryName: String,
val pj_content: String,
val pj_deadline: String,
val pj_endTerm: String,
val pj_header: String,
val pj_progress: String,
val pj_recruitPerson: String,
val pj_startTerm: String,
val pj_subCategoryName: String,
val pj_totalPerson: String,
val pj_views: Int,
val user_id: String,
val user_nickname: String,
val user_prPhoto: String
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class IdeaListAdapter(): RecyclerView.Adapter<RecyclerView.ViewHolder>() {
fun onBind(ideaListInfo: ResponseLookUpAllProjectData.Result){
ImageRound.roundAll(binding.projectImageView, 36f)
binding.projectList = ideaListInfo

itemView.setOnClickListener {
it.findNavController().navigate(R.id.action_idea_list_fragment_to_categoryViewIdeaFragment)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ 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.navigation.findNavController
import com.example.infraandroid.R
import com.example.infraandroid.databinding.FragmentCategoryIdeaBinding
import com.example.infraandroid.home.view.fragment.HomeFragmentDirections

// 카테고리의 아이디어 탭

Expand Down Expand Up @@ -37,6 +39,16 @@ class CategoryIdeaFragment : Fragment() {
mBinding?.lookMyIdeaButton?.setOnClickListener {
it.findNavController().navigate(R.id.action_category_fragment_to_myInfoMyIdeaFragment)
}

mBinding?.categorySearchImageView?.setOnClickListener {
if(mBinding?.categoryIdeaSearchEditText?.text.toString().length>=2){
val action = CategoryFragmentDirections.actionCategoryFragmentToIdeaListFragment(mBinding?.categoryIdeaSearchEditText?.text.toString())
it.findNavController().navigate(action)
}
else{
Toast.makeText(requireActivity(), "검색어 2글자 이상 입력해주세요", Toast.LENGTH_SHORT).show()
}
}
}

override fun onDestroyView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.example.infraandroid.category.view.fragment

import android.util.Log
import androidx.navigation.findNavController
import androidx.navigation.fragment.navArgs
import com.example.infraandroid.R
import com.example.infraandroid.category.model.ResponseLookUpAllProjectData
import com.example.infraandroid.category.view.adapter.IdeaListAdapter
Expand All @@ -25,40 +26,68 @@ class IdeaListFragment : BaseFragment<FragmentIdeaListBinding>(R.layout.fragment

}

override fun FragmentIdeaListBinding.onViewCreated(){
override fun FragmentIdeaListBinding.onViewCreated(){
binding.ideaListRecyclerView.adapter = ideaListAdapter
val args: IdeaListFragmentArgs by navArgs()
val searchKeyword = args.searchKeyword
Log.d(TAG, "onViewCreated: $searchKeyword")
if(searchKeyword==null){
val call: Call<ResponseLookUpAllProjectData> = ServiceCreator.projectService
.getLookUpAllProject(InfraApplication.prefs.getString("jwt","null"), InfraApplication.prefs.getString("userId", "null"))

val call: Call<ResponseLookUpAllProjectData> = ServiceCreator.projectService
.getLookUpAllProject(InfraApplication.prefs.getString("jwt","null"), InfraApplication.prefs.getString("userId", "null"))

call.enqueue(object : Callback<ResponseLookUpAllProjectData>{
override fun onResponse(
call: Call<ResponseLookUpAllProjectData>,
response: Response<ResponseLookUpAllProjectData>
) {
if(response.isSuccessful){
val body = response.body()
if (body != null) {
when(body.code){
1000 -> {
val data = body.result
if (data != null) {
ideaListAdapter.ideaList = data
call.enqueue(object : Callback<ResponseLookUpAllProjectData>{
override fun onResponse(
call: Call<ResponseLookUpAllProjectData>,
response: Response<ResponseLookUpAllProjectData>
) {
if(response.isSuccessful){
val body = response.body()
if (body != null) {
when(body.code){
1000 -> {
val data = body.result
if (data != null) {
ideaListAdapter.ideaList = data
}
ideaListAdapter.notifyDataSetChanged()
}
}
}
}
}
override fun onFailure(call: Call<ResponseLookUpAllProjectData>, t: Throwable) {
Log.d(TAG, "onFailure: $t")
}
})
}
else{
val call: Call<ResponseLookUpAllProjectData> = ServiceCreator.createProjectService
.searchProject(InfraApplication.prefs.getString("jwt","null"),searchKeyword,InfraApplication.prefs.getString("userId", "null"))
call.enqueue(object:Callback<ResponseLookUpAllProjectData>{
override fun onResponse(
call: Call<ResponseLookUpAllProjectData>,
response: Response<ResponseLookUpAllProjectData>
) {
if(response.isSuccessful){
val body = response.body()
if(body!=null){
when(body.code){
1000->{
val data = body.result
if(data!=null){
ideaListAdapter.ideaList = data
}
}
ideaListAdapter.notifyDataSetChanged()
}
}
}
}
}

override fun onFailure(call: Call<ResponseLookUpAllProjectData>, t: Throwable) {
Log.d(TAG, "onFailure: $t")
}

})


override fun onFailure(call: Call<ResponseLookUpAllProjectData>, t: Throwable) {
TODO("Not yet implemented")
}
})
}

binding.ideaListBackButton.setOnClickListener {
it.findNavController().navigate(R.id.action_idea_list_fragment_to_category_fragment)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.infraandroid.home.model

import com.example.infraandroid.category.model.ResponseLookUpAllProjectData
import com.example.infraandroid.id.model.RequestLoginData
import com.example.infraandroid.id.model.ResponseLoginData
import okhttp3.MultipartBody
Expand All @@ -15,4 +16,11 @@ interface CreateProjectService {
@Part ("jsonList") jsonList: RequestBody,
@Part images: MultipartBody.Part?,
): Call<ResponseCreateProjectData>

@GET("/project/inquiry?")
fun searchProject(
@Header("X-ACCESS-TOKEN") jwt: String,
@Query("search") searchKeyword : String,
@Query("user_id") userId : String
): Call<ResponseLookUpAllProjectData>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ data class ResponseCreateProjectData(
@SerializedName("pj_name")
val projectTitle : String
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.example.infraandroid.home.model

data class ResponseSearchProjectData(
val code: Int,
val isSuccess: Boolean,
val message: String,
val result: List<Result>
){
data class Result(
val hashtag: Any,
val pj_categoryName: String,
val pj_daysub: Int,
val pj_deadline: String,
val pj_header: String,
val pj_like: Int,
val pj_num: Int,
val pj_photo: List<String>,
val pj_progress: String,
val pj_recruit: String,
val pj_recruitPerson: Int,
val pj_totalPerson: Int,
val user_id: String
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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.navigation.findNavController
import com.example.infraandroid.util.InfraApplication
Expand Down Expand Up @@ -78,6 +79,16 @@ class HomeFragment : Fragment() {
mBinding?.homeBtnMakeNewProj?.setOnClickListener {
it.findNavController().navigate(R.id.action_home_fragment_to_createProjectFragment)
}

mBinding?.homeKeywordSearchIv?.setOnClickListener{
if(mBinding?.homeSearchEt?.text.toString().length>=2){
val action = HomeFragmentDirections.actionHomeFragmentToIdeaListFragment(mBinding?.homeSearchEt?.text.toString())
it.findNavController().navigate(action)
}
else{
Toast.makeText(requireActivity(), "검색어 2글자 이상 입력해주세요", Toast.LENGTH_SHORT).show()
}
}
}
override fun onDestroyView() {
mBinding = null
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/layout/fragment_category_idea.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/infra_blue_d">
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/infra_blue_d"
tools:context="com.example.infraandroid.category.view.fragment.CategoryIdeaFragment">

<ScrollView
android:layout_width="match_parent"
Expand All @@ -26,7 +27,7 @@
android:background="@drawable/rounded_edittext"
android:hint="@string/category_search_hint"
android:fontFamily="@font/noto_sans_kr_bold"
android:inputType="phone"
android:inputType="text"
android:textSize="11dp"
android:layout_marginTop="20dp"
app:layout_constraintTop_toTopOf="parent"
Expand Down
Loading

0 comments on commit 41b2aeb

Please sign in to comment.