-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'US02-CadastrarAlunoNaSala' into developer
- Loading branch information
Showing
10 changed files
with
280 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app/src/main/java/fga/mds/gpp/trezentos/DAO/AddStudentToClassRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package fga.mds.gpp.trezentos.DAO; | ||
|
||
import android.os.AsyncTask; | ||
import android.util.Log; | ||
|
||
import java.io.IOException; | ||
|
||
import fga.mds.gpp.trezentos.Model.UserAccount; | ||
import fga.mds.gpp.trezentos.Model.UserClass; | ||
|
||
import okhttp3.HttpUrl; | ||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.RequestBody; | ||
import okhttp3.Response; | ||
|
||
public class AddStudentToClassRequest extends AsyncTask<String, String, String>{ | ||
private final String student; | ||
private UserClass userClass; | ||
|
||
private String url = "https://trezentos-api.herokuapp.com/api/class/user/student"; | ||
|
||
public AddStudentToClassRequest (UserClass userClass, String student){ | ||
this.userClass = userClass; | ||
this.student = student; | ||
} | ||
|
||
@Override | ||
protected String doInBackground(String... params){ | ||
OkHttpClient client = new OkHttpClient(); | ||
|
||
String urlWithParameters = getUrlWithParameters(); | ||
|
||
RequestBody body = RequestBody.create(null, ""); | ||
Request request = new Request.Builder() | ||
.url(urlWithParameters) | ||
.put(body) | ||
.build(); | ||
|
||
try{ | ||
Response response = client.newCall(request).execute(); | ||
return response.body().string(); | ||
}catch (IOException e){ | ||
e.printStackTrace(); | ||
Log.i("LOG", "IOException in doInBackground method"); | ||
} | ||
return null; | ||
} | ||
|
||
private String getUrlWithParameters(){ | ||
HttpUrl.Builder builder = HttpUrl.parse(url).newBuilder(); | ||
|
||
builder.addQueryParameter("email", userClass.getOwnerEmail()); | ||
builder.addQueryParameter("name", userClass.getClassName()); | ||
builder.addQueryParameter("student", student); | ||
|
||
return builder.build().toString(); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/fga/mds/gpp/trezentos/Exception/UserClassException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package fga.mds.gpp.trezentos.Exception; | ||
|
||
|
||
public class UserClassException extends Exception{ | ||
|
||
public UserClassException(String message){ | ||
super(message); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.