Lecture_Notes/imperfect_notes/pragy/Project Building - Psych - Coding 1.md
2020-03-19 12:51:33 +05:30

3.2 KiB
Raw Permalink Blame History

Psych Coding 1

Base Setup

  1. Create free account on Heroku

  2. Install Heroku CLI https://devcenter.heroku.com/articles/getting-started-with-java#set-up

  3. Install PostgreSQL https://www.postgresql.org/download/

    brew install postgres
    sudo chown -R `whoami` /usr/local
    
  4. Ensure postgres is started automatically on boot

    pg_ctl -D /usr/local/var/postgres start && brew services start postgresql
    postgres -V
    
  5. Create new Idea Project

    1. Spring Initializer
      • SDK 11 or 13
      • com.psych.game
      • Scaler Backend Project - Psych
      • Java 11
      • Maven
      • Spring Boot Dev Tools
      • Lombok
      • Spring Web
      • Rest Repositories
      • Spring Web Services
      • Spring Data JPA
      • PostgreSQL Driver
    2. name: pragypsych

Hello World

  1. Create File: devtest.HelloController
    package com.psych.game.devtest;
    
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @RequestMapping("/dev-test")
    public class HelloController {
        @GetMapping("/")
        public String hello() {
            return "Hello, World!";
        }
    }
    
  2. Try Build & Run
    • Build succeeds
    • Run fails: Because No DB
  3. Run postgres
    psql postgres
    \du                  # display users
    \list                # list databases
    create database psych_local;
    \connect psych_local # connect to specific DB
    \dt                  # display tables in current DB
    # psql postgres -U pragyagarwal
    
  4. Add psych_local DB to IntelliJ
  5. Create application.properties
    spring.datasource.url=jdbc:postgresql://localhost:5432/psych_local
    spring.jpa.hibernate.ddl-auto=update
    
    
  6. Run again. Go to http://localhost:8080/dev-test/

Deploy on Heroku

  1. Create new project.
    heroku create pragy-psych
    
  2. goto https://pragy-psych.herokuapp.com/ to find nothing
  3. add git
    git init
    git add .
    git commit -m "Init"
    
  4. add heroku remote
    git remote add heroku https://git.heroku.com/pragy-psych.git
    
  5. Deploy
    git push heroku master
    
  6. Error: Push Rejected - invalid target release: 11
  7. Create system.properties
    java.runtime.version=11
    
  8. Add, commit & deploy
  9. Goto https://pragy-psych.herokuapp.com/dev-test/
  10. Goto https://dashboard.heroku.com/apps/pragy-psych to see your stuff
  11. Note: it auto adds postgres free account
  12. See the logs
    heroku logs --tail
    

Make the models


Test

https://pragy-psych.herokuapp.com/dev-test/ https://pragy-psych.herokuapp.com/dev-test/questions https://pragy-psych.herokuapp.com/dev-test/populate


Post Lecture

Restore

Google Docs create and edit documents online, for free. YouTube