Skip to content

Commit

Permalink
Merge branch 'main' into enhancement-167-edit-user-role-01
Browse files Browse the repository at this point in the history
  • Loading branch information
Annelisebx authored Dec 6, 2023
2 parents 56c2fed + 3df92a9 commit ab1ad69
Show file tree
Hide file tree
Showing 30 changed files with 1,263 additions and 559 deletions.
6 changes: 0 additions & 6 deletions .github/dependabot.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
- '**.kt'
- '**/*.xml' # Matches all XML files in any directory
- '**/*.png' # Matches all PNG files in any directory
- '**/*.md' # Matches all MD files in any directory
# Add any other file patterns you need to include

jobs:
Expand Down
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

7 changes: 7 additions & 0 deletions LICENSE.md
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.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,7 @@ dependencies {

// Kotlin Reflection
implementation "org.jetbrains.kotlin:kotlin-reflect:1.8.22"

// Coil
implementation "io.coil-kt:coil-compose:2.4.0"
}
3 changes: 2 additions & 1 deletion app/src/main/java/com/example/belindas_closet/Routes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ sealed class Routes (val route: String) {
object SignUp: Routes("SignUp")
object AddProduct: Routes("Add Product")
object ForgotPassword: Routes("Forgot Password")
object ResetPassword: Routes("Reset Password")
object IndividualProduct: Routes("Individual_Product")
object IndividualProductUpdatePage: Routes("Individual_Product_Update")
object AdminView: Routes("Admin_View")
object EditUserRole: Routes("Edit User Role")

object DonationInfo: Routes("Donation_Info")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package com.example.belindas_closet.data
import com.example.belindas_closet.R
import com.example.belindas_closet.model.Product
import com.example.belindas_closet.model.ProductGender
import com.example.belindas_closet.model.ProductSizes
import com.example.belindas_closet.model.ProductSizePantsInseam
import com.example.belindas_closet.model.ProductSizePantsWaist
import com.example.belindas_closet.model.ProductSizeShoes
import com.example.belindas_closet.model.ProductSizes
import com.example.belindas_closet.model.ProductType
import com.example.belindas_closet.model.User
import com.example.belindas_closet.model.UserRole
Expand Down Expand Up @@ -144,7 +144,7 @@ class Datasource {
ProductSizePantsInseam.XS,
"This is a handbag",
R.drawable.product12.toString(),
"13"
"655b46baa82ef869be176174"
)
)
productList.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ object HttpRoutes {
private const val BASE_URL = "http://10.0.2.2:3000/api"
const val PRODUCTS = "$BASE_URL/products"
const val PRODUCT = "$BASE_URL/products/{id}"
const val ARCHIVE = "$BASE_URL/products/archive"
const val DELETE = "$BASE_URL/products/remove"
const val LOGIN = "$BASE_URL/auth/login"
const val FORGOT_PASSWORD = "$BASE_URL/auth/forgot-password"
const val SIGNUP = "$BASE_URL/auth/signup"
Expand Down
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", "") ?: ""
}
)
}
}

}
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
}
}
}
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", "") ?: ""
}
)
}
}

}
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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import io.ktor.serialization.kotlinx.json.json
import kotlinx.serialization.json.Json

interface LoginService {

suspend fun login(loginRequest: LoginRequest) : LoginResponse?

companion object {
Expand Down
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
)
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
)
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
)
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
)
Loading

0 comments on commit ab1ad69

Please sign in to comment.