Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .idea/misc.xml

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

3 changes: 3 additions & 0 deletions app/src/main/java/com/example/infrastudy/APIData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ data class GetPostResponse(
@SerializedName("image_src") val imageSrc:String,
@SerializedName("user_id") val userid:String?
):Serializable
data class GetUserResponse(
@SerializedName("user_id") val userid:String
)

data class imgaeResponse(
@SerializedName("message") val message:String,
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/example/infrastudy/APIInterface.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ interface GetPostInterface{
):Response<ArrayList<GetPostResponse>?>
}

interface GetUserInterface{
@GET("/users/getid")
suspend fun GetUserRequest(
):Response<ArrayList<GetUserResponse>?>
}

interface DeleteInterface{
@DELETE("/board/{board_id}")
suspend fun DeleteRequest(
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/example/infrastudy/APIServiceImp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package com.example.infrastudy
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.create
import java.util.concurrent.TimeUnit

object APIServiceImp {
private const val BASE_URL = "http://133.186.159.229:80/"
private const val BASE_URL = "http://dev-api-team2.openinfra-kr.org/"
//"http://10.0.2.2"
//"http://133.186.223.119:80"

Expand All @@ -23,5 +24,6 @@ object APIServiceImp {
val getPostInterface =retrofit.create(GetPostInterface::class.java)
val imageInterface= retrofit.create(ImageInterface::class.java)
val deleteInterface= retrofit.create(DeleteInterface::class.java)
val getUserInterface=retrofit.create(GetUserInterface::class.java)
}

67 changes: 48 additions & 19 deletions app/src/main/java/com/example/infrastudy/LoginActivity.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.example.infrastudy
package com.example.infrastud


import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.webkit.CookieManager
import android.widget.Toast
import com.example.infrastudy.*
import com.example.infrastudy.databinding.ActivityLoginBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -18,6 +20,7 @@ import retrofit2.Response

class LoginActivity : AppCompatActivity() {
lateinit var binding: ActivityLoginBinding
var data=ArrayList<GetUserResponse>()

companion object {
const val TAG = "LoginActivty"
Expand All @@ -28,33 +31,56 @@ class LoginActivity : AppCompatActivity() {
binding = ActivityLoginBinding.inflate(layoutInflater)
setContentView(binding.root)
postInformation()
initData()
binding.userid.setText("fantasy7772")
binding.userpw.setText("123123k")
binding.username.setText("jinuk")
}

private fun initData(){
var response_GetUserRequest:Response<ArrayList<GetUserResponse>?>
CoroutineScope(Dispatchers.Main).launch {
withContext(Dispatchers.IO){
response_GetUserRequest= APIServiceImp.getUserInterface.GetUserRequest()
Log.i("userdata",response_GetUserRequest.body().toString())
}
response_GetUserRequest.body()?.let{data.addAll(it)}

}


}
private fun postInformation() {
binding.apply {
button3.setOnClickListener {
var response_Join: Response<JoinResponse>
CoroutineScope(Dispatchers.Main).launch {
withContext(Dispatchers.IO) {
response_Join = APIServiceImp.joinInterface.postJoinRequest(
userid = userid.text.toString(),
userpw = userpw.text.toString(),
username = username.text.toString()
)
if (response_Join != null) {
Log.i("message", "join success")
var check=true
for(i in 0 until data.count()){
if(data[i].userid==binding.userid.text.toString()){
Toast.makeText(this@LoginActivity, "중복된 ID 입니다", Toast.LENGTH_SHORT).show()
check=false
}
}
if(check==true) {
var response_Join: Response<JoinResponse>
CoroutineScope(Dispatchers.Main).launch {
withContext(Dispatchers.IO) {
response_Join = APIServiceImp.joinInterface.postJoinRequest(
userid = userid.text.toString(),
userpw = userpw.text.toString(),
username = username.text.toString()
)
if (response_Join != null) {
Log.i("message", "join success")

} else {
Log.i("message", "join failed")
} else {
Log.i("message", "join failed")
}
}
if (response_Join != null) {
val i = Intent(this@LoginActivity, MainActivity::class.java)
i.putExtra("cur_user", userid.text.toString())
startActivity(i)
}
}
if(response_Join!=null){
val i= Intent(this@LoginActivity, MainActivity::class.java)
i.putExtra("cur_user", userid.text.toString())
startActivity(i)
}
}
}
Expand All @@ -72,11 +98,14 @@ class LoginActivity : AppCompatActivity() {
Log.i("message", "login failed")
}
}
if(response_Login!=null){
if(response_Login.body()!!.msg =="success"){
val i= Intent(this@LoginActivity, MainActivity::class.java)
i.putExtra("cur_user", userid.text.toString())
startActivity(i)
}
else{
Toast.makeText(this@LoginActivity, "로그인 실패", Toast.LENGTH_SHORT).show()
}
}
}
}
Expand Down