Skip to content

Instantly share code, notes, and snippets.

View hiteshchopra11's full-sized avatar

Hitesh Chopra hiteshchopra11

View GitHub Profile
@hiteshchopra11
hiteshchopra11 / MainActivityViewModel.kt
Last active December 11, 2021 10:55
Class Extending the ViewModel class
class MainActivityViewModel : ViewModel() {
private val _counterLiveData = MutableLiveData(0)
val counterLiveData: LiveData<Int> = _counterLiveData
fun incrementByOne() {
_counterLiveData.value = _counterLiveData.value?.plus(1)
}
}
fun Application.notesRoutes() {
val db = DatabaseConnection.database
routing {
get("/notes") {
val notes = db.from(NotesEntity).select().map {
val id = it[NotesEntity.id]
val note = it[NotesEntity.note]
Note(id ?: -1, note ?: "")
}
get("/notes") {
val notes = db.from(NotesResponse).select().map {
val id = it[NotesEntity.id]
val note = it[NotesEntity.note]
Note(id ?: -1, note ?: "")
}
// Returns the response to the User
call.respond(notes)
}
@Serializable
data class NoteResponse<T>(
val data: T,
val success: Boolean
)
val request = call.receive<NoteRequest>()
val result = db.insert(NotesEntity) {
set(it.note, request.note)
}
@Serializable
data class NoteRequest(val note: String)
database.insert(Notes) {
 set(it.id, "id")
 set(it.note, "note")
}
insert into t_note (id,note) values (?, ?)
routing {
get("/notes") {
val notes = arraylistof("Note 1","Note 2")
call.respond(notes)
}
}
{ "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],