๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ”ฅ ํ”„๋กœ์ ํŠธ20

[์˜ค๋ฅ˜] multipart์—์„œ PUT์ด ๋จนํžˆ์ง€ ์•Š๋Š” ์˜ค๋ฅ˜ ๋ฌธ์ œ ์ƒํ™ฉ PUT ๋ฐฉ์‹์œผ๋กœ multipart๋ฅผ ๋ณด๋ƒˆ๋Š”๋ฐ, ๊ธฐ๋Šฅ ์ž์ฒด๋Š” ์ž˜ ๋Œ์•„๊ฐ”์œผ๋‚˜ ํ…Œ์ŠคํŠธํ•  ๋•Œ ์ž๊พธ ์˜ค๋ฅ˜๊ฐ€ ์ƒ๊น€ ๋ฐœ์ƒ ์›์ธ ๊ธฐ๋ณธ์ ์œผ๋กœ multipart ์š”์ฒญ์€ GET/POST๋งŒ ์ง€์›ํ•œ๋‹ค ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• POST๋กœ ์ˆ˜์ •ํ•˜์˜€๋”๋‹ˆ ๋Œ์•„๊ฐ”๋‹ค! ๋ฆฌํŒฉํ† ๋ง ์• ์ดˆ์— API ์„ค๊ณ„ ์›์น™์—๋„ ์กฐ๊ธˆ ์–ด๊ธ‹๋‚œ ๊ฒƒ ๊ฐ™์•„์„œ ๊ฒธ์‚ฌ๊ฒธ์‚ฌ ์ˆ˜์ •ํ–ˆ๋‹ค PUT์€ ํŠน์ • ๋ฆฌ์†Œ์Šค๋ฅผ ๊ฐฑ์‹ ํ•˜๋Š” ์—ญํ• ์„ ํ•˜๋Š”๋ฐ multipart๋กœ ๋ณด๋‚ด๋ฉด ํ•œ๋ฒˆ์— ์—ฌ๋Ÿฌ ๋ฆฌ์†Œ์Šค๋ฅผ ์ฒ˜๋ฆฌํ•˜๋ฏ€๋กœ ์ด๋ฏธ์ง€ ๊ฐ™์€ ๊ฒฝ์šฐ๋ฅผ PUT์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๋ ค๋ฉด ์ด๋ฏธ์ง€๋“ฑ์— ๋Œ€ํ•œ ๋ฆฌ์†Œ์Šค URI์— ๋ณ„๋„์˜ PUT ์š”์ฒญ์„ ๋ณด๋‚ด์„œ ๊ฐฑ์‹ ํ•˜๊ณ  ์ผ๋ฐ˜์ ์ธ ํผ์€ ๋”ฐ๋กœ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•œ๋‹ค. ๋ผ๊พธ๋ผ๊พธ profileUpdate์—์„œ ํ•œ URI๋กœ PUT์„ ๋ณด๋‚ด์„œ ์—ฌ๋Ÿฌ ๋ฆฌ์†Œ์Šค(ํšŒ์› ์ •๋ณด + ์ด๋ฏธ์ง€)๋ฅผ ํ•œ๊บผ๋ฒˆ์— ์ฒ˜๋ฆฌํ•˜๋ ค๊ณ  ํ–ˆ์œผ๋ฏ€๋กœ PUT์ด ์ ํ•ฉ์น˜ .. 2023. 8. 13.
[์ถ”์ธก] ๊ธฐ์กด Spring Security๋ฅผ ์ ์šฉํ•œ ์ƒํ™ฉ์—์„œ OAuth2 ์ ์šฉ์ด ์•ˆ ๋จนํ˜”๋˜ ์ด์œ  ์ถ”์ธก ๋ฌธ์ œ ์ƒํ™ฉ ์ž์ฒด ํšŒ์›๊ฐ€์ž…์—์„œ jwt refresh & access token์„ ์ง์ ‘ ๋งŒ๋“ค์–ด์„œ ์ ์šฉํ•œ ์ƒํ™ฉ ์ด ์ƒํ™ฉ์—์„œ oAuth2 ์ ์šฉ ์‹œ๋„ํ•˜์˜€์œผ๋‚˜ ์‹คํŒจ ์˜ˆ์ƒ ์†Œ๋งˆ ๋ฉ˜ํ† ๋‹˜๊ป˜์„œ ์•Œ๋ ค์ฃผ์‹  ๊ฑด๋ฐ ์šฐ๋ฆฌ ํ”„๋กœ์ ํŠธ๋ž‘ ๋น„์Šทํ•œ ์ƒํ™ฉ์ธ ๊ฒƒ ๊ฐ™์•„ ๊ณต์œ ํ•ฉ๋‹ˆ๋‹ค ์ •์„์ ์ธ ๋ฐฉ๋ฒ•) jwk/jws๋Š” jwt์™€ ํ•จ๊ป˜ ์”€ ํ† ํฐ ํƒˆ์ทจํ•˜๋ฉด ๋งˆ์Œ๋Œ€๋กœ ์“ธ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— signature ๋„ฃ์–ด์„œ ์•”ํ˜ธํ™” ํ›„ ๋น„๋Œ€์นญ์œผ๋กœ ๊ฒ€์ฆํ•จ (์ง„์งœ ์„œ๋ฒ„์—์„œ ๋ณด๋‚ธ ๊ฒƒ์ธ์ง€ ํ™•์ธ) ์†Œ์…œ๋กœ๊ทธ์ธ์ด๋ž‘ ๊ฐ™์ด ์“ธ ๋•Œ์˜ ๋ฌธ์ œ์  ์ผ๋ฐ˜ ๋กœ๊ทธ์ธ ์‹œ spring์—์„œ ์“ฐ๋Š” token์ด๋ž‘ ์†Œ์…œ ๋กœ๊ทธ์ธ ์‹œ ๋‚˜์˜ค๋Š” token์ด ๋ถ„๋ฆฌ๋˜์–ด ์žˆ์Œ ๊ทธ๋Ÿฌ๋‚˜ spring ์ž์ฒด์—์„œ ์ด 2๊ฐœ๋ฅผ ํ•˜๋‚˜์˜ token์œผ๋กœ ํ•ฉ์ณ์„œ clientํ•œํ…Œ ๋ณด๋‚ด์คŒ(๋‘˜์ด ์„œ๋กœ ๋‹ค๋ฅธ ์œ ์ €๋กœ ์žกํžˆ๋Š” ๊ฒƒ์„ ๋ง‰๊ธฐ ์œ„ํ•จ) ⇒ โœจ๊ทผ๋ฐ ๋‚ด.. 2023. 8. 13.
[์˜ค๋ฅ˜] WebMvcTest์—์„œ body๊ฐ’์ด empty์ธ ๊ฒฝ์šฐ ๋ฌธ์ œ ์ƒํ™ฉ ProfileUpdateController์—์„œ status๋Š” ํ™•์ธ๋˜๋Š”๋ฐ body์—์„œ ์ž๊พธ null๊ฐ’์ด ๋ฐœ์ƒํ•˜๋Š” ์˜ค๋ฅ˜ ๋ฐœ์ƒ String์„ ๋ฐ˜ํ™˜๊ฐ’์œผ๋กœ ํ•˜๋ฉด ์ž˜ ๋˜๋Š”๋ฐ dto์˜ body์—์„œ๋งŒ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ฒจ์„œ ๊ฐ™์ด ์—ฌ๋Ÿฌ๋ชจ๋กœ ๊ณ ๋ฏผํ–ˆ๋‹ค. Multipart๋ฅผ ์ธ์ž๋กœ ๋ฐ›๋Š” ๊ฒƒ์ด๋ผ multipart์˜ ๋ฌธ์ œ์ธ ์ค„ ์•Œ์•˜์œผ๋‚˜.... ๋ฐœ์ƒ ์›์ธ ProfileUpdateController๋กœ ์ „๋‹ฌ๋œ JSON์ด ๋งŒ๋“ค์–ด๋‚ธ Response ๊ฐ์ฒด๊ฐ€ ์šฐ๋ฆฌ๊ฐ€ ์˜ˆ์ƒํ•œ ๊ฒƒ๊ณผ ๋‹ค๋ฅธ ๊ฐ์ฒด๋ผ ๋ฐœ์ƒํ•˜๋Š” ๋ฌธ์ œ์˜€๋‹ค (Multipart๋ž‘ 1๋„ ์ƒ๊ด€์—†์—ˆ๋‹ค^^) https://velog.io/@devmizz/Spring-WebMvcTest%EC%97%90%EC%84%9C-Response-Body%EA%B0%80-Empty%EC%9D%BC-%EB%95%8C 2023. 8. 13.
[์„ค๊ณ„] File ํ…Œ์ด๋ธ” ๋‚ด์˜ item_id ์นผ๋Ÿผ ๋ฆฌํŒฉํ† ๋ง ํ˜„์žฌ ์ƒํ™ฉ ํ˜„์žฌ File ํ…Œ์ด๋ธ”์„ User, Portfolio, Item 3๊ฐœ์˜ ํ…Œ์ด๋ธ”์ด ์ฐธ์กฐํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. User์™€ Portfolio๋Š” File๊ณผ 1๋Œ€1 ๊ด€๊ณ„์ด๊ธฐ ๋•Œ๋ฌธ์— fk๋ฅผ ๊ฐ์ž์˜ ํ…Œ์ด๋ธ”์— ๋‘์ง€๋งŒ, Item์˜ ๊ฒฝ์šฐ 1๋Œ€๋‹ค ๊ด€๊ณ„์ด๊ธฐ ๋•Œ๋ฌธ์— fk๋ฅผ File ํ…Œ์ด๋ธ”์—์„œ ๊ฐ€์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด ๊ฒฝ์šฐ์˜ ๋ฌธ์ œ์ ์€ ํ…Œ์ด๋ธ”์˜ ์ •ํ•ฉ์„ฑ์„ ํ•ด์น˜๊ณ , item_id๊ฐ’์„ ๊ฐ€์ง€์ง€ ์•Š๋Š” User ์™€ Portfolio ํ…Œ์ด๋ธ”์—์„œ๋„ item_id ์นผ๋Ÿผ ๊ฐ’์„ ๋ถˆํ•„์š”ํ•˜๊ฒŒ ๊ฐ€์ ธ null ๊ฐ’์ด ๋ฐœ์ƒํ•œ๋‹ค๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•ด๊ฒฐ๋ฐฉ์•ˆ ์ด์˜ ๊ฒฝ์šฐ 2๊ฐ€์ง€์˜ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•์„ ๋– ์˜ฌ๋ฆด ์ˆ˜ ์ž‡์Šต๋‹ˆ๋‹ค. ItemFile ํ…Œ์ด๋ธ”์„ ๋”ฐ๋กœ ๋งŒ๋“ค์–ด์„œ ๊ธฐ์กด ํŒŒ์ผ๊ณผ ์ด๋ฅผ ๊ตฌ๋ถ„ํ•œ๋‹ค. File ํ…Œ์ด๋ธ”์—์„œ Item_Id๊ฐ€ ์•„๋‹Œ OwnerId ๊ฐ’์„ ๋‘์–ด ์ด ๊ณณ์— item_id, .. 2023. 8. 13.