Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
api 호출 변경, 업데이트 페이지 변경, 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
leehj050211 committed Nov 21, 2021
1 parent 43e1183 commit 1502af6
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 172 deletions.
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

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

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.zzz2757.bsm"
minSdk 21
targetSdk 30
versionCode 6
versionName "Beta 0.3.0"
versionCode 7
versionName "1.0.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/zzz2757/bsm/Api/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static Retrofit getApiClient(Context context){
if (retrofit == null){
retrofit = new Retrofit.Builder()
.client(client)
.baseUrl(Common.getBaseUrl())
.baseUrl(Common.getBaseUrl()+"api/")
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
Expand Down
58 changes: 26 additions & 32 deletions app/src/main/java/com/zzz2757/bsm/Api/ApiInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,55 @@
import com.zzz2757.bsm.GetterSetter.GetterSetter;
import com.zzz2757.bsm.GetterSetter.PostData;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.POST;
import retrofit2.http.Path;
import retrofit2.http.Streaming;
import retrofit2.http.Url;

public interface ApiInterface
{
@GET
@Streaming
Call<ResponseBody> downloadFile(@Url String url);
@GET("version/app/android")
Call<String> version();
@FormUrlEncoded
@POST("database")
Call<String> version(
@Field("command_type") String command_type,
@Field("os") String os,
@Field("app") String app
);
@FormUrlEncoded
@POST("database")
@POST("account/login")
Call<GetterSetter> login(
@Field("command_type") String command_type,
@Field("member_id") String member_id,
@Field("member_pw") String member_pw
);
@FormUrlEncoded
@POST("database")
@GET("board/{boardType}")
Call<String> board(
@Field("command_type") String command_type,
@Field("boardType") String boardType
@Path("boardType") String boardType
);
@FormUrlEncoded
@POST("database")
@GET("post/{boardType}/{postNo}")
Call<PostData> post(
@Field("command_type") String command_type,
@Field("boardType") String boardType,
@Field("post_no") int post_no
@Path("boardType") String boardType,
@Path("postNo") int postNo
);
@FormUrlEncoded
@POST("database")
@GET("comment/{boardType}/{postNo}")
Call<String> comment(
@Field("command_type") String command_type,
@Field("boardType") String boardType,
@Field("post_no") int post_no
@Path("boardType") String boardType,
@Path("postNo") int postNo
);
@FormUrlEncoded
@POST("database")
@POST("comment/{boardType}/{postNo}")
Call<GetterSetter> commentWrtie(
@Field("command_type") String command_type,
@Field("boardType") String boardType,
@Field("post_no") int post_no,
@Field("post_comment") String post_comment
@Path("boardType") String boardType,
@Path("postNo") int postNo,
@Field("comment") String post_comment
);
@FormUrlEncoded
@POST("database")
@POST("like/{boardType}/{postNo}")
Call<String> likeSend(
@Field("command_type") String command_type,
@Field("boardType") String boardType,
@Field("post_no") int post_no,
@Path("boardType") String boardType,
@Path("postNo") int postNo,
@Field("like") int like
);
}
8 changes: 4 additions & 4 deletions app/src/main/java/com/zzz2757/bsm/Board/BoardFrag.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

private void board(String boardType){
ApiInterface apiInterface = ApiClient.getApiClient(context).create(ApiInterface.class);
Call<String> call = apiInterface.board("board", boardType);
Call<String> call = apiInterface.board(boardType);
call.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
Expand All @@ -72,11 +72,11 @@ public void onResponse(Call<String> call, Response<String> response) {
e.printStackTrace();
}
if(getSet.getStatus()!=1){
ErrorCode.errorCode(context, getSet.getStatus());
ErrorCode.errorCode(context, getSet.getStatus(), getSet.getSubStatus());
}else{
try {
JSONObject jsonObject = new JSONObject(response.body().toString());
JSONArray arr_board = jsonObject.getJSONArray("arr_board");
JSONArray arr_board = jsonObject.getJSONArray("arrBoard");
for(int i=0;i<arr_board.length();i++){
JSONObject boardObject = arr_board.getJSONObject(i);
boardList.add(new BoardData(
Expand All @@ -88,7 +88,7 @@ public void onResponse(Call<String> call, Response<String> response) {
boardObject.getString("memberNickname"),
boardObject.getString("postDate"),
Integer.parseInt(boardObject.getString("postHit")),
Integer.parseInt(boardObject.getString("post_like"))
Integer.parseInt(boardObject.getString("postLike"))
));
}
} catch (JSONException e) {
Expand Down
46 changes: 23 additions & 23 deletions app/src/main/java/com/zzz2757/bsm/Board/BoardViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,24 @@ protected void onCreate(Bundle savedInstanceState) {
comment(boardType, postNo);
}

private void post(String boardType, int post_no){
private void post(String boardType, int postNo){
ApiInterface apiInterface = ApiClient.getApiClient(this).create(ApiInterface.class);
Call<PostData> call = apiInterface.post("post", boardType, post_no);
Call<PostData> call = apiInterface.post(boardType, postNo);
call.enqueue(new Callback<PostData>() {
@Override
public void onResponse(Call<PostData> call, Response<PostData> response) {
if(response.isSuccessful()&&response.body()!=null){
getSet.setStatus(response.body().getStatus());;
if(getSet.getStatus()!=1){
ErrorCode.errorCode(getApplicationContext(), getSet.getStatus());
ErrorCode.errorCode(getApplicationContext(), getSet.getStatus(), getSet.getSubStatus());
}else{
postNo_text.setText(""+post_no);
postTitle.setText(response.body().getPost_title());
memberNickname.setText(response.body().getMember_nickname());
postComments.setText(response.body().getPost_comments()+" 댓글");
postHit.setText("조회 "+response.body().getPost_hit());
postDate.setText(response.body().getPost_date());
postLike.setText(response.body().getPost_like());
postNo_text.setText(""+postNo);
postTitle.setText(response.body().getPostTitle());
memberNickname.setText(response.body().getMemberNickname());
postComments.setText(response.body().getPostComments()+" 댓글");
postHit.setText("조회 "+response.body().getPostHit());
postDate.setText(response.body().getPostDate());
postLike.setText(response.body().getPostLike());
if(response.body().getLike()>0){
post_like_btn.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.green_btn));
post_dislike_btn.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.gray));
Expand All @@ -126,7 +126,7 @@ public void onResponse(Call<PostData> call, Response<PostData> response) {
post_like_btn.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.gray));
post_dislike_btn.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.gray));
}
webView.loadDataWithBaseURL("https://bssm.kro.kr.", "<!DOCTYPE HTML><html lang=\"kr\"><head>" +webviewStyle+"</head><body>"+response.body().getPost_content()+"</body></html>", "text/html; charset=utf8", "UTF-8", null);
webView.loadDataWithBaseURL("https://bssm.kro.kr.", "<!DOCTYPE HTML><html lang=\"kr\"><head>" +webviewStyle+"</head><body>"+response.body().getPostContent()+"</body></html>", "text/html; charset=utf8", "UTF-8", null);
}
}
}
Expand All @@ -137,9 +137,9 @@ public void onFailure(Call<PostData> call, Throwable t) {
});
}

