Django Angular 12 PostgreSQL CRUD Example

Django is a Python-based free and open-source web framework that follows the model-template-view architectural pattern. Angular 12 is a TypeScript-based open-source web application framework led by the Angular Team at Google. In the tutorial, I introduce how to build a “Django Python Angular 12 PostgreSQL CRUD RestAPI Example” with Fullstack Projects providing POST/GET/PUT/DELETE requests using Django Rest Framework and PostgreSQL database with step by step coding examples:

– I draw a fullstack overview Diagram Architecture from Angular 12 Frontend to PostgreSQL database through Django RestAPI backend.
– Develop Django CRUD RestAPIs with the supporting of Django Rest Framework.
– Implement Angular 12 CRUD application with the Angular 12 Httpclient to do CRUD request (Post/Get/Put/Delete) to Django Backend APIs.
– I create a testsuite with a number of integrative testcases with CRUD RestAPI requests from Angular 12 HttpClient to do CRUD requests to Django RestAPIs Server and save/retrieve data to PostgreSQL database.

Related posts:


Continue reading “Django Angular 12 PostgreSQL CRUD Example”

Kotlin Solution with Codility Example – Find The Smallest Positive Integer

Write a function:
fun solution(A: IntArray): Int
that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.
For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.
Given A = [1, 2, 3], the function should return 4.
Given A = [−1, −3], the function should return 1.
Write an efficient algorithm for the following assumptions:
N is an integer within the range [1..100,000];
each element of array A is an integer within the range [−1,000,000..1,000,000].

Solution using HashMap

– BigO = O(n)
Kotlin Coding:


import java.util.*

fun main() {
    var original: IntArray = intArrayOf(1, 2, 3)
    solution(original)
}

fun solution(A: IntArray): Int {
	if (A.size == 0)
		return 1
	
    var max = A[0]

    for (num in A) {
        if (max < num)
            max = num
    }


    var min = A[0]

    for (num in A) {
        if (min > num)
            min = num
    }

	if(max < 1) return 1
	if(min > 1) return 1
	
	var hashMap : HashMap<Int, Int> = HashMap<Int, Int> ()
	
	for ((index, value) in A.withIndex()) {
		hashMap.put(value , index)
	}
	
    val len = A.size - 1
    
	for (i in 1..len) {
		if(hashMap.get(i) == null){
			return i
        }
	}
	
	return A[A.size - 1] + 1
}

Solution 2 using Sorting

– BigO = O(nlg(n))

Kotlin Coding:


import java.util.*

fun main() {
    var original: IntArray = intArrayOf(4, 5, 3, -1, 11, -2, 1)
    println(solution(original))
}

fun solution(A: IntArray): Int {
	A.sort()	
	
	var indexPositiveStart = -1
	
	for((index, value) in A.withIndex()) {
		if (value > 0) {
			indexPositiveStart = index
			break
		}
	}
	if (indexPositiveStart == -1)
		return 1
	
	if(A[indexPositiveStart] > 1){
		return 1
	}
	
	for (i in indexPositiveStart until (A.size - 1)){
		// check next item
		if (i + 1 <= A.size - 1) {
			if (A[i] + 1 < A[i+1])
				return A[i] + 1
		}
	}
	
	return A[A.size - 1] + 1
}