feat: All entity and UserApi added
This commit is contained in:
parent
430e0bfcdf
commit
1344f247b1
@ -24,6 +24,7 @@ public class CallToConsumer <SOURCE, DEST> implements Callback<SOURCE> {
|
|||||||
this.mapper = mapper;
|
this.mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<SOURCE> call, @NonNull Response<SOURCE> response) {
|
public void onResponse(@NonNull Call<SOURCE> call, @NonNull Response<SOURCE> response) {
|
||||||
callback.accept(
|
callback.accept(
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package ru.myitschool.work.data;
|
package ru.myitschool.work.data;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.camera.core.processing.SurfaceProcessorNode;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -12,7 +11,7 @@ import ru.myitschool.work.data.dto.UserDto;
|
|||||||
import ru.myitschool.work.data.network.RetrofitFactory;
|
import ru.myitschool.work.data.network.RetrofitFactory;
|
||||||
import ru.myitschool.work.data.source.CredentialsDataSource;
|
import ru.myitschool.work.data.source.CredentialsDataSource;
|
||||||
import ru.myitschool.work.data.source.UserApi;
|
import ru.myitschool.work.data.source.UserApi;
|
||||||
import ru.myitschool.work.domain.entities.HistioryEntity;
|
import ru.myitschool.work.domain.entities.HistoryEntity;
|
||||||
import ru.myitschool.work.domain.entities.Status;
|
import ru.myitschool.work.domain.entities.Status;
|
||||||
import ru.myitschool.work.domain.entities.UserEntity;
|
import ru.myitschool.work.domain.entities.UserEntity;
|
||||||
|
|
||||||
@ -53,8 +52,39 @@ public class UserResponseImpl {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void getAllUserHistory(@NonNull Integer id, @NonNull Consumer<Status<List<UserEntity>>> callback) {
|
||||||
|
userApi.getAllUserHistory(id).enqueue(new CallToConsumer<>(
|
||||||
|
callback,
|
||||||
|
historiesDto -> {
|
||||||
|
ArrayList<HistoryEntity> result = new ArrayList<>(historiesDto.size());
|
||||||
|
for (HistoryDto history : historiesDto) {
|
||||||
|
final Integer id1 = history.id;
|
||||||
|
final Integer idUser = history.idUser;
|
||||||
|
final Long time = history.time;
|
||||||
|
final String nameReader = history.nameReader;
|
||||||
|
final String type = history.type;
|
||||||
|
if (idUser != null && id1 != null){
|
||||||
|
result.add(new HistoryEntity(id1, idUser, time, nameReader, type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void login(@NonNull String username, @NonNull String password, Consumer<Status<Void>> callback) {
|
||||||
|
credentialsDataSource.updateLogin(username, password);
|
||||||
|
userApi = RetrofitFactory.getInstance().getUserApi();
|
||||||
|
userApi.login().enqueue(new CallToConsumer<>(
|
||||||
|
callback,
|
||||||
|
dto -> null
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void logout() {
|
||||||
|
credentialsDataSource.logout();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,4 +25,6 @@ public class HistoryDto {
|
|||||||
@SerializedName("type")
|
@SerializedName("type")
|
||||||
public String type;
|
public String type;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,4 +13,5 @@ public class ReaderDto {
|
|||||||
@SerializedName("typeReader")
|
@SerializedName("typeReader")
|
||||||
public Integer typeReader;
|
public Integer typeReader;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,4 +14,5 @@ public class RoleDto {
|
|||||||
public int status;
|
public int status;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,7 @@ public class UserDto {
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getPhoto() {
|
public String getPhoto() {
|
||||||
return photo;
|
return photo;
|
||||||
|
@ -35,6 +35,7 @@ public class RetrofitFactory {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
private final Retrofit retrofit = new Retrofit.Builder()
|
private final Retrofit retrofit = new Retrofit.Builder()
|
||||||
.baseUrl("http://10.0.2.2:8080/")
|
.baseUrl("http://10.0.2.2:8080/")
|
||||||
.client(client.build())
|
.client(client.build())
|
||||||
|
@ -22,8 +22,8 @@ public interface UserApi {
|
|||||||
@GET("api/user/login")
|
@GET("api/user/login")
|
||||||
Call<Void> login();
|
Call<Void> login();
|
||||||
@GET("api/history/user/{id}")
|
@GET("api/history/user/{id}")
|
||||||
Call<List<History>> getAllUserHistory(@Path("id") Integer id);
|
Call<List<HistoryDto>> getAllUserHistory(@Path("id") Integer id);
|
||||||
@GET("api/history/{id}")
|
@GET("api/history/{id}")
|
||||||
Call<History> getHistoryById(@Path("id") Integer id);
|
Call<HistoryDto> getHistoryById(@Path("id") Integer id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import androidx.annotation.Nullable;
|
|||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
public class HistioryEntity {
|
public class HistoryEntity {
|
||||||
@Nullable
|
@Nullable
|
||||||
@SerializedName("id")
|
@SerializedName("id")
|
||||||
public Integer id;
|
public Integer id;
|
||||||
@ -54,7 +54,7 @@ public class HistioryEntity {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HistioryEntity(@Nullable Integer id, @Nullable Integer idUser, @Nullable Long time, @Nullable String nameReader, @Nullable String type) {
|
public HistoryEntity(@Nullable Integer id, @Nullable Integer idUser, @Nullable Long time, @Nullable String nameReader, @Nullable String type) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.idUser = idUser;
|
this.idUser = idUser;
|
||||||
this.time = time;
|
this.time = time;
|
@ -34,4 +34,6 @@ public class RoleEntity {
|
|||||||
public void setStatus(int status) {
|
public void setStatus(int status) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,4 +30,6 @@ public class Status<T>{
|
|||||||
public Throwable getErrors() {
|
public Throwable getErrors() {
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,5 +82,4 @@ public class UserEntity {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user