private void comment(String boardType, int post_no){
private void comment(String boardType, int postNo){
ApiInterface apiInterface = ApiClient.getApiClient(this).create(ApiInterface.class);
Call<String> call = apiInterface.comment("comment", boardType, post_no);
Call<String> call = apiInterface.comment(boardType, postNo);
call.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
Expand All @@ -151,11 +151,11 @@ public void onResponse(Call<String> call, Response<String> response) {
e.printStackTrace();
}
if(getSet.getStatus()!=1){
ErrorCode.errorCode(getApplicationContext(), getSet.getStatus());
ErrorCode.errorCode(getApplicationContext(), getSet.getStatus(), getSet.getSubStatus());
}else{
try {
JSONObject jsonObject = new JSONObject(response.body().toString());
JSONArray arr_comment = jsonObject.getJSONArray("arr_comment");
JSONArray arr_comment = jsonObject.getJSONArray("arrComment");
for(int i=0;i<arr_comment.length();i++){
JSONObject commentObject = arr_comment.getJSONObject(i);
commentList.add(new CommentData(
Expand All @@ -179,23 +179,23 @@ public void onFailure(Call<String> call, Throwable t) {
});
}

private void commentWrite(String boardType, int post_no, String comment, EditText edit_comment){
private void commentWrite(String boardType, int postNo, String comment, EditText edit_comment){
ApiInterface apiInterface = ApiClient.getApiClient(this).create(ApiInterface.class);
Call<GetterSetter> call = apiInterface.commentWrtie("comment_write", boardType, post_no, comment);
Call<GetterSetter> call = apiInterface.commentWrtie(boardType, postNo, comment);
call.enqueue(new Callback<GetterSetter>() {
@Override
public void onResponse(Call<GetterSetter> call, Response<GetterSetter> response) {
if(response.isSuccessful()&&response.body()!=null){
getSet.setStatus(response.body().getStatus());;
if(getSet.getStatus()!=1){
ErrorCode.errorCode(getApplicationContext(), getSet.getStatus());
ErrorCode.errorCode(getApplicationContext(), getSet.getStatus(), getSet.getSubStatus());
}else{
edit_comment.setText(null);
commentList = new ArrayList<>();
commentAdapter = new CommentAdapter(commentList, getApplicationContext());
recyclerView.removeAllViewsInLayout();
recyclerView.setAdapter(commentAdapter);
comment(boardType, post_no);
comment(boardType, postNo);
}
}
}
Expand All @@ -211,9 +211,9 @@ public void onClickSubmit(View view) {
commentWrite(boardType, postNo, edit_comment.getText().toString(), edit_comment);
}

private void likeSend(String boardType, int post_no, int like){
private void likeSend(String boardType, int postNo, int like){
ApiInterface apiInterface = ApiClient.getApiClient(this).create(ApiInterface.class);
Call<String> call = apiInterface.likeSend("like", boardType, post_no, like);
Call<String> call = apiInterface.likeSend(boardType, postNo, like);
call.enqueue(new Callback<String>() {
@Override
public void onResponse(Call<String> call, Response<String> response) {
Expand All @@ -225,11 +225,11 @@ public void onResponse(Call<String> call, Response<String> response) {
e.printStackTrace();
}
if(getSet.getStatus()!=1){
ErrorCode.errorCode(getApplicationContext(), getSet.getStatus());
ErrorCode.errorCode(getApplicationContext(), getSet.getStatus(), getSet.getSubStatus());
}else{
try {
JSONObject jsonObject = new JSONObject(response.body().toString());
postLike.setText(jsonObject.getString("post_like"));
postLike.setText(jsonObject.getString("postLike"));
if(Integer.parseInt(jsonObject.getString("like"))>0){
post_like_btn.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.green_btn));
post_dislike_btn.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.gray));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String boardType = bundle.getString("boardType");
int post_no = bundle.getInt("postNo");
if(post_no==0){
webView.loadUrl(Common.getBaseUrl() +"app/post_write/"+boardType);
int postNo = bundle.getInt("postNo");
if(postNo==0){
webView.loadUrl(Common.getBaseUrl() +"app/board/write/"+boardType);
}else{
webView.loadUrl(Common.getBaseUrl() +"app/post_write/"+boardType+"?post_no="+post_no);
webView.loadUrl(Common.getBaseUrl() +"app/board/write/"+boardType+"/"+postNo);
}
}

Expand Down
52 changes: 32 additions & 20 deletions app/src/main/java/com/zzz2757/bsm/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,48 @@
import android.widget.Toast;

public class ErrorCode{
public static void errorCode(Context context, int error_code){
String[] error_msg = {
public static void errorCode(Context context, int status, int subStatus){
String[][] error_msg = {
{
"서버와의 연결에 실패하였습니다.",
},
{
"정상 처리되었습니다.",
"정상적인 접근이 아닙니다.",
},
{
"서버에 문제가 발생하였습니다.",
"로그인 세션 저장에 실패하였습니다.",
"id 또는 password가 맞지 않습니다.",
"비밀번호 재입력이 맞지 않습니다.",
"이미 사용중인 id입니다.",
"이미 사용중인 닉네임입니다.",
"계정 인증이 필요합니다.",
"유효한 코드가 아닙니다.",
"만료된 코드입니다, 새로운 코드를 발급받아 주세요.",
"회원가입중 알 수 없는 문제가 발생하였습니다.",
"수정할 비밀번호 재입력이 맞지 않습니다.",
"비밀번호 수정에 실패하였습니다.",
"파일 업로드에 실패하였습니다.",
"게시글 작성에 실패하였습니다.",
},
{
"정상적인 접근이 아닙니다.",
"권한이 없습니다.",
"유효한 코드가 아닙니다.",
"멤버코드가 없습니다.",
"검색어가 없습니다.",
"잘못된 검색 대상입니다.",
"게시글 번호가 없습니다.",
"삭제된 게시글 입니다.",
"로그인후 이용 가능 합니다.",
"권한이 없습니다.",
"비밀번호 재설정이 필요합니다.",
"파일 업로드에 실패하였습니다.",
"게시글 작성에 실패하였습니다.",
"게시글 작성자가 아닙니다.",
"삭제된 게시글이거나 게시글이 없습니다.",
"작성자가 아닙니다.",
"학생정보가 맞지 않습니다.",
"인증코드 전송에 실패하였습니다.",
},
{
"계정이 정지되었습니다.",
"로그인후 이용 가능 합니다.",
"비밀번호 재설정이 필요합니다.",
"만료된 코드입니다, 회원가입된 계정으로 로그인해주세요.",
},
{
"id 또는 password가 맞지 않습니다.",
"비밀번호 재입력이 맞지 않습니다.",
"이미 사용중인 id입니다.",
"이미 사용중인 닉네임입니다.",
"수정할 비밀번호 재입력이 맞지 않습니다.",
},
};
Toast.makeText(context, "에러코드 "+error_code+"\n"+ error_msg[error_code], Toast.LENGTH_SHORT).show();
Toast.makeText(context, "에러코드 "+status+"_"+subStatus+"\n"+ error_msg[status][subStatus], Toast.LENGTH_SHORT).show();
}
}
12 changes: 5 additions & 7 deletions app/src/main/java/com/zzz2757/bsm/GetterSetter/GetterSetter.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.zzz2757.bsm.GetterSetter;

public class GetterSetter {
private int status;
private int status, subStatus;

public int getStatus(){
return status;
}
public void setStatus(int status){
this.status = status;
}
public int getStatus() {return status;}
public int getSubStatus() {return subStatus;}
public void setStatus(int status){ this.status = status;}
public void setSubStatus(int subStatus) {this.subStatus = subStatus;}
}
Loading

0 comments on commit 1502af6

Please sign in to comment.