Implement Syncing Modifications in Songs (not tested yet)
This commit is contained in:
parent
7a7b483ac2
commit
b7c62f2328
@ -5,6 +5,8 @@ import androidx.room.Ignore;
|
||||
import androidx.room.PrimaryKey;
|
||||
import core.notevault.data.sync.SyncStatus;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Entity(tableName = "music_notes")
|
||||
public class MusicNote {
|
||||
|
||||
@ -12,6 +14,7 @@ public class MusicNote {
|
||||
private long musicNoteId;
|
||||
private String serverID;
|
||||
private SyncStatus syncStatus;
|
||||
private LocalDateTime last_sync;
|
||||
|
||||
private String title;
|
||||
private String composer;
|
||||
@ -92,4 +95,13 @@ public class MusicNote {
|
||||
public void setSyncStatus(SyncStatus syncStatus) {
|
||||
this.syncStatus = syncStatus;
|
||||
}
|
||||
|
||||
public LocalDateTime getLast_sync() {
|
||||
|
||||
return last_sync;
|
||||
}
|
||||
|
||||
public void setLast_sync(LocalDateTime last_sync) {
|
||||
this.last_sync = last_sync;
|
||||
}
|
||||
}
|
||||
|
@ -62,4 +62,9 @@ public interface MusicNoteDAO {
|
||||
|
||||
@Query("UPDATE music_notes SET syncStatus = :status, serverID = :serverID WHERE musicNoteId = :localID")
|
||||
void storeSongSyncResponse(long localID, SyncStatus status, String serverID);
|
||||
|
||||
@Query("UPDATE music_notes SET syncStatus = :status, last_sync = :currentTime WHERE serverID IN (:serverIDs)")
|
||||
void storeSongSyncModifyResponses(List<String> serverIDs, SyncStatus status, LocalDateTime currentTime);
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package core.notevault.sync.synchronisation;
|
||||
import core.notevault.data.sync.SyncResponse;
|
||||
import core.notevault.sync.synchronisation.songs.creation.SongCreationBatchRequest;
|
||||
import core.notevault.sync.synchronisation.songs.creation.SongCreationBatchResponse;
|
||||
import core.notevault.sync.synchronisation.songs.modification.SongModificationBatchRequest;
|
||||
import core.notevault.sync.synchronisation.songs.modification.SongModificationBatchResponse;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.POST;
|
||||
@ -11,4 +13,7 @@ public interface SyncService {
|
||||
|
||||
@POST("/sync/songs/create")
|
||||
Call<SongCreationBatchResponse> performSongCreation(@Body SongCreationBatchRequest syncRequest);
|
||||
|
||||
@POST("/sync/songs/modify")
|
||||
Call<SongModificationBatchResponse> performSongModification(@Body SongModificationBatchRequest syncRequest);
|
||||
}
|
||||
|
@ -10,6 +10,9 @@ import core.notevault.sync.synchronisation.SyncService;
|
||||
import core.notevault.sync.synchronisation.songs.creation.SongCreationBatchRequest;
|
||||
import core.notevault.sync.synchronisation.songs.creation.SongCreationBatchResponse;
|
||||
import core.notevault.sync.synchronisation.songs.creation.SongCreationRequest;
|
||||
import core.notevault.sync.synchronisation.songs.modification.SongModificationBatchRequest;
|
||||
import core.notevault.sync.synchronisation.songs.modification.SongModificationBatchResponse;
|
||||
import core.notevault.sync.synchronisation.songs.modification.SongModificationRequest;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
@ -31,7 +34,7 @@ public class SongSyncWorker {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public SongCreationBatchRequest buildCreationRequest() {
|
||||
private SongCreationBatchRequest buildCreationRequest() {
|
||||
List<MusicNote> created_songs = database.getSongsWithSyncStatus(SyncStatus.CREATED);
|
||||
List<SongCreationRequest> songCreationRequests = new ArrayList<>();
|
||||
for(MusicNote musicNote : created_songs) {
|
||||
@ -60,4 +63,30 @@ public class SongSyncWorker {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private SongModificationBatchRequest buildModificationRequest() {
|
||||
List<MusicNote> modified_songs = database.getSongsWithSyncStatus(SyncStatus.MODIFIED);
|
||||
List<SongModificationRequest> songModificationRequests = new ArrayList<>();
|
||||
for(MusicNote musicNote : modified_songs) {
|
||||
songModificationRequests.add(new SongModificationRequest(musicNote.getServerID(), musicNote.getTitle(), musicNote.getComposer(), musicNote.getGenre(), musicNote.getYear()));
|
||||
}
|
||||
return new SongModificationBatchRequest(songModificationRequests);
|
||||
}
|
||||
|
||||
public void syncSongModifications() {
|
||||
SongModificationBatchRequest request = buildModificationRequest();
|
||||
syncService.performSongModification(request).enqueue(new Callback<SongModificationBatchResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<SongModificationBatchResponse> call, Response<SongModificationBatchResponse> response) {
|
||||
executorService.execute(() -> {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<SongModificationBatchResponse> call, Throwable throwable) {
|
||||
Toast.makeText(context, "Sync of Modified Songs failed", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package core.notevault.sync.synchronisation.songs.modification;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SongModificationBatchRequest {
|
||||
private List<SongModificationRequest> songs;
|
||||
|
||||
public SongModificationBatchRequest(List<SongModificationRequest> songs) {
|
||||
this.songs = songs;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package core.notevault.sync.synchronisation.songs.modification;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SongModificationBatchResponse {
|
||||
private List<String> updated_songs;
|
||||
|
||||
public SongModificationBatchResponse(List<String> updated_songs) {
|
||||
this.updated_songs = updated_songs;
|
||||
}
|
||||
|
||||
public List<String> getUpdated_songs() {
|
||||
return updated_songs;
|
||||
}
|
||||
|
||||
public void setUpdated_songs(List<String> updated_songs) {
|
||||
this.updated_songs = updated_songs;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package core.notevault.sync.synchronisation.songs.modification;
|
||||
|
||||
public class SongModificationRequest {
|
||||
private String serverID;
|
||||
private String title;
|
||||
private String composer;
|
||||
private String genre;
|
||||
private int year;
|
||||
|
||||
public SongModificationRequest(String serverID, String title, String composer, String genre, int year) {
|
||||
this.serverID = serverID;
|
||||
this.title = title;
|
||||
this.composer = composer;
|
||||
this.genre = genre;
|
||||
this.year = year;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user