feat: All entity and UserApi added

This commit is contained in:
aklyushova 2025-02-19 16:07:16 +03:00 committed by SunZar
parent 430e0bfcdf
commit 1344f247b1
12 changed files with 47 additions and 7 deletions

View File

@ -24,6 +24,7 @@ public class CallToConsumer <SOURCE, DEST> implements Callback<SOURCE> {
this.mapper = mapper;
}
@Override
public void onResponse(@NonNull Call<SOURCE> call, @NonNull Response<SOURCE> response) {
callback.accept(

View File

@ -1,7 +1,6 @@
package ru.myitschool.work.data;
import androidx.annotation.NonNull;
import androidx.camera.core.processing.SurfaceProcessorNode;
import java.util.ArrayList;
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.source.CredentialsDataSource;
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.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();
}
}

View File

@ -25,4 +25,6 @@ public class HistoryDto {
@SerializedName("type")
public String type;
}

View File

@ -13,4 +13,5 @@ public class ReaderDto {
@SerializedName("typeReader")
public Integer typeReader;
}

View File

@ -14,4 +14,5 @@ public class RoleDto {
public int status;
}

View File

@ -70,6 +70,7 @@ public class UserDto {
this.password = password;
}
@Nullable
public String getPhoto() {
return photo;

View File

@ -35,6 +35,7 @@ public class RetrofitFactory {
}
);
private final Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://10.0.2.2:8080/")
.client(client.build())

View File

@ -22,8 +22,8 @@ public interface UserApi {
@GET("api/user/login")
Call<Void> login();
@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}")
Call<History> getHistoryById(@Path("id") Integer id);
Call<HistoryDto> getHistoryById(@Path("id") Integer id);
}

View File

@ -4,7 +4,7 @@ import androidx.annotation.Nullable;
import com.google.gson.annotations.SerializedName;
public class HistioryEntity {
public class HistoryEntity {
@Nullable
@SerializedName("id")
public Integer id;
@ -54,7 +54,7 @@ public class HistioryEntity {
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.idUser = idUser;
this.time = time;

View File

@ -34,4 +34,6 @@ public class RoleEntity {
public void setStatus(int status) {
this.status = status;
}
}

View File

@ -30,4 +30,6 @@ public class Status<T>{
public Throwable getErrors() {
return errors;
}
}

View File

@ -82,5 +82,4 @@ public class UserEntity {
}