전체 글 229

[Javascript] 객체 메소드 / computed property

※ computed property : 계산된 프로퍼티 let a = 'age'; const user = { name : 'sian', [a] : 30 } const user = { [1+4] : 5, ["안녕" + "하세요"] : "Hello" } ex ) key 와 value 값을 받아서 객체로 만들어주는 함수 makeObj () function makeObj(key,val){ return{ [key] : val, }; } const obj = makeObj("name", "sian"); console.log(obj); // {"name" : "sian"} ※ 객체 메소드 ▷ Object.assign() : 객체 복제 const newUser = Object.assign({},user); const ..

Javascript 2022.12.03

[Javascript] var, let, const & 호이스팅 / 생성자 함수

※ var & let & const var, let : 대부분의 경우 둘을 바꿔 사용해도 문제가 없음 let : 변할수도 있는 값을 선언할 때 const : 변하지 않는 값을 선언할 때 var 는 이제 사용하지 맙시다 함수 스코프를 가진다. 중복 선언이 가능하다. 선언하기 전에 사용 가능하다 (호이스팅 : 코드가 최상위로 끌어올려진 것 처럼 동작함) - 선언은 호이스팅이 되지만 할당은 호이스팅 되지 않는다. 따라서 사용 후 할당을 하는 것은 불가하다. var name; console.log(name); // undefined name = 'sian'; console.log(name); // ReferenceError let name = 'sian'; let 호이스팅 가능한데, 왜 var 처럼 동작하지 않..

카테고리 없음 2022.12.03

[React 프로젝트] 프로젝트 생성 / 발생에러 및 해결

▶ React 프로젝트 생성 PowerShell 관리자 권한으로 실행 cd C:/Users/user/desktop/proj npx create-react-app {프로젝트 이름} 이런 화면 뜨면 준비 OK cd {프로젝트 이름} npm start Error [eslint] Plugin "react" was conflicted between "package.json » eslint-config-react-app » C:\Users\user\desktop\proj\react-basic-proj\node_modules\eslint-config-react-app\base.js" and "BaseConfig » C:\Users\user\Desktop\proj\react-basic-proj\node_modules\..

React 2022.11.28

[Kotlin + SpringBoot + RESTApi] 오늘의 찌개 Today's Jjigae

Github : https://github.com/HAN-SEOHYUN/todaysjjigae 🔨 소개 매일 저녁 반복되는 메뉴 고민을 덜기 위해 제작했습니다. '오늘의 찌개' 에서 찌개를 랜덤으로 선택해드립니다. 사용자의 선호도가 높은 찌개는 추첨확률이 높습니다. 좋아하는 찌개를 등록, 수정, 삭제 가능합니다. API 서버만 구현되었습니다. 🪛목표 Kotlin 언어 학습 REST API 자체 Exception 클래스 생성 : 발생할 수 있는 모든 예외를 고려하여 예외처리 ⚙️개발 환경 Gradle Kotlin 1.6.21 Springboot 2.7.5 Mysql (AWS RDS) Spring Data JPA 🛠️프로젝트 구조 DTO : 계층 간 데이터 전송을 위한 객체 생성 Entity : 도메인 모델..

프로젝트 2022.11.22

[Kotlin] 목록에서 랜덤으로 1개만 가져오기 (response : objectDTO)

DB 에 저장된 찌개 목록중에서 랜덤으로 1가지만 가져오는 메서드 getRandomJjigae() 를 만들어보겠다. 1. 모든 찌개 정보 가져오기 2. 찌개의 Id만 List 에 담기 3. List 에 담긴 id 중 랜덤으로 1개 고르기 (random()) 4. 랜덤으로 선택 된 id 의 객체 가져오기 JpaRepository 클래스의 findAll() 메서드를 사용하면 Iterable 의 형태로 반환된다. List 형태로 반환받기 위해서 Repository 인터페이스에서 쿼리를 작성한다. 가져온 List 를 for 문을 돌려서 Object.id 만 List 에 담아줄거다. Kotlin 에서 List 는 읽기 전용이다. 때문에 값을 변경하기위한 List 인 mutableList 를 사용할거다. 선언을 먼..

Kotlin 2022.11.22

[Kotlin 토이프로젝트] CRUD 별 예외 처리

https://github.com/HAN-SEOHYUN/movie-api CRUD 작성 기본흐름 : Service => ServiceIml => Resource Create ▶ ServiceImpl It has problem. Because it has expecting a Movie. 문제가 있다. save() 는 Movie 객체가 인자로 들어가야한다. So use a Mapper class (Movie Mapper Class) 그래서 ~ 만들어 둔 Mapper 클래스를 사용할거다. (Mapper 클래스는 DTO / Entity 간 변환을 위해 만들었다) And the method have to return the new entity (Whenever we creating or updating, we ..

프로젝트 2022.11.18

[Kotlin 토이프로젝트] Handling Exceptions

https://github.com/HAN-SEOHYUN/movie-api ※ Handling Exceptions Exception 을 각각 설명하는 것이 아닌, 프로젝트를 진행하면서 어떤 과정에서 예외처리가 필요한 상황이 발생했는지, 어떻게 예외를 처리했는지, 또 예외 처리 과정을 어떻게 develop 했는지 흐름에 따라 정리했다. 따라서 위부터 읽어 내려가는 것을 추천한다. Expected Exception : How will we know that if the id is there or not ? ( id 값을 넣어서 DTO 를 보내면 Create 가 아니라 Update 가 된다 ) 1. Define a default value to DTO 이제 id 에 값을 지정하지 않고 send 하면 defaul..

프로젝트 2022.11.18

[Kotlin 토이프로젝트] 프로젝트 구조설계

https://github.com/HAN-SEOHYUN/movie-api 1. Entity data class / DTO data class Q. Why we creating two different classes ? 왜 두개의 클래스를 각각 생성해야 하는가 ? A. Spring boot has an architecture. It has different layers and each layer has their own responsibilities. 스프링부트는 아키텍쳐를 가지고 있는데, 각 레이어들은 모두 다른 책임을 갖고있어서. 1st. controller layer (Calls the service) - exposed to the outside / endpoint / has responsible f..

프로젝트 2022.11.18

[Kotlin] 유용한 함수 with / run

▶ with with 함수는 인자로 받는 객체를 this 로 사용할 수 있다. class withTestClass { var number = 10 fun sum(a:Int,b:Int): Int{ return a+b } } fun main(args:Array){ var testClass = withTestClass() var num = with(testClass){ number = number + 10 sum (10,number) } println(num) //30 } 객체를 생성하고 이것을 with 함수의 인자로 넘겨받았다. 그리고 with 로 시작한 코드블록에서 실제로 testClass 의 객체를 this 로 사용할 수 있게 되었다. 멤버변수인 number 의 값을 10 늘려주고, sum 메소드를 클래..

Kotlin 2022.11.15