-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: mentorship relation list and detail screen (#28)
- Loading branch information
1 parent
6fd4223
commit 878ef43
Showing
24 changed files
with
1,254 additions
and
8 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
20 changes: 20 additions & 0 deletions
20
app/src/main/java/org/systers/mentorship/remote/Constants.kt
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,20 @@ | ||
package org.systers.mentorship.remote | ||
|
||
/** | ||
* This [Enum] represents all the states of a Mentorship Relation. | ||
* These values are the same used in the backend. | ||
* PENDING - first applied state when a user sends a request | ||
* ACCEPTED - when the receiving user accepts the relation, which will start at the time | ||
* of acceptance | ||
* REJECTED - when the receiving user rejects the relation, no longer available to be accepted | ||
* CANCELLED - when any of the users of a current relation cancel a relation | ||
* COMPLETED - when a current relation passes the end date it becomes completed, | ||
* this happens automatically, does not require action from any user | ||
*/ | ||
enum class MentorshipRelationState(val value: Int) { | ||
PENDING(1), | ||
ACCEPTED(2), | ||
REJECTED(3), | ||
CANCELLED(4), | ||
COMPLETED(5) | ||
} |
50 changes: 50 additions & 0 deletions
50
app/src/main/java/org/systers/mentorship/remote/datamanager/RelationDataManager.kt
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,50 @@ | ||
package org.systers.mentorship.remote.datamanager | ||
|
||
import io.reactivex.Observable | ||
import org.systers.mentorship.remote.ApiManager | ||
import org.systers.mentorship.remote.responses.CustomResponse | ||
import org.systers.mentorship.remote.responses.MentorshipRelationResponse | ||
|
||
/** | ||
* This class represents the data manager related to Mentorship Relation API | ||
*/ | ||
class RelationDataManager { | ||
|
||
private val apiManager: ApiManager = ApiManager() | ||
|
||
/** | ||
* This will call a method of RelationService interface to fetch | ||
* all mentorship requests and relations | ||
* @return an Observable of a list of [MentorshipRelationResponse] | ||
*/ | ||
fun getAllMentorshipRelationsAndRequests(): Observable<List<MentorshipRelationResponse>> { | ||
return apiManager.getMentorshipRelationService().getAllMentorshipRelations() | ||
} | ||
|
||
/** | ||
* This will call a method from RelationService interface to accept a mentorship request | ||
* @param relationId id of the request being accepted | ||
* @return an Observable of [CustomResponse] | ||
*/ | ||
fun acceptMentorshipRelation(relationId: Int): Observable<CustomResponse> { | ||
return apiManager.getMentorshipRelationService().acceptMentorshipRelation(relationId) | ||
} | ||
|
||
/** | ||
* This will call a method from RelationService interface to reject a mentorship request | ||
* @param relationId id of the request being rejected | ||
* @return an Observable of [CustomResponse] | ||
*/ | ||
fun rejectMentorshipRelation(relationId: Int): Observable<CustomResponse> { | ||
return apiManager.getMentorshipRelationService().rejectMentorshipRelation(relationId) | ||
} | ||
|
||
/** | ||
* This will call a method from RelationService interface to delete a mentorship request | ||
* @param relationId id of the request being deleted | ||
* @return an Observable of [CustomResponse] | ||
*/ | ||
fun deleteMentorshipRelation(relationId: Int): Observable<CustomResponse> { | ||
return apiManager.getMentorshipRelationService().deleteMentorshipRelation(relationId) | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
app/src/main/java/org/systers/mentorship/remote/responses/MentorshipRelationResponse.kt
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,80 @@ | ||
package org.systers.mentorship.remote.responses | ||
|
||
import android.os.Parcel | ||
import android.os.Parcelable | ||
import com.google.gson.annotations.SerializedName | ||
|
||
/** | ||
* This data class represents partial information of user of the system. | ||
* This is used in APIs not directly related with Users, such as in responses | ||
* related to MentorshipRelation | ||
* | ||
* @param id identifier of the mentorship relation | ||
* @param actionUserId id of the user that sent the request for this mentorship relation | ||
* @param sentByMe indication if the current user was the action user | ||
* @param mentor user with mentor role in the relation | ||
* @param mentee user with mentee role in the relation | ||
* @param createdAtTimestamp date of creation unix timestamp | ||
* @param acceptedAtTimestamp date of acceptance unix timestamp | ||
* @param startAtTimestamp start date unix timestamp | ||
* @param endAtTimestamp end date unix timestamp | ||
* @param state state of the relation (@link to MentorshipRelationState) | ||
* @param notes notes related to the mentorship relation | ||
*/ | ||
data class MentorshipRelationResponse( | ||
val id: Int, | ||
@SerializedName("action_user_id") val actionUserId: Int, | ||
@SerializedName("sent_by_me") val sentByMe: Boolean, | ||
val mentor: RelationUserResponse, | ||
val mentee: RelationUserResponse, | ||
@SerializedName("creation_date") val createdAtTimestamp: Float, | ||
@SerializedName("accept_date") val acceptedAtTimestamp: Float, | ||
@SerializedName("start_date") val startAtTimestamp: Float, | ||
@SerializedName("end_date") val endAtTimestamp: Float, | ||
val state: Int, | ||
val notes: String | ||
) : Parcelable { | ||
constructor(parcel: Parcel) : this( | ||
parcel.readInt(), | ||
parcel.readInt(), | ||
parcel.readByte() != 0.toByte(), | ||
parcel.readParcelable(RelationUserResponse::class.java.classLoader), | ||
parcel.readParcelable(RelationUserResponse::class.java.classLoader), | ||
parcel.readFloat(), | ||
parcel.readFloat(), | ||
parcel.readFloat(), | ||
parcel.readFloat(), | ||
parcel.readInt(), | ||
parcel.readString()) | ||
|
||
override fun writeToParcel(parcel: Parcel, flags: Int) { | ||
parcel.writeInt(id) | ||
parcel.writeInt(actionUserId) | ||
parcel.writeByte(if (sentByMe) 1 else 0) | ||
parcel.writeParcelable(mentor, flags) | ||
parcel.writeParcelable(mentee, flags) | ||
parcel.writeFloat(createdAtTimestamp) | ||
parcel.writeFloat(acceptedAtTimestamp) | ||
parcel.writeFloat(startAtTimestamp) | ||
parcel.writeFloat(endAtTimestamp) | ||
parcel.writeInt(state) | ||
parcel.writeString(notes) | ||
} | ||
|
||
override fun describeContents(): Int { | ||
return 0 | ||
} | ||
|
||
/** | ||
* Class responsible for generating instances of this Parcelable class from a Parcel | ||
*/ | ||
companion object CREATOR : Parcelable.Creator<MentorshipRelationResponse> { | ||
override fun createFromParcel(parcel: Parcel): MentorshipRelationResponse { | ||
return MentorshipRelationResponse(parcel) | ||
} | ||
|
||
override fun newArray(size: Int): Array<MentorshipRelationResponse?> { | ||
return arrayOfNulls(size) | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/org/systers/mentorship/remote/responses/RelationUserResponse.kt
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,41 @@ | ||
package org.systers.mentorship.remote.responses | ||
|
||
import android.os.Parcel | ||
import android.os.Parcelable | ||
|
||
/** | ||
* This data class represents partial information of user of the system. | ||
* This is used in APIs not directly related with Users, such as in responses | ||
* related to MentorshipRelation | ||
* | ||
* @param id identifier of the user | ||
* @param name name of the user | ||
*/ | ||
data class RelationUserResponse (val id: Int, val name: String) : Parcelable { | ||
|
||
constructor(parcel: Parcel) : this( | ||
parcel.readInt(), | ||
parcel.readString()) | ||
|
||
override fun writeToParcel(parcel: Parcel, flags: Int) { | ||
parcel.writeInt(id) | ||
parcel.writeString(name) | ||
} | ||
|
||
override fun describeContents(): Int { | ||
return 0 | ||
} | ||
|
||
/** | ||
* Class responsible for generating instances of this Parcelable class from a Parcel | ||
*/ | ||
companion object CREATOR : Parcelable.Creator<RelationUserResponse> { | ||
override fun createFromParcel(parcel: Parcel): RelationUserResponse { | ||
return RelationUserResponse(parcel) | ||
} | ||
|
||
override fun newArray(size: Int): Array<RelationUserResponse?> { | ||
return arrayOfNulls(size) | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
app/src/main/java/org/systers/mentorship/remote/services/RelationService.kt
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,43 @@ | ||
package org.systers.mentorship.remote.services | ||
|
||
import io.reactivex.Observable | ||
import retrofit2.http.GET | ||
import retrofit2.http.PUT | ||
import retrofit2.http.Path | ||
import org.systers.mentorship.remote.responses.CustomResponse | ||
import org.systers.mentorship.remote.responses.MentorshipRelationResponse | ||
import retrofit2.http.DELETE | ||
|
||
/** | ||
* This interface describes the methods related to Mentorship Relation REST API | ||
*/ | ||
interface RelationService { | ||
|
||
/** | ||
* This function returns all mentorship requests and relations of the current user | ||
* @return an observable instance of a list of [MentorshipRelationResponse]s | ||
*/ | ||
@GET("mentorship_relations") | ||
fun getAllMentorshipRelations(): Observable<List<MentorshipRelationResponse>> | ||
|
||
/** | ||
* This function performs the acceptance of a mentorship request | ||
* @return an observable instance of [CustomResponse] with a proper error or success message | ||
*/ | ||
@PUT("mentorship_relation/{relation_id}/accept") | ||
fun acceptMentorshipRelation(@Path("relation_id") relationId: Int): Observable<CustomResponse> | ||
|
||
/** | ||
* This function performs the rejection of a mentorship request | ||
* @return an observable instance of [CustomResponse] with a proper error or success message | ||
*/ | ||
@PUT("mentorship_relation/{relation_id}/reject") | ||
fun rejectMentorshipRelation(@Path("relation_id") relationId: Int): Observable<CustomResponse> | ||
|
||
/** | ||
* This function performs the deletion of a mentorship request | ||
* @return an observable instance of [CustomResponse] with a proper error or success message | ||
*/ | ||
@DELETE("mentorship_relation/{relation_id}") | ||
fun deleteMentorshipRelation(@Path("relation_id") relationId: Int): Observable<CustomResponse> | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/org/systers/mentorship/utils/DateAndTimeUtils.kt
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,28 @@ | ||
package org.systers.mentorship.utils | ||
|
||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
|
||
const val DATE_FORMAT = "dd MMM yyyy" | ||
const val EXTENDED_DATE_FORMAT = "dd MMMM yyyy" | ||
const val MILLISECONDS_FACTOR = 1000L | ||
|
||
/** | ||
* Get [Date] from [unixTimestamp] in [String] format | ||
* @param unixTimestamp time in Unix timestamp format, in seconds | ||
* @param format date string format to use | ||
* @return date in string format | ||
*/ | ||
fun convertUnixTimestampIntoStr(unixTimestamp: Float, format: String) : String { | ||
|
||
val date = Date(getUnixTimestampInMilliseconds(unixTimestamp)) | ||
val sdf = SimpleDateFormat(format) | ||
return sdf.format(date) | ||
} | ||
|
||
/** | ||
* Convert Unix timestamp seconds to milliseconds [Long] format | ||
* @param unixTimestamp time in Unix timestamp format, in seconds | ||
* @return unix timestamp in milliseconds | ||
*/ | ||
fun getUnixTimestampInMilliseconds(unixTimestamp: Float) : Long = (unixTimestamp * MILLISECONDS_FACTOR).toLong() |
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.