Skip to content

Commit f22c469

Browse files
committed
fix: integration with room database & payment method stripe
1 parent a1139c2 commit f22c469

18 files changed

+263
-88
lines changed

.idea/deploymentTargetDropDown.xml

-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle.kts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
plugins {
22
id("com.android.application")
33
id("org.jetbrains.kotlin.android")
4+
id ("com.google.devtools.ksp")
5+
id("org.jetbrains.kotlin.plugin.compose") version "2.0.0"
46
}
57

68
android {
@@ -73,7 +75,12 @@ dependencies {
7375
// Extended Icon
7476
implementation("com.vipulasri:ticketview:1.1.2")
7577

76-
// Swipe
78+
// Room dependency
79+
val room_version = "2.5.2"
80+
81+
implementation("androidx.room:room-ktx:$room_version")
82+
// To use Kotlin annotation processing tool (kapt)
83+
ksp("androidx.room:room-compiler:$room_version")
7784

7885

7986
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.ticketapp
2+
3+
4+
5+
import android.app.Application
6+
import com.example.ticketapp.database.AppDatabase
7+
8+
class App : Application() {
9+
override fun onCreate() {
10+
super.onCreate()
11+
AppDatabase.getDatabase(this)
12+
}
13+
}

app/src/main/java/com/example/ticketapp/MainActivity.kt

+19-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import androidx.compose.ui.unit.dp
3737
import androidx.compose.ui.unit.sp
3838
import com.example.ticketapp.components.HeaderComponent
3939
import com.example.ticketapp.components.SearchBarSection
40-
import com.example.ticketapp.models.ConcertsSectionData
4140
import com.example.ticketapp.ui.theme.TicketAppTheme
4241

4342
import android.app.PendingIntent
@@ -58,6 +57,11 @@ import androidx.navigation.compose.rememberNavController
5857
import com.example.ticketapp.components.EventDetails
5958
import com.example.ticketapp.components.TicketBookingScreen
6059
import com.example.ticketapp.components.TicketComponent
60+
import com.example.ticketapp.data.ConcertSection
61+
import com.example.ticketapp.database.AppDatabase
62+
import com.example.ticketapp.models.Event
63+
import kotlinx.coroutines.GlobalScope
64+
import kotlinx.coroutines.launch
6165

6266
class MainActivity : ComponentActivity() {
6367

@@ -159,6 +163,19 @@ class MainActivity : ComponentActivity() {
159163
}
160164
}
161165

166+
fun populateDatabase() {
167+
val eventDao = AppDatabase.getDatabase(this).eventDao()
168+
169+
// Créez des instances de Event
170+
val event1 = Event(eventId = 1, name = "Nom de l'événement", description = "Loremdjdeere", dateTime = "eee", location = "Terre")
171+
val event2 = Event(eventId = 2, name = "Nom de l'événement", description = "Loremdjdeere", dateTime = "eee", location = "Location 2")
172+
GlobalScope.launch {
173+
// Insérez les événements dans la base de données
174+
eventDao.insertEvent(event1)
175+
eventDao.insertEvent(event2)
176+
// Insérez autant d'événements que vous le souhaitez
177+
}
178+
}
162179
@Preview(showSystemUi = true)
163180
@Composable
164181
fun HomeScreen() {
@@ -181,7 +198,7 @@ class MainActivity : ComponentActivity() {
181198
fontSize = 20.sp
182199
)
183200

184-
ConcertsSectionData()
201+
ConcertSection()
185202

186203
Row(
187204
modifier = Modifier

app/src/main/java/com/example/ticketapp/models/ConcertsSection.kt app/src/main/java/com/example/ticketapp/components/ConcertSection.kt

+31-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.ticketapp.models
1+
package com.example.ticketapp.data
22

33
import androidx.compose.foundation.Image
44
import androidx.compose.foundation.layout.Box
@@ -22,33 +22,41 @@ import androidx.compose.ui.unit.dp
2222
import androidx.compose.ui.unit.sp
2323
import com.example.ticketapp.R
2424

25-
val concerts = listOf(
25+
data class Concerts(
26+
val nameArtiste: String,
27+
val location: String,
28+
val hour: String
29+
)
30+
31+
val damsoConcert = Concerts(
32+
nameArtiste = "Damso",
33+
location = "Videotron",
34+
hour = "8.00 PM - 11.00 PM"
35+
)
36+
37+
val tiakolaConcert = Concerts(
38+
nameArtiste = "Tiakola",
39+
location = "Centre Bell",
40+
hour = "8.00 PM - 11.00 PM"
41+
)
42+
43+
val gazoConcert = Concerts(
44+
nameArtiste = "Gazo",
45+
location = "K.C Irving",
46+
hour = "8.00 PM - 11.00 PM"
47+
)
2648

27-
Concerts(
28-
nameArtiste = "Damso",
29-
location = "Videotron",
30-
hour = "8.00 PM - 11.00 PM"
31-
),
32-
Concerts(
33-
nameArtiste = "Tiakola",
34-
location = "Centre Bell",
35-
hour = "8.00 PM - 11.00 PM"
36-
),
37-
Concerts(
38-
nameArtiste = "Gazo",
39-
location = "K.C Irving",
40-
hour = "8.00 PM - 11.00 PM"
41-
),
42-
Concerts(
43-
nameArtiste = "Ninho",
44-
location = "Gill",
45-
hour = "8.00 PM - 11.00 PM"
46-
),
49+
val ninhoConcert = Concerts(
50+
nameArtiste = "Ninho",
51+
location = "Gill",
52+
hour = "8.00 PM - 11.00 PM"
4753
)
4854

55+
val concerts = listOf(damsoConcert, tiakolaConcert, gazoConcert, ninhoConcert)
56+
4957
@Preview(showSystemUi = true)
5058
@Composable
51-
fun ConcertsSectionData() {
59+
fun ConcertSection() {
5260
LazyRow {
5361
items(concerts.size) {index ->
5462
ConcertItem(index)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.example.ticketapp.dao
2+
3+
import androidx.room.Dao
4+
import androidx.room.Insert
5+
import androidx.room.OnConflictStrategy
6+
import androidx.room.Query
7+
import com.example.ticketapp.models.Event
8+
import com.example.ticketapp.models.User
9+
10+
@Dao
11+
interface EventDao {
12+
@Query("""
13+
SELECT users.* FROM users
14+
INNER JOIN bookings ON users.userId = bookings.userId
15+
WHERE bookings.eventId = :eventId
16+
""")
17+
fun getUsersWhoBookedEvent(eventId: Long): List<User>
18+
19+
// Insertion d'un événement OnConflictStrategy.REPLACE permet de remplacer un événement existant
20+
@Insert(onConflict = OnConflictStrategy.REPLACE)
21+
suspend fun insertEvent(event: Event)
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.example.ticketapp.database
2+
3+
import android.content.Context
4+
import androidx.room.Database
5+
import androidx.room.Room
6+
import androidx.room.RoomDatabase
7+
import com.example.ticketapp.dao.EventDao
8+
import com.example.ticketapp.models.Booking
9+
import com.example.ticketapp.models.Event
10+
import com.example.ticketapp.models.Ticket
11+
import com.example.ticketapp.models.User
12+
13+
@Database(entities = [User::class, Event::class, Ticket::class, Booking::class], version = 1)
14+
abstract class AppDatabase : RoomDatabase() {
15+
abstract fun eventDao(): EventDao
16+
17+
companion object {
18+
@Volatile
19+
private var INSTANCE: AppDatabase? = null
20+
21+
fun getDatabase(context: Context): AppDatabase {
22+
val tempInstance = INSTANCE
23+
if (tempInstance != null) {
24+
return tempInstance
25+
}
26+
synchronized(this) {
27+
val instance = Room.databaseBuilder(
28+
context.applicationContext,
29+
AppDatabase::class.java,
30+
"app_database"
31+
).build()
32+
INSTANCE = instance
33+
return instance
34+
}
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.example.ticketapp.models
2+
3+
import androidx.room.Entity
4+
import androidx.room.ForeignKey
5+
import androidx.room.ForeignKey.Companion.CASCADE
6+
import androidx.room.PrimaryKey
7+
8+
9+
// Contraints for the Booking entity
10+
@Entity(
11+
tableName = "bookings",
12+
foreignKeys = [
13+
ForeignKey(
14+
entity = User::class,
15+
parentColumns = ["userId"],
16+
childColumns = ["userId"],
17+
onDelete = CASCADE
18+
),
19+
ForeignKey(
20+
entity = Event::class,
21+
parentColumns = ["eventId"],
22+
childColumns = ["eventId"],
23+
onDelete = CASCADE
24+
),
25+
ForeignKey(
26+
entity = Ticket::class,
27+
parentColumns = ["ticketId"],
28+
childColumns = ["ticketId"],
29+
onDelete = CASCADE
30+
)
31+
]
32+
)
33+
data class Booking(
34+
@PrimaryKey(autoGenerate = true) val bookingId: Long = 0,
35+
val userId: Long,
36+
val eventId: Long,
37+
val ticketId: Long,
38+
val quantityTickets: Int
39+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.ticketapp.models
2+
3+
import androidx.room.Entity
4+
import androidx.room.PrimaryKey
5+
6+
@Entity(tableName = "events")
7+
data class Event(
8+
@PrimaryKey(autoGenerate = true) val eventId: Long = 0,
9+
val name: String,
10+
val description: String,
11+
val dateTime: String,
12+
val location: String
13+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.example.ticketapp.models
2+
3+
import androidx.room.Entity
4+
import androidx.room.ForeignKey
5+
import androidx.room.ForeignKey.Companion.CASCADE
6+
import androidx.room.PrimaryKey
7+
8+
@Entity(
9+
tableName = "payments",
10+
foreignKeys = [
11+
ForeignKey(
12+
entity = Booking::class,
13+
parentColumns = ["bookingId"],
14+
childColumns = ["bookingId"],
15+
onDelete = CASCADE
16+
)
17+
]
18+
)
19+
data class Payment(
20+
@PrimaryKey(autoGenerate = true) val paymentId: Long = 0,
21+
val bookingId: Long,
22+
val amount: Double,
23+
val paymentDate: String,
24+
val paymentMethod: String
25+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.example.ticketapp.models
2+
3+
import androidx.room.Entity
4+
import androidx.room.PrimaryKey
5+
6+
@Entity(tableName = "tickets")
7+
data class Ticket(
8+
@PrimaryKey(autoGenerate = true) val ticketId: Long = 0,
9+
val typeTicket: String,
10+
val price: Double,
11+
val seatNumber: Int,
12+
val section: Int,
13+
val nbreTickets: Int
14+
)

app/src/main/java/com/example/ticketapp/models/TicketViewData.kt

-24
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.example.ticketapp.models
2+
3+
import androidx.room.Entity
4+
import androidx.room.PrimaryKey
5+
6+
@Entity(tableName = "users")
7+
data class User(
8+
@PrimaryKey(autoGenerate = true) val userId: Long = 0,
9+
val firstName: String,
10+
val lastName: String,
11+
val password: String,
12+
val email: String
13+
)

0 commit comments

Comments
 (0)