Skip to main content

25-03-10

๐Ÿ“Œ Daily Reportโ€‹

https://github.com/ssginc-be/DOKI/issues/56


๐Ÿ“Œ ํ”„๋กœ์ ํŠธ ์ƒํ™ฉโ€‹

2์‹œ๊ฐ„ ๋ฐ˜ ์žค๋‹ค. ๋” ์ด์ƒ์˜ ์„ค๋ช…์€ ์ƒ๋žตํ•œ๋‹ค.

ํ”ผ๊ณคํ•จ๊ณผ ๋ณ„๊ฐœ๋กœ, ์ง€๊ธˆ ์ฝ”๋“œ ์•ˆ์งœ๋ฉด ์ง„์งœ ๋งํ• ์ˆ˜๋„ ์žˆ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“œ๋‹ˆ๊นŒ ์ดˆ์ธ์ ์ธ ์ง‘์ค‘๋ ฅ์ด ๋‚˜์˜ค๊ณ  ์žˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ์—”๋“œํฌ์ธํŠธ๋กœ ๋Œ๋ฆด ์ˆ˜ ์žˆ๋Š”๊ฑด ๋‹ค ๋Œ๋ ค์„œ, ์นดํ”„์นด / ์œ ๋ ˆ์นด ์ „๋ถ€ ํด๋ผ์šฐ๋“œ ์„œ๋ฒ„๋กœ ๋Œ๋ฆฌ๊ณ  ๋กœ์ปฌ์€ ์ตœ๋Œ€ํ•œ ์ž์›์„ ์•„๋ผ๋ ค ํ•˜๊ณ  ์žˆ๋‹ค.

Java๋กœ ๊ฐœ๋ฐœ๋œ IDE์—์„œ Java๋กœ ๊ฐœ๋ฐœ๋œ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ๋Œ๋ฆฌ๊ณ  ๊ฑฐ๊ธฐ์— ํฌ๋กฌ๊นŒ์ง€ ํƒญ ๋‚ญ๋‚ญํ•˜๊ฒŒ ๋„์›Œ๋†จ๋‹ค?

8GB๊ฐ€ ๊ณ ์ž‘ ์ข€ ๋ฒ„๋ฒ…๊ฑฐ๋ฆฌ๋Š” ๊ฒƒ์œผ๋กœ ๋๋‚จ์— ๊ฐ์‚ฌํ•ด์•ผ ํ•œ๋‹ค;

์ œ๋ฐœ ์˜ฌํ•ด๋Š” ๋…ธํŠธ๋ถ RAM ํ™•์žฅ์„ ํ•˜์ž.


๐Ÿ“Œ @Value์™€ Constructor ์ฃผ์ž…โ€‹

CoolSMS๋กœ ๋ฌธ์ž ๋ฐœ์†ก ๊ธฐ๋Šฅ ๊ตฌํ˜„ํ•˜๋‹ค๊ฐ€ ๋‹ค์‹œ ํ•œ๋ฒˆ ์ƒ๊ธฐํ•˜๊ฒŒ ๋œ ๋ถ€๋ถ„์ธ๋ฐ,

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ƒ์„ฑ์ž ์ฃผ์ž…์„ ํ•˜๋ฉด @Value๋กœ ์ฃผ์ž…ํ•˜๋ ค๋Š” ๊ฐ’๋“ค์€ ์ƒ์„ฑ์ž ์ฃผ์ž… ์‹œ์ ์— null์ด๋‹ค.

๊ทธ ์ด์œ ๋Š”, ์ด ๋ ˆํผ๋Ÿฐ์Šค์—์„œ ๋‹ต์„ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค.

Spring won't inject the properties' values until the object is fully instantiated.

์ •๋ฆฌํ•˜๋ฉด, ์ƒ์„ฑ์ž ํ˜ธ์ถœ -> ์ธ์Šคํ„ด์Šคํ™” -> property ๊ฐ’ ์ฃผ์ž… ์ˆœ์œผ๋กœ ์ผ์–ด๋‚˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

SmsUtil.java
@Component
public class SmsUtil {

@Value("${coolsms.apiKey}")
private String SMS_API_KEY;

@Value("${coolsms.secret}")
private String SMS_SECRET;

@Value("${coolsms.sender}")
private String SMS_SENDER; // ๋ฐœ์‹  ๋ฒˆํ˜ธ

@Value("${coolsms.enable}")
private boolean SMS_ENABLED; // false๋ฉด ๋กœ๊ทธ๋งŒ ์ฐํžˆ๊ณ  ์‹ค์ œ ๋ฌธ์ž ์ „์†ก์€ ์Šคํ‚ต๋จ

// ...

// CoolSMS API ์„ค์ •
private final DefaultMessageService messageService;

public SmsUtil() {
this.messageService = NurigoApp.INSTANCE.initialize(SMS_API_KEY, SMS_SECRET, "https://api.coolsms.co.kr");
}
// ...
}

