-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into enhancement-167-edit-user-role-01
- Loading branch information
Showing
30 changed files
with
1,263 additions
and
559 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright (c) 2023 North Seattle College Application Development Department | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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
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
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/example/belindas_closet/data/network/auth/ArchiveService.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,42 @@ | ||
package com.example.belindas_closet.data.network.auth | ||
|
||
import com.example.belindas_closet.MainActivity | ||
import com.example.belindas_closet.data.network.dto.auth_dto.ArchiveRequest | ||
import com.example.belindas_closet.data.network.dto.auth_dto.ArchiveResponse | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.engine.android.Android | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.client.plugins.logging.DEFAULT | ||
import io.ktor.client.plugins.logging.LogLevel | ||
import io.ktor.client.plugins.logging.Logger | ||
import io.ktor.client.plugins.logging.Logging | ||
import io.ktor.serialization.kotlinx.json.json | ||
import kotlinx.serialization.json.Json | ||
|
||
interface ArchiveService { | ||
suspend fun archive(archiveRequest: ArchiveRequest) : ArchiveResponse? | ||
|
||
companion object { | ||
fun create() : ArchiveService { | ||
return ArchiveServiceImpl( | ||
client = HttpClient(Android) { | ||
install(ContentNegotiation) { | ||
json(Json { | ||
prettyPrint = true | ||
isLenient = true | ||
ignoreUnknownKeys = true | ||
}) | ||
} | ||
install (Logging) { | ||
level = LogLevel.ALL | ||
logger = Logger.DEFAULT | ||
} | ||
}, | ||
getToken = suspend { | ||
MainActivity.getPref().getString("token", "") ?: "" | ||
} | ||
) | ||
} | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/example/belindas_closet/data/network/auth/ArchiveServiceImpl.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,48 @@ | ||
package com.example.belindas_closet.data.network.auth | ||
|
||
import com.example.belindas_closet.data.network.HttpRoutes | ||
import com.example.belindas_closet.data.network.dto.auth_dto.ArchiveRequest | ||
import com.example.belindas_closet.data.network.dto.auth_dto.ArchiveResponse | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.plugins.ClientRequestException | ||
import io.ktor.client.plugins.RedirectResponseException | ||
import io.ktor.client.plugins.ServerResponseException | ||
import io.ktor.client.request.header | ||
import io.ktor.client.request.put | ||
import io.ktor.client.request.url | ||
import io.ktor.http.ContentType | ||
import io.ktor.http.HttpHeaders | ||
import io.ktor.util.InternalAPI | ||
import kotlinx.serialization.json.Json | ||
|
||
class ArchiveServiceImpl ( | ||
private val client: HttpClient, | ||
private val getToken: suspend () -> String | ||
) : ArchiveService { | ||
@OptIn(InternalAPI::class) | ||
override suspend fun archive(archiveRequest: ArchiveRequest): ArchiveResponse? { | ||
return try { | ||
val token = getToken() | ||
val response = client.put { | ||
url("${HttpRoutes.ARCHIVE}/${archiveRequest.id}") | ||
header(HttpHeaders.ContentType, ContentType.Application.Json.toString()) | ||
header(HttpHeaders.Authorization, "Bearer $token") | ||
body = Json.encodeToString(ArchiveRequest.serializer(), archiveRequest) | ||
} | ||
response.body() | ||
} catch (e: RedirectResponseException) { | ||
println("Error: ${e.response.status.description}") | ||
null | ||
} catch (e: ClientRequestException) { | ||
println("Error: ${e.response.status.description}") | ||
null | ||
} catch (e: ServerResponseException) { | ||
println("Error: ${e.response.status.description}") | ||
null | ||
} catch (e: Exception) { | ||
println("Error: ${e.message}") | ||
null | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
app/src/main/java/com/example/belindas_closet/data/network/auth/DeleteService.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,42 @@ | ||
package com.example.belindas_closet.data.network.auth | ||
|
||
import com.example.belindas_closet.MainActivity | ||
import com.example.belindas_closet.data.network.dto.auth_dto.DeleteRequest | ||
import com.example.belindas_closet.data.network.dto.auth_dto.DeleteResponse | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.engine.android.Android | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.client.plugins.logging.DEFAULT | ||
import io.ktor.client.plugins.logging.LogLevel | ||
import io.ktor.client.plugins.logging.Logger | ||
import io.ktor.client.plugins.logging.Logging | ||
import io.ktor.serialization.kotlinx.json.json | ||
import kotlinx.serialization.json.Json | ||
|
||
interface DeleteService { | ||
suspend fun delete(deleteRequest: DeleteRequest) : DeleteResponse? | ||
|
||
companion object { | ||
fun create() : DeleteService { | ||
return DeleteServiceImpl( | ||
client = HttpClient(Android) { | ||
install(ContentNegotiation) { | ||
json(Json { | ||
prettyPrint = true | ||
isLenient = true | ||
ignoreUnknownKeys = true | ||
}) | ||
} | ||
install (Logging) { | ||
level = LogLevel.ALL | ||
logger = Logger.DEFAULT | ||
} | ||
}, | ||
getToken = suspend { | ||
MainActivity.getPref().getString("token", "") ?: "" | ||
} | ||
) | ||
} | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/example/belindas_closet/data/network/auth/DeleteServiceImpl.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,48 @@ | ||
package com.example.belindas_closet.data.network.auth | ||
|
||
import com.example.belindas_closet.data.network.HttpRoutes | ||
import com.example.belindas_closet.data.network.dto.auth_dto.DeleteRequest | ||
import com.example.belindas_closet.data.network.dto.auth_dto.DeleteResponse | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.plugins.ClientRequestException | ||
import io.ktor.client.plugins.RedirectResponseException | ||
import io.ktor.client.plugins.ServerResponseException | ||
import io.ktor.client.request.delete | ||
import io.ktor.client.request.header | ||
import io.ktor.client.request.url | ||
import io.ktor.http.ContentType | ||
import io.ktor.http.HttpHeaders | ||
import io.ktor.util.InternalAPI | ||
import kotlinx.serialization.json.Json | ||
|
||
class DeleteServiceImpl ( | ||
private val client: HttpClient, | ||
private val getToken: suspend () -> String | ||
) : DeleteService { | ||
@OptIn(InternalAPI::class) | ||
override suspend fun delete(deleteRequest: DeleteRequest): DeleteResponse? { | ||
return try { | ||
val token = getToken() | ||
val response = client.delete { | ||
url("${HttpRoutes.DELETE}/${deleteRequest.id}") | ||
header(HttpHeaders.ContentType, ContentType.Application.Json.toString()) | ||
header(HttpHeaders.Authorization, "Bearer $token") | ||
body = Json.encodeToString(DeleteRequest.serializer(), deleteRequest) | ||
} | ||
response.body() | ||
} catch (e: RedirectResponseException) { | ||
println("Error: ${e.response.status.description}") | ||
null | ||
} catch (e: ClientRequestException) { | ||
println("Error: ${e.response.status.description}") | ||
null | ||
} catch (e: ServerResponseException) { | ||
println("Error: ${e.response.status.description}") | ||
null | ||
} catch (e: Exception) { | ||
println("Error: ${e.message}") | ||
null | ||
} | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/example/belindas_closet/data/network/dto/auth_dto/ArchiveRequest.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,13 @@ | ||
package com.example.belindas_closet.data.network.dto.auth_dto | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ArchiveRequest( | ||
@SerialName("id") | ||
val id: String, | ||
|
||
@SerialName("role") | ||
val role: Role | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/example/belindas_closet/data/network/dto/auth_dto/ArchiveResponse.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,10 @@ | ||
package com.example.belindas_closet.data.network.dto.auth_dto | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ArchiveResponse( | ||
@SerialName("isSold") | ||
val isSold: Boolean = false | ||
) |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/example/belindas_closet/data/network/dto/auth_dto/DeleteRequest.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,13 @@ | ||
package com.example.belindas_closet.data.network.dto.auth_dto | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class DeleteRequest( | ||
@SerialName("id") | ||
val id: String, | ||
|
||
@SerialName("role") | ||
val role: Role | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/example/belindas_closet/data/network/dto/auth_dto/DeleteResponse.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,10 @@ | ||
package com.example.belindas_closet.data.network.dto.auth_dto | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class DeleteResponse( | ||
@SerialName("isHidden") | ||
val isHidden: Boolean = false | ||
) |
Oops, something went wrong.