Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] データクラスの変数名とJSONキー名の統一 #106

Merged
merged 14 commits into from
Oct 23, 2023
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation "androidx.browser:browser:1.4.0"
implementation 'androidx.browser:browser:1.4.0'
implementation 'com.google.android:flexbox:1.1.0'
implementation 'com.github.bumptech.glide:glide:4.4.0'
kapt 'com.github.bumptech.glide:compiler:4.4.0'
Expand All @@ -57,7 +57,7 @@ dependencies {
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.code.gson:gson:2.9.0'
implementation("com.squareup.okhttp3:logging-interceptor:4.11.0")
implementation 'com.squareup.okhttp3:logging-interceptor:4.11.0'

// coroutine
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1'
Expand All @@ -70,9 +70,9 @@ dependencies {

implementation 'com.github.bumptech.glide:glide:4.13.0'

implementation "com.squareup.moshi:moshi-kotlin:1.12.0"
kapt "com.squareup.moshi:moshi-kotlin-codegen:1.12.0"
implementation 'com.squareup.moshi:moshi-kotlin:1.12.0'
kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.12.0'

//coil
implementation "io.coil-kt:coil:1.1.1"
implementation 'io.coil-kt:coil:1.1.1'
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.example.funcy_portfolio_android.model.data

data class AuthData(
val code: String,
val userID: String
val userID: String,
val code: String
)

data class UserIdData(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.funcy_portfolio_android.model.data

/**
* マイページ (mypage) のデータクラス
* @param works: 中身はWorkDataList.ktを参照してください
*/
data class MyPageData(
val icon: String,
val header: String,
val user_description: String,
val sns: List<String>,
val group: List<String>,
val skills: List<String>,
val displayName: String,
val works: WorkDataList
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.example.funcy_portfolio_android.model.data

/**
* サインアップ(ユーザ情報登録) (signup) のデータクラス
*/
data class SignupData(
val icon: String,
val familyName: String,
val course: String,
val displayName: String,
val firstName: String,
val grade: String,
val icon: String,
val mail: String,
val password: String
val password: String,
val grade: String,
val course: String,
val displayName: String
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
package com.example.funcy_portfolio_android.model.data

/**
* 作品一覧画面 (main) のデータクラス
*/

data class WorkDataList(
val work_id: Int,
val works: List<WorkData>
)
data class WorkData(
val workID: String,
val userID: String,
val user_name: String,
val title: String,
val images: String
val thumbnail: String,
val description: String,
val icon: String,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「,」いらない,あっても動くんだっけ?(記憶力なし)

)
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
package com.example.funcy_portfolio_android.model.data

data class WorkData(
/**
* 作品詳細 (workDetail) のデータクラス
*/
data class WorkDetails(
val title: String,
val description: String,
val thumbnail: String,
val user_icon: String,
val user_name: String,
val userID: String,
val images: List<ImageData>,
val URL: String,
val work_url: String,
val movie_url: String,
val tags: List<TagData>,
val group: String?,
val security: Int,
)

data class ImageData(
val Image: String
val image: String
)

data class TagData(
val Tag: String
val tag: String
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.funcy_portfolio_android.model.repository

import com.example.funcy_portfolio_android.model.data.WorkData
import com.example.funcy_portfolio_android.model.data.WorkDetails
import com.example.funcy_portfolio_android.network.ApiService
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.withContext
Expand All @@ -9,7 +9,7 @@ import java.io.IOException
class WorkRepository() {
private val service = ApiService.service

suspend fun registerWork(work: WorkData): String? {
suspend fun registerWork(work: WorkDetails): String? {
val data = work
var res = ""

Expand All @@ -26,7 +26,8 @@ class WorkRepository() {
return res
}

suspend fun getWorkDetail(token: String, workId:String) = service.getWorkDetail(token = token, workId = workId)
suspend fun getWorkDetail(token: String, workId: String) =
service.getWorkDetail(token = token, workId = workId)

suspend fun getWork(token: String) = service.getWorks(token = token)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.example.funcy_portfolio_android.network
import com.example.funcy_portfolio_android.model.data.AuthData
import com.example.funcy_portfolio_android.model.data.SignupData
import com.example.funcy_portfolio_android.model.data.UserIdData
import com.example.funcy_portfolio_android.model.data.WorkData
import com.example.funcy_portfolio_android.model.data.WorkDataList
import com.example.funcy_portfolio_android.model.data.WorkDetails
import retrofit2.Call
import retrofit2.Response
import retrofit2.http.*
Expand All @@ -14,14 +14,14 @@ interface FuncyApi {
/* 作品の投稿(個人) */
@Headers("token:Token1")
@POST("work")
fun registerWorkData(@Body work: WorkData): Call<WorkData>
fun registerWorkData(@Body work: WorkDetails): Call<WorkDetails>

//作品詳細取得
@GET("work/{workID}")
suspend fun getWorkDetail(
@Header("token") token: String,
@Path("workID") workId: String
): WorkData
): WorkDetails

//登録データ送信
@POST("sign/up")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AuthenticationViewModel : ViewModel() {
viewModelScope.launch {
try {
val response = userRepository.userAuthentication(
AuthData(inputCode.value!!, userId)
AuthData(userId, inputCode.value!!)
)
if (response.isSuccessful) {
Log.i("Authentication", "認証が完了しました${response.body()}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CardAdapterBefore (private val worklist: List<WorkDataList>) : RecyclerVie

override fun onBindViewHolder(viewHolder: CardAdapterBefore.ViewHolder, position: Int) {
val work = worklist[position]
viewHolder.image.setImageResource(work.work_id)
viewHolder.image.setImageResource(work.workID)
viewHolder.title.text = work.title
}
override fun getItemCount() = worklist.size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import androidx.recyclerview.widget.RecyclerView
import com.example.funcy_portfolio_android.databinding.CreateCardBinding
import com.example.funcy_portfolio_android.model.data.WorkDataList

class CardAdapter:ListAdapter<WorkDataList, CardAdapter.WorkDataViewHolder>(DiffCallBack){
class CardAdapter : ListAdapter<WorkDataList, CardAdapter.WorkDataViewHolder>(DiffCallBack) {

class WorkDataViewHolder(private var binding: CreateCardBinding):
RecyclerView.ViewHolder(binding.root){
fun bind(workDataList: WorkDataList){
binding.work = workDataList
binding.executePendingBindings()
}
}
class WorkDataViewHolder(private var binding: CreateCardBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(workDataList: WorkDataList) {
binding.work = workDataList
binding.executePendingBindings()
}
}

companion object DiffCallBack : DiffUtil.ItemCallback<WorkDataList>(){
companion object DiffCallBack : DiffUtil.ItemCallback<WorkDataList>() {
override fun areItemsTheSame(oldItem: WorkDataList, newItem: WorkDataList): Boolean {
return oldItem.work_id == newItem.work_id
return oldItem.workID == newItem.workID
}

override fun areContentsTheSame(oldItem: WorkDataList, newItem: WorkDataList): Boolean {
return oldItem.images == newItem.images
return oldItem.thumbnail == newItem.thumbnail
}

}
Expand All @@ -45,9 +45,6 @@ class CardAdapter:ListAdapter<WorkDataList, CardAdapter.WorkDataViewHolder>(Diff
}





//@BindingAdapter
//fun bindArticle(article: ImageView, articleUrl: String?){
// articleUrl?.let{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.example.funcy_portfolio_android.ui.main

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.funcy_portfolio_android.model.data.WorkDataList
import com.example.funcy_portfolio_android.model.repository.WorkRepository
import com.example.funcy_portfolio_android.ui.workRegister.WorkRegisterBottomSheet.Companion.TAG
import kotlinx.coroutines.launch

/*FUNCYサーバーとの接続を確認するステータスを定義*/
enum class FuncyApiStatus { LOADING, ERROR, DONE }
Expand All @@ -21,24 +25,24 @@ class MainViewModel : ViewModel() {
private val _status = MutableLiveData<FuncyApiStatus>()
val status: LiveData<FuncyApiStatus> = _status

// init {
// getWorks("Token1")
// }

// private fun getWorks(token: String) {
// viewModelScope.launch {
// _status.value = FuncyApiStatus.LOADING
// try {
// _works.value = repository.service.getWorks(token)
// _status.value = FuncyApiStatus.DONE
// Log.d(TAG, "通信出来たよ")
// } catch (e: Exception) {
// _status.value = FuncyApiStatus.ERROR
// _works.value = listOf()
// Log.e(TAG, e.message.toString())
// }
//
// }
// }
init {
getWorks("Token1")
}

private fun getWorks(token: String) {
viewModelScope.launch {
_status.value = FuncyApiStatus.LOADING
try {
_works.value = WorkRepository().getWork(token)
_status.value = FuncyApiStatus.DONE
Log.d(TAG, "通信出来たよ")
} catch (e: Exception) {
_status.value = FuncyApiStatus.ERROR
_works.value = listOf()
Log.e(TAG, e.message.toString())
}

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ class SignupViewModel : ViewModel() {
try {
val res =userRepository.userRegistration(
SignupData(
"noIcon",
familyName.value!!,
course,
displayName.value!!,
firstName.value!!,
grade,
"noIcon",
sendMailAddress,
password.value!!
password.value!!,
grade,
course,
displayName.value!!,
)
)
if (res.isSuccessful) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class WorkDetailFragment : Fragment() {
})

viewModel.images.observe(viewLifecycleOwner, Observer {
Glide.with(this).load(it[0].Image).error(R.drawable.img_work_detail_thumbnail).into(binding.imgThumbnail)
Glide.with(this).load(it[0].image).error(R.drawable.img_work_detail_thumbnail).into(binding.imgThumbnail)
})

viewModel.workDetailStatus.observe(viewLifecycleOwner, Observer { status ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.funcy_portfolio_android.model.data.ImageData
import com.example.funcy_portfolio_android.model.data.TagData
import com.example.funcy_portfolio_android.model.data.WorkData
import com.example.funcy_portfolio_android.model.data.WorkDetails
import com.example.funcy_portfolio_android.model.repository.WorkRepository
import com.google.android.material.chip.Chip
import com.google.android.material.chip.ChipGroup
Expand All @@ -29,8 +29,8 @@ class WorkDetailViewModel : ViewModel() {
val userName: LiveData<String> = _userName

//ここから作品詳細
private val _work = MutableLiveData<WorkData>()
val work: LiveData<WorkData> = _work
private val _work = MutableLiveData<WorkDetails>()
val work: LiveData<WorkDetails> = _work

private val _workDetailStatus = MutableLiveData<WorkApiStatus>()
val workDetailStatus: LiveData<WorkApiStatus> = _workDetailStatus
Expand Down Expand Up @@ -79,7 +79,7 @@ class WorkDetailViewModel : ViewModel() {
chipGroup.removeAllViews()
_tagList.value?.forEach { tag ->
val chip = Chip(context)
chip.text = tag.Tag
chip.text = tag.tag
chipGroup.addView(chip)
}
}
Expand All @@ -91,7 +91,7 @@ class WorkDetailViewModel : ViewModel() {
_explanation.value = workValue.description
_tagList.value = workValue.tags
_youtubeUrl.value = workValue.movie_url
_githubUrl.value = workValue.URL
_githubUrl.value = workValue.work_url
}

//Web遷移系の処理//////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.funcy_portfolio_android.model.data.ImageData
import com.example.funcy_portfolio_android.model.data.TagData
import com.example.funcy_portfolio_android.model.data.WorkData
import com.example.funcy_portfolio_android.model.data.WorkDetails
import com.example.funcy_portfolio_android.model.repository.WorkRepository
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -85,7 +85,7 @@ class WorkRegisterViewModel : ViewModel() {
viewModelScope.launch {
val postTagList = stringTagListToTagList(tags)
res = workRepository.registerWork(
WorkData(
WorkDetails(
title,
description,
listOf(ImageData("")),
Expand Down
Loading