๋”ฐ๋ผ์„œ ์ƒ๋‹จ์˜ ์ฝ”๋“œ์—์„œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—๋Ÿฌ๋ฅผ ๋งž๊ฒŒ ๋œ๋‹ค.

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.ssginc.commonservice.util.SmsUtil]: Constructor threw exception
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:222)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:122)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1337)
... 50 common frames omitted
Caused by: java.lang.NullPointerException: Parameter specified as non-null is null: method net.nurigo.sdk.NurigoApp.initialize, parameter apiKey

๊ทธ๋Ÿฌ๋ฏ€๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ƒ์„ฑ์ž๋ฅผ ์ˆ˜์ •ํ•ด์•ผ ํ•œ๋‹ค.

SmsUtil.java
@Autowired
public SmsUtil(@Value("${coolsms.apiKey}") String SMS_API_KEY, @Value("${coolsms.secret}") String SMS_SECRET) {
this.messageService = NurigoApp.INSTANCE.initialize(SMS_API_KEY, SMS_SECRET, "https://api.coolsms.co.kr");
}

๐Ÿ“Œ ๋ฌธ์ž ๋ฐœ์†ก ๊ธฐ๋Šฅ ๊ตฌํ˜„์‹œ ์ฃผ์˜์‚ฌํ•ญโ€‹

๋ฒˆํ˜ธ๋„์šฉ ๋ฌธ์ž์ฐจ๋‹จ์„œ๋น„์Šค์— ๊ฐ€์ž…๋˜์–ด ์žˆ์„ ์ˆ˜ ์žˆ์Œ.........

ํ•ด์ง€ ์‹ ์ฒญ ๋„ฃ์–ด๋„ ๋ฐ˜์˜๊นŒ์ง€ ์ตœ์†Œ 1~2์ผ ๊ฑธ๋ฆฐ๋‹ค๊ณ  ํ•˜๋‹ˆ ์ง์ „์— ๊ธ‰ํ•˜๊ฒŒ ๊ตฌํ˜„ํ•˜์ง€ ๋ง ๊ฒƒ.

ใ…‡ใ„ด


๐Ÿ“Œ ์ธ์ฆ ์„ฑ๊ณตํ•˜๋ฉด, ๊ทธ ๋‹ค์Œ์€?โ€‹

๋ณด์•ˆ์ ์ธ ์ธก๋ฉด์„ ์ƒ๊ฐํ•ด๋ณด๋ฉด, ์‚ฌ์šฉ์ž๊ฐ€ ์ด๋ฉ”์ผ ์ธ์ฆ ๋ฒˆํ˜ธ ์ธ์ฆ๊นŒ์ง€ ๋งˆ์ณค๋Š”๋ฐ

๊ทธ ์ƒํƒœ์—์„œ ํŽ˜์ด๋กœ๋“œ๋ฅผ ์กฐ์ž‘ํ•ด์„œ ํšŒ์›๊ฐ€์ž… REST ์š”์ฒญ์„ ๋ณด๋‚ผ ์ˆ˜๋„ ์žˆ๋‹ค.

๋ฌด์Šจ ์†Œ๋ฆฌ๋ƒ๋ฉด, ์ด๋ฉ”์ผ ์ธ์ฆ ์„ฑ๊ณต -> ํœด๋Œ€ํฐ ์ธ์ฆ ์„ฑ๊ณต -> ๊ฐ€์ž… ๋ฒ„ํŠผ ํ™œ์„ฑํ™”๋จ -> ๊ฐ€์ž… ํŽ˜์ด๋กœ๋“œ ์กฐ์ž‘ํ•˜์—ฌ API request

์ด๋Ÿด ์ˆ˜๋„ ์žˆ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค.

๊ทธ๋ž˜์„œ ์ง„์งœ ๊ฒฌ๊ณ ํ•œ ์‹œ์Šคํ…œ์„ ๊ตฌ์ƒํ•ด๋ณธ๋‹ค๋ฉด,

ํšŒ์›๊ฐ€์ž… ํŽ˜์ด์ง€ ์ง„์ž… -> ๊ณ ์œ  ์ฝ”๋“œ์˜ JWT ๋ฐœ๊ธ‰ํ•ด์„œ Set-Cookie (30๋ถ„ ํ›„ ๋งŒ๋ฃŒ)
์ด๋ฉ”์ผ ์ธ์ฆ ์„ฑ๊ณต -> JWT์— ํ•ด๋‹น ์ด๋ฉ”์ผ ๊ธฐ๋กํ•ด์„œ Set-Cookie
ํœด๋Œ€ํฐ ๋ฒˆํ˜ธ ์ธ์ฆ ์„ฑ๊ณต -> JWT์— ํ•ด๋‹น ํœด๋Œ€ํฐ ๋ฒˆํ˜ธ ๊ธฐ๋กํ•ด์„œ Set-Cookie

์ด๋Ÿฐ ์‹์œผ๋กœ ๊ฐ€์•ผ ํด๋ผ์ด์–ธํŠธ ์ธก์˜ ๋ณ€์กฐ ์œ„ํ—˜์„ฑ์„ ์›์ฒœ ์ฐจ๋‹จํ•  ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒ ์‹ถ๋‹ค.


๐Ÿ“Œ JPA ๋ฉ”์†Œ๋“œ๋กœ ์ค‘๊ณ„ํ…Œ์ด๋ธ”์˜ id ์ ‘๊ทผํ•˜๊ธฐโ€‹

์นดํ…Œ๊ณ ๋ฆฌ ํ•„ํ„ฐ ๋ชฉ๋ก ์กฐํšŒ ๊ตฌํ˜„ํ•˜๋‹ค๊ฐ€ ํ˜น์‹œ๋‚˜ ์‹ถ์–ด ์‹œ๋„ํ•ด๋ดค๋Š”๋ฐ, ๋†€๋ž๊ฒŒ๋„ ์ž‘๋™ํ•˜๋”๋ผ.

์›๋ž˜ FK ๊ด€๊ณ„๋Š” underscore์™€ Pascal case๋กœ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฉ”์†Œ๋“œ ๋„ค์ด๋ฐ ์ปจ๋ฒค์…˜์ด ์žˆ๋Š”๋ฐ, ์ค‘๊ณ„ ํ…Œ์ด๋ธ”์ด ์žˆ์–ด๋„ ์ด๊ฑธ ๊ทธ๋Œ€๋กœ ๋”ฐ๋ฅด๋Š” ๊ฒƒ ๊ฐ™๋‹ค.


์ฐธ๊ณ ๋กœ, Store์—๋Š” storeCategoryList๋ผ๋Š” ์ค‘๊ณ„ํ…Œ์ด๋ธ”๊ณผ์˜ @OnetoMany ๋งคํ•‘๊ด€๊ณ„๊ฐ€ ์žˆ๊ณ ,

์ค‘๊ณ„ํ…Œ์ด๋ธ”์ธ StoreCategory์—๋Š” category๋ผ๋Š” @ManyToOne ๋งคํ•‘๊ด€๊ณ„๊ฐ€ ์žˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  Category์˜ PK ํ•„๋“œ๋ช…์€ categoryId ์ด๋‹ค.


๋”ฐ๋ผ์„œ ๋‹ค์Œ์˜ ๋„ค์ด๋ฐ์€ Store์˜ categoryList์˜ category์˜ categoryId๋ฅผ WHERE์ ˆ๋กœ ์žก์•„ ๋งค์นญํ•˜๊ณ , LIMIT์œผ๋กœ ํŽ˜์ด์ง•ํ•˜๋Š” ์ฟผ๋ฆฌ๊ฐ€ ๋œ๋‹ค(!)

StoreRepository.java
public interface StoreRepository extends JpaRepository<Store, Long> {
Page<Store> findAllByStoreCategoryList_Category_CategoryId(Long categoryId, PageRequest pageRequest);
}

๐Ÿ“Œ ์–ด์ฉŒ๋‹ค๋ณด๋‹ˆ SPAโ€‹

ํŒ์—…์Šคํ† ์–ด ์นดํ…Œ๊ณ ๋ฆฌ ๋ชฉ๋ก ์กฐํšŒ๋ฅผ ๋น„๋™๊ธฐ ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ–ˆ๋Š”๋ฐ

๊ทธ๋Ÿฌ๋‹ค๋ณด๋‹ˆ ์ „์ฒด ๋ชฉ๋ก ์กฐํšŒ ๋ฐฉ์‹์ด๋ž‘ ๋‹ฌ๋ผ์„œ history๊ฐ€ ์ข€ ๊ผฌ์ด๋Š” ๊ฒƒ ๊ฐ™๋‹ค.

demo์—๋Š” ๋ฌธ์ œ ์—†์ง€๋งŒ ๋งˆ์Œ์— ์•ˆ๋“ค์–ด์„œ ์ถ”ํ›„์— ๋ณด์ˆ˜๋ฅผ ์ข€ ํ•ด์•ผ๊ฒ ์Œ...

DOM์€ JS ๊ฐ์ฒด๋กœ ๋‹ค๋ฃจ๋Š”๊ฒŒ ์•ˆ์ •์ ์ธ ๊ฒƒ ๊ฐ™์€๋ฐ ์›Œ๋‚™ ํƒœ๊ทธ๋„ ๋งŽ๊ณ  ํ•ด์„œ, ํ˜„ ์‹œ์ ์—์„  ๊นก ๋ฌธ์ž์—ด ์ฒ˜๋ฆฌ๊ฐ€ ๋ถˆ๊ฐ€ํ”ผ ํ•ด๋ณด์ธ๋‹ค.

table_view

ํŠนํžˆ ํ…Œ์ด๋ธ” ๋‹ค๋ฃฐ ๋•Œ ์ข‹๋”๋ผ~(?)