From 19dabbf05a7820bba5e798c63caaa1fe3a7d9c2b Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Sun, 5 Nov 2023 23:19:50 +0900 Subject: [PATCH 01/66] =?UTF-8?q?fix:=20kakaoLogin=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A3=B0=EB=9F=AC=20=EC=9D=91=EB=8B=B5=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/.DS_Store | Bin 10244 -> 10244 bytes .../tily/socialLogin/SocialLoginResponse.java | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/tily/.DS_Store b/src/main/java/com/example/tily/.DS_Store index 1fba9cef8e5127a832d82f9e5332ca03137ce9d2..ebcd01df0432d809ea074eb22314b4d487c23150 100644 GIT binary patch literal 10244 zcmeHMYitx%6h3FVrL$8?r<6zO0$FLos|DKyN(%{0N9>OH35VHK%|RNc{bgqD6F4d*A&5NSwR#@9zfZt8OelZB(CB0 z8+-(O1bhU11bhU11a1ukXwPOvEVrqD_Yv?B@DZ3mfW05WbTJxr=$K9UtAlPl1t1!r zW?raHc>tFQJ2dLhF`IHx8q>}m&=Ex^#Xwt}`ooN!Xw;!&Hnqh8ZE-+nW^^(X$ZR+2B1bhUpMS$h*r7!?VFd$o$zq3GUqigL|Ubv`>GcjytoJ{}SL`G9htFiHG z6iNc6v&zIWv0OYH8#0DtR@};&?eXkE_S9<_TB1;oC-$n!@PIt8!_cj`sw-J8pr#aJ zIkZpJQ^s(+k<(KqmyOvSVo(eY$O}hDn#4dKz&NMl2I{krB8CxYVqx;r=T z891t?b>lI=t}LWoA2kRR{F8d!pj1OU z@tL4NFQ||v+66jTRJY(5tcCljHxKdRQQ%F_C}rFPX)aIF#oPj0m3z)oK2sb9LAhNF z!Jy*`X@gC%q>;{$%7x-mS2Ob+w%?Uh75wg-g5L$D@=)JiseeG8n`{nM%`2V6ZT71)9AleTSgS)Z_{Qw{OO`FKZ``nHOUL$IJ>wN~D&;DvS~@_U ztXt|4Rmtv;n@L4asrq2wu$r=l_T^PmO=wE59#1R5Dr^XjS1edqv#2%{vKb}?3atIP zg!({EwT{VkqR8i18VXB?Qna|;MvBdn66LpP9Gbl@6b>C^Jsnwv?kN(G=Tufm(yG09ExX^o?&_gI4bO*R&Fk8XF^>m)iQV| zq0t=a(66rRS%@dQav1QD@C85yXw&dx6(CSla`vEYYJ<5 z#_?E8fEcWsVvW4ry|N>#zW8CwalSIAZ*o1}zA08wPNy`3&RHsXhX&nLAEdhOviVIp z%0^n7=_q?Wlh5QRJB@Nvz&Z`58|d9f_k8+{4fM3!lhEIod*;UQxJH0XX0gq=IE;}w zxjT#}_*}-kDFM8$rL`g4M9IkXiOEa?ctRf!9wj`n&^&0cl*En3Jf4blQ~J?H$C?Z| zyGm{!=duPRC(|S)xP-=Wrx^jr@x&(UnUA4ACEv|PKhm<1&~Is-M8A2xCoP;A`i|Zn z^hxd8sFc{cgxUB1uIc~(-$okys`v=_2zU{|KxeG8omvZdrI&$yYY)?PA6=|4zA>9} x5xViu@kIIOczR%;<5$wfcnj$^t4E!-F`H5gm7Dc5z|a5v{NMTV_P@*j{{iTWnlk_Z delta 51 zcmV-30L=e{P=rvBPXQgVP`eKS9kUD&k^-~O7{LLP{~H&x4;%Odv4EKdvj-sh1e4DY JJG0dr$O7tp6RiLM diff --git a/src/main/java/com/example/tily/socialLogin/SocialLoginResponse.java b/src/main/java/com/example/tily/socialLogin/SocialLoginResponse.java index b250fd78..f9c9dd53 100644 --- a/src/main/java/com/example/tily/socialLogin/SocialLoginResponse.java +++ b/src/main/java/com/example/tily/socialLogin/SocialLoginResponse.java @@ -3,7 +3,7 @@ public class SocialLoginResponse{ public record UserInfoDto(String nickname, String email){}; - public record TokenDTO(String token){}; + public record TokenDTO(String accessToken){}; } From ae8ae0071305fcf893101e56a6d69ac1f10f4e20 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Sun, 5 Nov 2023 23:21:38 +0900 Subject: [PATCH 02/66] =?UTF-8?q?Revert=20"fix:=20kakaoLogin=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A3=B0=EB=9F=AC=20=EC=9D=91=EB=8B=B5=20=EC=88=98?= =?UTF-8?q?=EC=A0=95"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 19dabbf05a7820bba5e798c63caaa1fe3a7d9c2b. --- src/main/java/com/example/tily/.DS_Store | Bin 10244 -> 10244 bytes .../tily/socialLogin/SocialLoginResponse.java | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/tily/.DS_Store b/src/main/java/com/example/tily/.DS_Store index ebcd01df0432d809ea074eb22314b4d487c23150..1fba9cef8e5127a832d82f9e5332ca03137ce9d2 100644 GIT binary patch delta 51 zcmV-30L=e{P=rvBPXQgVP`eKS9kUD&k^-~O7{LLP{~H&x4;%Odv4EKdvj-sh1e4DY JJG0dr$O7tp6RiLM literal 10244 zcmeHMYitx%6h3FVrL$8?r<6zO0$FLos|DKyN(%{0N9>OH35VHK%|RNc{bgqD6F4d*A&5NSwR#@9zfZt8OelZB(CB0 z8+-(O1bhU11bhU11a1ukXwPOvEVrqD_Yv?B@DZ3mfW05WbTJxr=$K9UtAlPl1t1!r zW?raHc>tFQJ2dLhF`IHx8q>}m&=Ex^#Xwt}`ooN!Xw;!&Hnqh8ZE-+nW^^(X$ZR+2B1bhUpMS$h*r7!?VFd$o$zq3GUqigL|Ubv`>GcjytoJ{}SL`G9htFiHG z6iNc6v&zIWv0OYH8#0DtR@};&?eXkE_S9<_TB1;oC-$n!@PIt8!_cj`sw-J8pr#aJ zIkZpJQ^s(+k<(KqmyOvSVo(eY$O}hDn#4dKz&NMl2I{krB8CxYVqx;r=T z891t?b>lI=t}LWoA2kRR{F8d!pj1OU z@tL4NFQ||v+66jTRJY(5tcCljHxKdRQQ%F_C}rFPX)aIF#oPj0m3z)oK2sb9LAhNF z!Jy*`X@gC%q>;{$%7x-mS2Ob+w%?Uh75wg-g5L$D@=)JiseeG8n`{nM%`2V6ZT71)9AleTSgS)Z_{Qw{OO`FKZ``nHOUL$IJ>wN~D&;DvS~@_U ztXt|4Rmtv;n@L4asrq2wu$r=l_T^PmO=wE59#1R5Dr^XjS1edqv#2%{vKb}?3atIP zg!({EwT{VkqR8i18VXB?Qna|;MvBdn66LpP9Gbl@6b>C^Jsnwv?kN(G=Tufm(yG09ExX^o?&_gI4bO*R&Fk8XF^>m)iQV| zq0t=a(66rRS%@dQav1QD@C85yXw&dx6(CSla`vEYYJ<5 z#_?E8fEcWsVvW4ry|N>#zW8CwalSIAZ*o1}zA08wPNy`3&RHsXhX&nLAEdhOviVIp z%0^n7=_q?Wlh5QRJB@Nvz&Z`58|d9f_k8+{4fM3!lhEIod*;UQxJH0XX0gq=IE;}w zxjT#}_*}-kDFM8$rL`g4M9IkXiOEa?ctRf!9wj`n&^&0cl*En3Jf4blQ~J?H$C?Z| zyGm{!=duPRC(|S)xP-=Wrx^jr@x&(UnUA4ACEv|PKhm<1&~Is-M8A2xCoP;A`i|Zn z^hxd8sFc{cgxUB1uIc~(-$okys`v=_2zU{|KxeG8omvZdrI&$yYY)?PA6=|4zA>9} x5xViu@kIIOczR%;<5$wfcnj$^t4E!-F`H5gm7Dc5z|a5v{NMTV_P@*j{{iTWnlk_Z diff --git a/src/main/java/com/example/tily/socialLogin/SocialLoginResponse.java b/src/main/java/com/example/tily/socialLogin/SocialLoginResponse.java index f9c9dd53..b250fd78 100644 --- a/src/main/java/com/example/tily/socialLogin/SocialLoginResponse.java +++ b/src/main/java/com/example/tily/socialLogin/SocialLoginResponse.java @@ -3,7 +3,7 @@ public class SocialLoginResponse{ public record UserInfoDto(String nickname, String email){}; - public record TokenDTO(String accessToken){}; + public record TokenDTO(String token){}; } From 026108e9d388b7b3a0f4cc32198552935fef7d6e Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Mon, 6 Nov 2023 22:30:57 +0900 Subject: [PATCH 03/66] =?UTF-8?q?feat:=20Roadmap=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20soft/delete=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/.DS_Store | Bin 10244 -> 10244 bytes .../java/com/example/tily/_core/.DS_Store | Bin 6148 -> 6148 bytes .../com/example/tily/roadmap/Roadmap.java | 2 ++ 3 files changed, 2 insertions(+) diff --git a/src/main/java/com/example/tily/.DS_Store b/src/main/java/com/example/tily/.DS_Store index 1fba9cef8e5127a832d82f9e5332ca03137ce9d2..144f801ea3f65ae7a3034cce122263e133dba65d 100644 GIT binary patch literal 10244 zcmeHMYitx%6h3FVrLzOIQ(9hKAS+GEqouY>DJ>Y-zJR7BRoX&%S@$utBeOH>&g{0( z5UWHJ0UyyAO%#0mH9q*^BN&bTP)YnHHb#D^i6;KhMD(A=1kb%Q+s78L%>78L%>7e_CSEnY?j1@Huat!0v-Y$0@Dbv{UJ!1(Xc}&ZOXR}dhif{sE?X? zqB6w+TqfwyutO(p%0+2RJ9RDkpwtj?_lE{u)nQ)WsPcGm}oF|6VkysixJ?@HGlW zzTyQXVu`p=JkmdEjP+X)D{Zz%QioV=z%aCEwj7D>Qw0?=pUAsO-wX~n(Bfrp_6sNiPlg3t{pq=nfxVS`&SE}O1V%vluPA~+ z#}}lHH1@}gM3R=AO|Io?W~RfoyQ1=}-F=g_JHNCrFt|?|8kQGl$hi8FmTKtcJ|$%m z9hS>XGQ#edq2H5ISpWW*p`{bLIV_jQB3dl1MJ%OF)B4pDiaBH{;}$C&G>w$i!5N2T zIc+L?72;DfN+)rfLn;l&*ebK{>QMB*xoF9%H8r&jo40Q7*wxcFReDF6TrO2e2g#Ck zOFgP8sRI!+rs#219~m4|rgtX zKA2Xm<8rkq@;O!qg3{qQz1$un&Sr^=@;fvR&0ZY{1`e^Fj+8>rI0?vil$A=-`VD@+ z92qca9h|XFs+R_ikqi1|(-v)%HU$Q?NL11Ma@?M$S!xOF&)C@d#p8Sp%a<-I4cr^(7v;+$sYul`Ds4NYaeMa>tHT>?rSJv%tHTYBjzm~N z{uzedaG1O{38&yJoP+c52D}TOz!&f(T!HW4d-wr*&XeGvkr#{JE)NB zD$W)yXmhzrRo6~w_if=SR~B*SSX@!LWOenrjiKgkJEo1uwz{mLxy_fWGsn`o&2s0- zv$rYkMbgSuS+|*SB-^nD$=H=~k@=il;&9)&MkHgGi=ArCTB`QQ3+!rDZJkJtB@0t4 zmMvdeFEvPV5&4jx_exc@oBg7Uc13F4O73OKKBu~JJ5|9MroDrPxg?9XZlxFCB76*& zV2Z5tC-@nz!Zj4hHmfj*HQYLDaU(Y47Hq+-csF+8PTYmvWTyi-i2HB|4?0#liYlhi zM2l?oA)LgA@f1EvmiiPvjnCkV_!6GOmmQmZ8!zNpVRx<-;>BDmOcHArq`Nys` z%O@s6p%!+RX}Qk5hTU5z6};D+q0YQj&2gmWak#Yh~~XV0GC zswv1lqoNyg&!MUUM=EbV zhW?y<^NoI}WecI-(mI2Fb5mZpc5~=E>&`=;mhGimMxe-+2(s`0U4{Su-}1PgfQNvG zz`q9p^mX=kw$uA&X}DQ;Nlcs1OIWaPY%pZo%&zc@WsB)qu~2NHo+2a1#DLw4A22d9a!lr7%ui-w2xc(ONjD5m&d)7iKmf3K zZoZ34QcivnP?#f4^Xx;rs-uoTHdHPJr(8h>vU!`!7&Tcpvvcrs09~>9BI9@F$^0Ug R9E=PMK*YeXIY49!GXNAyCYk^M delta 66 zcmZoMXfc=|#>B`mu~2NHo+2a5#DLw5ER%Vd@;5(bQeoZLkioc_or9kPsA97t^LOUS U{34bd3_!rhz`(RQKx7Lu07aY+zyJUM diff --git a/src/main/java/com/example/tily/roadmap/Roadmap.java b/src/main/java/com/example/tily/roadmap/Roadmap.java index 191cdb3c..ba53a931 100644 --- a/src/main/java/com/example/tily/roadmap/Roadmap.java +++ b/src/main/java/com/example/tily/roadmap/Roadmap.java @@ -44,6 +44,8 @@ public class Roadmap extends BaseTimeEntity { private int stepNum; @Column private String image; + @Column + private Boolean isDeleted = false; @Builder public Roadmap(Long id, User creator, Category category, String name, String description, Boolean isPublic, Long currentNum, String code, Boolean isRecruit, int stepNum, String image) { From 75d606a3f2cb5d6febbc86c741d99dccd7ff73be Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Mon, 6 Nov 2023 22:40:38 +0900 Subject: [PATCH 04/66] =?UTF-8?q?feat:=20Step=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20soft/delete=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/roadmap/Roadmap.java | 6 +++--- src/main/java/com/example/tily/til/Til.java | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/tily/roadmap/Roadmap.java b/src/main/java/com/example/tily/roadmap/Roadmap.java index ba53a931..7d21d85e 100644 --- a/src/main/java/com/example/tily/roadmap/Roadmap.java +++ b/src/main/java/com/example/tily/roadmap/Roadmap.java @@ -33,19 +33,19 @@ public class Roadmap extends BaseTimeEntity { @Column private String description; @Column - private Boolean isPublic; + private boolean isPublic; @Column private Long currentNum; @Column private String code; @Column - private Boolean isRecruit; + private boolean isRecruit; @Column private int stepNum; @Column private String image; @Column - private Boolean isDeleted = false; + private boolean isDeleted; @Builder public Roadmap(Long id, User creator, Category category, String name, String description, Boolean isPublic, Long currentNum, String code, Boolean isRecruit, int stepNum, String image) { diff --git a/src/main/java/com/example/tily/til/Til.java b/src/main/java/com/example/tily/til/Til.java index f4b5975a..560ebf94 100644 --- a/src/main/java/com/example/tily/til/Til.java +++ b/src/main/java/com/example/tily/til/Til.java @@ -49,6 +49,9 @@ public class Til extends BaseTimeEntity { @Column private boolean isPersonal; + @Column + private boolean isDeleted; + @Builder public Til(Long id, Roadmap roadmap, Step step, User writer, String title, String content, String submitContent, LocalDateTime submitDate, int commentNum, boolean isPersonal) { From 2d203575cade3ba9829d1e4a3ad5da93c3156d2c Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Mon, 6 Nov 2023 22:43:30 +0900 Subject: [PATCH 05/66] =?UTF-8?q?feat:=20Til=20=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=20soft/delete=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/roadmap/Roadmap.java | 9 +++++++++ src/main/java/com/example/tily/step/Step.java | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/src/main/java/com/example/tily/roadmap/Roadmap.java b/src/main/java/com/example/tily/roadmap/Roadmap.java index 7d21d85e..657d3b1f 100644 --- a/src/main/java/com/example/tily/roadmap/Roadmap.java +++ b/src/main/java/com/example/tily/roadmap/Roadmap.java @@ -28,22 +28,31 @@ public class Roadmap extends BaseTimeEntity { @Enumerated(value = EnumType.STRING) @Column(nullable = false) private Category category; + @Column(nullable = false) private String name; + @Column private String description; + @Column private boolean isPublic; + @Column private Long currentNum; + @Column private String code; + @Column private boolean isRecruit; + @Column private int stepNum; + @Column private String image; + @Column private boolean isDeleted; diff --git a/src/main/java/com/example/tily/step/Step.java b/src/main/java/com/example/tily/step/Step.java index 4dfec685..a81b5dd3 100644 --- a/src/main/java/com/example/tily/step/Step.java +++ b/src/main/java/com/example/tily/step/Step.java @@ -28,11 +28,16 @@ public class Step { @Column(nullable = false) private String title; + @Column private String description; + @Column private LocalDateTime dueDate; + @Column + private boolean isDeleted; + @Builder public Step(Long id, Roadmap roadmap, String title, String description, LocalDateTime dueDate) { this.id = id; From c8631e1d936728bff50fabadeeb5ba52b3313b80 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Mon, 6 Nov 2023 22:58:34 +0900 Subject: [PATCH 06/66] =?UTF-8?q?feat:=20Comment=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20soft/delete=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/comment/Comment.java | 4 +++- src/main/java/com/example/tily/roadmap/Roadmap.java | 2 +- src/main/java/com/example/tily/step/Step.java | 2 +- src/main/java/com/example/tily/til/Til.java | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/tily/comment/Comment.java b/src/main/java/com/example/tily/comment/Comment.java index 018c6947..6cbb6dac 100644 --- a/src/main/java/com/example/tily/comment/Comment.java +++ b/src/main/java/com/example/tily/comment/Comment.java @@ -30,8 +30,10 @@ public class Comment extends BaseTimeEntity { @JoinColumn(name="writer_id") private User writer; - private String content; + @Column + private boolean isDeleted = false; + private String content; @Builder diff --git a/src/main/java/com/example/tily/roadmap/Roadmap.java b/src/main/java/com/example/tily/roadmap/Roadmap.java index 657d3b1f..f9bc1ec3 100644 --- a/src/main/java/com/example/tily/roadmap/Roadmap.java +++ b/src/main/java/com/example/tily/roadmap/Roadmap.java @@ -54,7 +54,7 @@ public class Roadmap extends BaseTimeEntity { private String image; @Column - private boolean isDeleted; + private boolean isDeleted = false; @Builder public Roadmap(Long id, User creator, Category category, String name, String description, Boolean isPublic, Long currentNum, String code, Boolean isRecruit, int stepNum, String image) { diff --git a/src/main/java/com/example/tily/step/Step.java b/src/main/java/com/example/tily/step/Step.java index a81b5dd3..aea8b18d 100644 --- a/src/main/java/com/example/tily/step/Step.java +++ b/src/main/java/com/example/tily/step/Step.java @@ -36,7 +36,7 @@ public class Step { private LocalDateTime dueDate; @Column - private boolean isDeleted; + private boolean isDeleted = false; @Builder public Step(Long id, Roadmap roadmap, String title, String description, LocalDateTime dueDate) { diff --git a/src/main/java/com/example/tily/til/Til.java b/src/main/java/com/example/tily/til/Til.java index 560ebf94..43acd680 100644 --- a/src/main/java/com/example/tily/til/Til.java +++ b/src/main/java/com/example/tily/til/Til.java @@ -50,7 +50,7 @@ public class Til extends BaseTimeEntity { private boolean isPersonal; @Column - private boolean isDeleted; + private boolean isDeleted = false; @Builder From a68a90ad9f4ef490ec859b24731bf44cfee8db6e Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 00:18:04 +0900 Subject: [PATCH 07/66] =?UTF-8?q?feat:=20Reference=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20soft/delete=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/comment/Comment.java | 6 ++++-- src/main/java/com/example/tily/image/Image.java | 6 ++++++ src/main/java/com/example/tily/roadmap/Roadmap.java | 2 ++ src/main/java/com/example/tily/roadmap/RoadmapService.java | 4 ++-- src/main/java/com/example/tily/step/Step.java | 2 ++ .../java/com/example/tily/step/reference/Reference.java | 6 ++++++ src/main/java/com/example/tily/til/Til.java | 3 ++- src/main/java/com/example/tily/user/User.java | 2 ++ 8 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/tily/comment/Comment.java b/src/main/java/com/example/tily/comment/Comment.java index 6cbb6dac..f0d06c07 100644 --- a/src/main/java/com/example/tily/comment/Comment.java +++ b/src/main/java/com/example/tily/comment/Comment.java @@ -9,6 +9,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; @@ -16,6 +17,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="comment_tb") +@SQLDelete(sql = "UPDATE comment_tb SET isDeleted = true WHERE id = ?") public class Comment extends BaseTimeEntity { @Id @@ -31,10 +33,10 @@ public class Comment extends BaseTimeEntity { private User writer; @Column - private boolean isDeleted = false; - private String content; + @Column + private boolean isDeleted = false; @Builder public Comment (Long id, Roadmap roadmap, Step step, Til til, User writer, String content) { diff --git a/src/main/java/com/example/tily/image/Image.java b/src/main/java/com/example/tily/image/Image.java index 862638ad..8322cedb 100644 --- a/src/main/java/com/example/tily/image/Image.java +++ b/src/main/java/com/example/tily/image/Image.java @@ -13,8 +13,14 @@ public class Image { @Id @GeneratedValue private Long id; + + @Column private String originalImageName; + + @Column private String storageImageName; + + @Column private String imagePath; public Image(String originalImageName, String storageImageName, String imagePath) { diff --git a/src/main/java/com/example/tily/roadmap/Roadmap.java b/src/main/java/com/example/tily/roadmap/Roadmap.java index f9bc1ec3..a29d5298 100644 --- a/src/main/java/com/example/tily/roadmap/Roadmap.java +++ b/src/main/java/com/example/tily/roadmap/Roadmap.java @@ -7,6 +7,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; import java.util.ArrayList; @@ -16,6 +17,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="roadmap_tb") +@SQLDelete(sql = "UPDATE roadmap_tb SET isDeleted = true WHERE id = ?") public class Roadmap extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index b3fd5a2f..74ee4208 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -355,7 +355,7 @@ public void applyGroupRoadmap(RoadmapRequest.ApplyRoadmapDTO requestDTO, Long id Roadmap roadmap = getRoadmapById(id); // 모집을 중단했을 때 - if (!roadmap.getIsRecruit()) + if (!roadmap.isRecruit()) throw new CustomException(ExceptionCode.ROADMAP_END_RECRUIT); // 최초로 한 번만 신청 가능 @@ -386,7 +386,7 @@ public void applyTilyRoadmap(Long id, User user) { Roadmap roadmap = getRoadmapById(id); // 모집을 중단했을 때 - if (!roadmap.getIsRecruit()) + if (!roadmap.isRecruit()) throw new CustomException(ExceptionCode.ROADMAP_END_RECRUIT); // 이미 로드맵에 속한 경우 diff --git a/src/main/java/com/example/tily/step/Step.java b/src/main/java/com/example/tily/step/Step.java index aea8b18d..f34589f0 100644 --- a/src/main/java/com/example/tily/step/Step.java +++ b/src/main/java/com/example/tily/step/Step.java @@ -6,6 +6,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; import java.time.LocalDateTime; @@ -16,6 +17,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="step_tb") +@SQLDelete(sql = "UPDATE step_tb SET isDeleted = true WHERE id = ?") public class Step { @Id diff --git a/src/main/java/com/example/tily/step/reference/Reference.java b/src/main/java/com/example/tily/step/reference/Reference.java index 6ffbcdf1..17f624a5 100644 --- a/src/main/java/com/example/tily/step/reference/Reference.java +++ b/src/main/java/com/example/tily/step/reference/Reference.java @@ -5,6 +5,8 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.checkerframework.checker.units.qual.C; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; @@ -12,6 +14,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="reference_tb") +@SQLDelete(sql = "UPDATE reference_tb SET isDeleted = true WHERE id = ?") public class Reference { @Id @@ -28,6 +31,9 @@ public class Reference { @Column(nullable = false, columnDefinition="TEXT", length = 1000) private String link; + @Column + private boolean isDeleted = false; + @Builder public Reference(Step step, Long id, String category, String link) { this.step = step; diff --git a/src/main/java/com/example/tily/til/Til.java b/src/main/java/com/example/tily/til/Til.java index 43acd680..d010d154 100644 --- a/src/main/java/com/example/tily/til/Til.java +++ b/src/main/java/com/example/tily/til/Til.java @@ -5,6 +5,7 @@ import com.example.tily.step.Step; import com.example.tily.user.User; import lombok.*; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; import java.time.LocalDateTime; @@ -13,6 +14,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="til_tb") +@SQLDelete(sql = "UPDATE til_tb SET isDeleted = true WHERE id = ?") public class Til extends BaseTimeEntity { @Id @@ -52,7 +54,6 @@ public class Til extends BaseTimeEntity { @Column private boolean isDeleted = false; - @Builder public Til(Long id, Roadmap roadmap, Step step, User writer, String title, String content, String submitContent, LocalDateTime submitDate, int commentNum, boolean isPersonal) { this.id = id; diff --git a/src/main/java/com/example/tily/user/User.java b/src/main/java/com/example/tily/user/User.java index e4398179..46ff322c 100644 --- a/src/main/java/com/example/tily/user/User.java +++ b/src/main/java/com/example/tily/user/User.java @@ -7,6 +7,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; import java.util.ArrayList; @@ -16,6 +17,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="user_tb") +@SQLDelete(sql = "UPDATE user_tb SET isDeleted = true WHERE id = ?") public class User extends BaseTimeEntity { @Id From db192a675b219539684614a4f48892576bad4bc6 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 00:19:45 +0900 Subject: [PATCH 08/66] =?UTF-8?q?feat:=20User=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20soft/delete=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/user/User.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/example/tily/user/User.java b/src/main/java/com/example/tily/user/User.java index 46ff322c..a5a544f6 100644 --- a/src/main/java/com/example/tily/user/User.java +++ b/src/main/java/com/example/tily/user/User.java @@ -38,6 +38,9 @@ public class User extends BaseTimeEntity { @Enumerated(EnumType.STRING) private Role role; + @Column + private boolean isDeleted = false; + @Builder public User(Long id, String email, String name, String password, String image, Role role) { this.id = id; From 2e9eefec57013095e38d1b820468355b95969ec0 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 00:25:10 +0900 Subject: [PATCH 09/66] =?UTF-8?q?feat:=20UserRoadmap=20Soft/delete=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/tily/roadmap/relation/UserRoadmap.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java b/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java index 83f5f4f7..67b046c2 100644 --- a/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java +++ b/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java @@ -7,6 +7,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; @@ -14,6 +15,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="user_roadmap_tb") +@SQLDelete(sql = "UPDATE user_roadmap_tb SET isDeleted = true WHERE id = ?") public class UserRoadmap extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -39,6 +41,9 @@ public class UserRoadmap extends BaseTimeEntity { @Column(nullable = false) private int progress; + @Column + private boolean isDeleted = false; + @Builder public UserRoadmap(Roadmap roadmap, User user, String content, Boolean isAccept, GroupRole role, int progress) { this.roadmap = roadmap; From 440e20965c4d2b714e42aa368f94e21db3e4d3d7 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 00:30:39 +0900 Subject: [PATCH 10/66] =?UTF-8?q?feat:=20UserStep=20=EC=97=94=ED=8B=B0?= =?UTF-8?q?=ED=8B=B0=20soft/delete=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/step/relation/UserStep.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/example/tily/step/relation/UserStep.java b/src/main/java/com/example/tily/step/relation/UserStep.java index 481d3a6d..5b6ecb86 100644 --- a/src/main/java/com/example/tily/step/relation/UserStep.java +++ b/src/main/java/com/example/tily/step/relation/UserStep.java @@ -7,6 +7,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.hibernate.annotations.SQLDelete; import javax.persistence.*; @@ -14,6 +15,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="user_step_tb") +@SQLDelete(sql = "UPDATE user_step_tb SET isDeleted = true WHERE id = ?") public class UserStep { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -34,6 +36,9 @@ public class UserStep { @Column(nullable = false) private Boolean isSubmit; + @Column + private boolean isDeleted = false; + @Builder public UserStep(Roadmap roadmap, Step step, User user, Boolean isSubmit){ this.roadmap = roadmap; From 72033fbf937cd7b6974c6b63546b2ea88c99ad4b Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 00:36:33 +0900 Subject: [PATCH 11/66] =?UTF-8?q?feat:=20@Where=20=EC=96=B4=EB=85=B8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EC=85=98=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/comment/Comment.java | 2 ++ src/main/java/com/example/tily/roadmap/Roadmap.java | 2 ++ .../java/com/example/tily/roadmap/relation/UserRoadmap.java | 2 ++ src/main/java/com/example/tily/step/Step.java | 2 ++ src/main/java/com/example/tily/step/reference/Reference.java | 2 ++ src/main/java/com/example/tily/step/relation/UserStep.java | 2 ++ src/main/java/com/example/tily/til/Til.java | 2 ++ src/main/java/com/example/tily/user/User.java | 2 ++ 8 files changed, 16 insertions(+) diff --git a/src/main/java/com/example/tily/comment/Comment.java b/src/main/java/com/example/tily/comment/Comment.java index f0d06c07..4156be6b 100644 --- a/src/main/java/com/example/tily/comment/Comment.java +++ b/src/main/java/com/example/tily/comment/Comment.java @@ -10,6 +10,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; @@ -18,6 +19,7 @@ @Entity @Table(name="comment_tb") @SQLDelete(sql = "UPDATE comment_tb SET isDeleted = true WHERE id = ?") +@Where(clause = "isDeleted = false") public class Comment extends BaseTimeEntity { @Id diff --git a/src/main/java/com/example/tily/roadmap/Roadmap.java b/src/main/java/com/example/tily/roadmap/Roadmap.java index a29d5298..d9c6b401 100644 --- a/src/main/java/com/example/tily/roadmap/Roadmap.java +++ b/src/main/java/com/example/tily/roadmap/Roadmap.java @@ -8,6 +8,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; import java.util.ArrayList; @@ -18,6 +19,7 @@ @Entity @Table(name="roadmap_tb") @SQLDelete(sql = "UPDATE roadmap_tb SET isDeleted = true WHERE id = ?") +@Where(clause = "isDeleted = false") public class Roadmap extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java b/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java index 67b046c2..ab8cc98d 100644 --- a/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java +++ b/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java @@ -8,6 +8,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; @@ -16,6 +17,7 @@ @Entity @Table(name="user_roadmap_tb") @SQLDelete(sql = "UPDATE user_roadmap_tb SET isDeleted = true WHERE id = ?") +@Where(clause = "isDeleted = false") public class UserRoadmap extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/example/tily/step/Step.java b/src/main/java/com/example/tily/step/Step.java index f34589f0..83c6a42b 100644 --- a/src/main/java/com/example/tily/step/Step.java +++ b/src/main/java/com/example/tily/step/Step.java @@ -7,6 +7,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; import java.time.LocalDateTime; @@ -18,6 +19,7 @@ @Entity @Table(name="step_tb") @SQLDelete(sql = "UPDATE step_tb SET isDeleted = true WHERE id = ?") +@Where(clause = "isDeleted = false") public class Step { @Id diff --git a/src/main/java/com/example/tily/step/reference/Reference.java b/src/main/java/com/example/tily/step/reference/Reference.java index 17f624a5..aee26fab 100644 --- a/src/main/java/com/example/tily/step/reference/Reference.java +++ b/src/main/java/com/example/tily/step/reference/Reference.java @@ -7,6 +7,7 @@ import lombok.NoArgsConstructor; import org.checkerframework.checker.units.qual.C; import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; @@ -15,6 +16,7 @@ @Entity @Table(name="reference_tb") @SQLDelete(sql = "UPDATE reference_tb SET isDeleted = true WHERE id = ?") +@Where(clause = "isDeleted = false") public class Reference { @Id diff --git a/src/main/java/com/example/tily/step/relation/UserStep.java b/src/main/java/com/example/tily/step/relation/UserStep.java index 5b6ecb86..d8daa4fd 100644 --- a/src/main/java/com/example/tily/step/relation/UserStep.java +++ b/src/main/java/com/example/tily/step/relation/UserStep.java @@ -8,6 +8,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; @@ -16,6 +17,7 @@ @Entity @Table(name="user_step_tb") @SQLDelete(sql = "UPDATE user_step_tb SET isDeleted = true WHERE id = ?") +@Where(clause = "isDeleted = false") public class UserStep { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/example/tily/til/Til.java b/src/main/java/com/example/tily/til/Til.java index d010d154..72e373a8 100644 --- a/src/main/java/com/example/tily/til/Til.java +++ b/src/main/java/com/example/tily/til/Til.java @@ -6,6 +6,7 @@ import com.example.tily.user.User; import lombok.*; import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; import java.time.LocalDateTime; @@ -15,6 +16,7 @@ @Entity @Table(name="til_tb") @SQLDelete(sql = "UPDATE til_tb SET isDeleted = true WHERE id = ?") +@Where(clause = "isDeleted = false") public class Til extends BaseTimeEntity { @Id diff --git a/src/main/java/com/example/tily/user/User.java b/src/main/java/com/example/tily/user/User.java index a5a544f6..0cecdb45 100644 --- a/src/main/java/com/example/tily/user/User.java +++ b/src/main/java/com/example/tily/user/User.java @@ -8,6 +8,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.hibernate.annotations.SQLDelete; +import org.hibernate.annotations.Where; import javax.persistence.*; import java.util.ArrayList; @@ -18,6 +19,7 @@ @Entity @Table(name="user_tb") @SQLDelete(sql = "UPDATE user_tb SET isDeleted = true WHERE id = ?") +@Where(clause = "isDeleted = false") public class User extends BaseTimeEntity { @Id From 31918ec3749751bee80de8fc4044f2b98bbd0b68 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 01:10:43 +0900 Subject: [PATCH 12/66] =?UTF-8?q?feat:=20=EC=B0=B8=EA=B3=A0=EC=9E=90?= =?UTF-8?q?=EB=A3=8C=20soft/delete=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/roadmap/RoadmapResponse.java | 2 +- .../java/com/example/tily/step/StepController.java | 8 ++++++++ src/main/java/com/example/tily/step/StepService.java | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/tily/roadmap/RoadmapResponse.java b/src/main/java/com/example/tily/roadmap/RoadmapResponse.java index 8f237f24..1301752b 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapResponse.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapResponse.java @@ -24,7 +24,7 @@ public CreateRoadmapDTO(Roadmap roadmap) { public record FindGroupRoadmapDTO(Creator creator, String name, String description, String myRole, Long recentTilId, Long recentStepId, Boolean isPublic, Boolean isRecruit, String code, List steps) { public FindGroupRoadmapDTO(Roadmap roadmap, List steps, User user, Long recentTilId, Long recentStepId, String myRole) { - this(new Creator(user.getName(), user.getImage()), roadmap.getName(), roadmap.getDescription(), myRole, recentTilId, recentStepId, roadmap.getIsPublic(), roadmap.getIsRecruit(), roadmap.getCode(), steps); + this(new Creator(user.getName(), user.getImage()), roadmap.getName(), roadmap.getDescription(), myRole, recentTilId, recentStepId, roadmap.isPublic(), roadmap.isRecruit(), roadmap.getCode(), steps); } public record Creator(String name, String image) {} diff --git a/src/main/java/com/example/tily/step/StepController.java b/src/main/java/com/example/tily/step/StepController.java index 4799e87e..df1aaf7e 100644 --- a/src/main/java/com/example/tily/step/StepController.java +++ b/src/main/java/com/example/tily/step/StepController.java @@ -36,4 +36,12 @@ public ResponseEntity findAllStep(@PathVariable("roadmapId") Long roadmapId, StepResponse.FindAllStepDTO responseDTO = stepService.findAllStep(roadmapId, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } + + // 참고자료 삭제 + @DeleteMapping("/reference/{referenceId}") + public ResponseEntity deleteReference(@PathVariable Long referenceId, @AuthenticationPrincipal CustomUserDetails userDetails){ + stepService.deleteReference(referenceId); + + return ResponseEntity.ok().body(ApiUtils.success(null)); + } } \ No newline at end of file diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index 458291a0..da83b3b0 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -95,6 +95,13 @@ public StepResponse.FindAllStepDTO findAllStep (Long roadmapId, User user) { return new StepResponse.FindAllStepDTO(stepDTOs, progress, myRole); } + // 참고자료 삭제 + public void deleteReference(Long referenceId){ + Reference reference = getReferenceById(referenceId); + referenceRepository.delete(reference); + } + + private Roadmap getRoadmapById(Long roadmapId) { return roadmapRepository.findById(roadmapId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); } @@ -102,4 +109,8 @@ private Roadmap getRoadmapById(Long roadmapId) { private Step getStepById(Long stepId) { return stepRepository.findById(stepId).orElseThrow(() -> new CustomException(ExceptionCode.STEP_NOT_FOUND)); } + + private Reference getReferenceById(Long referenceId){ + return referenceRepository.findById(referenceId).orElseThrow(() -> new CustomException(ExceptionCode.REFERENCE_NOT_FOUND)); + } } From d41628c65cd0f61967bac27560bba9f4bcdcfd61 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 01:39:12 +0900 Subject: [PATCH 13/66] =?UTF-8?q?feat:=20=EC=B0=B8=EA=B3=A0=EC=9E=90?= =?UTF-8?q?=EB=A3=8C=20soft/delete=20=EA=B8=B0=EB=8A=A5=EC=97=90=20?= =?UTF-8?q?=EA=B6=8C=ED=95=9C=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_core/errors/exception/ExceptionCode.java | 1 + .../com/example/tily/step/StepController.java | 2 +- .../java/com/example/tily/step/StepService.java | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java b/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java index c1771d33..34d5d3bb 100644 --- a/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java +++ b/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java @@ -65,6 +65,7 @@ public enum ExceptionCode { // reference 관련 에러 REFERENCE_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 reference를 찾을 수 없습니다."), + REFERENCE_DELETE_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 reference를 삭제할 권한이 없습니다"), // image 관련 에러 IMAGE_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 image를 찰을 수 없습니다."), diff --git a/src/main/java/com/example/tily/step/StepController.java b/src/main/java/com/example/tily/step/StepController.java index df1aaf7e..c87ecd24 100644 --- a/src/main/java/com/example/tily/step/StepController.java +++ b/src/main/java/com/example/tily/step/StepController.java @@ -40,7 +40,7 @@ public ResponseEntity findAllStep(@PathVariable("roadmapId") Long roadmapId, // 참고자료 삭제 @DeleteMapping("/reference/{referenceId}") public ResponseEntity deleteReference(@PathVariable Long referenceId, @AuthenticationPrincipal CustomUserDetails userDetails){ - stepService.deleteReference(referenceId); + stepService.deleteReference(referenceId, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(null)); } diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index da83b3b0..9a4b42ec 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -96,11 +96,22 @@ public StepResponse.FindAllStepDTO findAllStep (Long roadmapId, User user) { } // 참고자료 삭제 - public void deleteReference(Long referenceId){ + public void deleteReference(Long referenceId, User user){ Reference reference = getReferenceById(referenceId); + + checkMasterAndManagerPermission(reference.getStep().getRoadmap().getId(), user); // 매니저급만 삭제 가능 + referenceRepository.delete(reference); } + private String checkMasterAndManagerPermission(Long roadmapId, User user) { + UserRoadmap userRoadmap = getUserBelongRoadmap(roadmapId, user.getId()); + + if(!userRoadmap.getRole().equals(GroupRole.ROLE_MASTER.getValue()) && !userRoadmap.getRole().equals(GroupRole.ROLE_MANAGER.getValue())){ + throw new CustomException(ExceptionCode.ROADMAP_FORBIDDEN); + } + return userRoadmap.getRole(); + } private Roadmap getRoadmapById(Long roadmapId) { return roadmapRepository.findById(roadmapId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); @@ -113,4 +124,8 @@ private Step getStepById(Long stepId) { private Reference getReferenceById(Long referenceId){ return referenceRepository.findById(referenceId).orElseThrow(() -> new CustomException(ExceptionCode.REFERENCE_NOT_FOUND)); } + + private UserRoadmap getUserBelongRoadmap(Long roadmapId, Long userId) { + return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, userId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_BELONG)); + } } From d5e4876586d1447ec02101cefe33fd7eaaa99b20 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 02:13:53 +0900 Subject: [PATCH 14/66] =?UTF-8?q?feat:=20=EC=8A=A4=ED=85=9D=20soft/delete?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/step/StepController.java | 8 ++++++++ .../java/com/example/tily/step/StepService.java | 16 ++++++++++++++++ .../java/com/example/tily/til/TilRepository.java | 5 +++++ 3 files changed, 29 insertions(+) diff --git a/src/main/java/com/example/tily/step/StepController.java b/src/main/java/com/example/tily/step/StepController.java index c87ecd24..5219fb46 100644 --- a/src/main/java/com/example/tily/step/StepController.java +++ b/src/main/java/com/example/tily/step/StepController.java @@ -37,6 +37,14 @@ public ResponseEntity findAllStep(@PathVariable("roadmapId") Long roadmapId, return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } + // step 삭제 + @DeleteMapping("/step/{stepId}") + public ResponseEntity deleteStep(@PathVariable Long stepId, @AuthenticationPrincipal CustomUserDetails userDetails){ + stepService.deleteStep(stepId, userDetails.getUser()); + + return ResponseEntity.ok().body(ApiUtils.success(null)); + } + // 참고자료 삭제 @DeleteMapping("/reference/{referenceId}") public ResponseEntity deleteReference(@PathVariable Long referenceId, @AuthenticationPrincipal CustomUserDetails userDetails){ diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index 9a4b42ec..e4ec7cce 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -95,6 +95,22 @@ public StepResponse.FindAllStepDTO findAllStep (Long roadmapId, User user) { return new StepResponse.FindAllStepDTO(stepDTOs, progress, myRole); } + // step 삭제 + @Transactional + public void deleteStep(Long stepId, User user){ + Step step = getStepById(stepId); + + checkMasterAndManagerPermission(step.getRoadmap().getId(), user); // 매니저급만 삭제 가능 + + List tils = tilRepository.findByStepId(stepId); + List tilIds = tils.stream() + .map(Til::getId) + .collect(Collectors.toList()); + tilRepository.softDeleteAllTils(tilIds); + + stepRepository.delete(step); + } + // 참고자료 삭제 public void deleteReference(Long referenceId, User user){ Reference reference = getReferenceById(referenceId); diff --git a/src/main/java/com/example/tily/til/TilRepository.java b/src/main/java/com/example/tily/til/TilRepository.java index 08185eb7..75c67ddd 100644 --- a/src/main/java/com/example/tily/til/TilRepository.java +++ b/src/main/java/com/example/tily/til/TilRepository.java @@ -3,6 +3,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.web.bind.annotation.RequestParam; @@ -54,4 +55,8 @@ List findTilsByUserIdAndDateRange(@Param("userId") Long userId, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate); + @Modifying + @Query("update Til t SET t.isDeleted = true WHERE t.isDeleted = false AND t.id IN :tilIds") + void softDeleteAllTils(List tilIds); + } From 164440c513736b9cb2ba1301b37b265f68400cd9 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 02:34:33 +0900 Subject: [PATCH 15/66] =?UTF-8?q?fix:=20=EC=8A=A4=ED=85=9D=20soft/delete?= =?UTF-8?q?=EC=8B=9C=20comment=EC=99=80=20userStep=EB=8F=84=20soft/delete?= =?UTF-8?q?=20=EB=90=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/tily/comment/CommentRepository.java | 5 +++++ .../java/com/example/tily/step/StepService.java | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/main/java/com/example/tily/comment/CommentRepository.java b/src/main/java/com/example/tily/comment/CommentRepository.java index e051e84f..1bc15fba 100644 --- a/src/main/java/com/example/tily/comment/CommentRepository.java +++ b/src/main/java/com/example/tily/comment/CommentRepository.java @@ -1,6 +1,7 @@ package com.example.tily.comment; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -10,4 +11,8 @@ public interface CommentRepository extends JpaRepository { @Query("select c from Comment c join fetch c.writer where c.til.id=:tilId") List findByTilId(@Param("tilId") Long tilId); + + @Modifying + @Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.til.id IN :tilIds") + void softDeleteAllCommentsByTilIds(List tilIds); } diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index e4ec7cce..a4752f3d 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -2,6 +2,7 @@ import com.example.tily._core.errors.exception.ExceptionCode; import com.example.tily._core.errors.exception.CustomException; +import com.example.tily.comment.CommentRepository; import com.example.tily.roadmap.Roadmap; import com.example.tily.roadmap.RoadmapRepository; import com.example.tily.roadmap.relation.GroupRole; @@ -31,6 +32,7 @@ public class StepService { private final TilRepository tilRepository; private final UserRoadmapRepository userRoadmapRepository; private final UserStepRepository userStepRepository; + private final CommentRepository commentRepository; // 개인 로드맵(카테고리)의 step 생성하기 @Transactional @@ -106,8 +108,18 @@ public void deleteStep(Long stepId, User user){ List tilIds = tils.stream() .map(Til::getId) .collect(Collectors.toList()); + + // 1. Til과 연관된 Comment들을 삭제한다. + commentRepository.softDeleteAllCommentsByTilIds(tilIds); + + // 2. Til들을 삭제한다 tilRepository.softDeleteAllTils(tilIds); + // 3. UserStep을 삭제한다 + UserStep userStep = getUserStepByUserIdAndStepId(user.getId(), stepId); + userStepRepository.delete(userStep); + + // 4. Step을 삭제한다 stepRepository.delete(step); } @@ -144,4 +156,8 @@ private Reference getReferenceById(Long referenceId){ private UserRoadmap getUserBelongRoadmap(Long roadmapId, Long userId) { return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, userId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_BELONG)); } + + private UserStep getUserStepByUserIdAndStepId(Long userId, Long stepId){ + return userStepRepository.findByUserIdAndStepId(userId, stepId).orElseThrow(() -> new CustomException(ExceptionCode.STEP_NOT_INCLUDE)); + } } From ba0d7c3deef2c1dae2d67d0be01edfa5fee5a7af Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 02:43:46 +0900 Subject: [PATCH 16/66] =?UTF-8?q?fix:=20=EC=8A=A4=ED=85=9D=20soft/delete?= =?UTF-8?q?=EC=8B=9C=20reference=EB=8F=84=20soft/delete=20=EB=90=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/step/StepService.java | 8 ++++++++ .../example/tily/step/reference/ReferenceRepository.java | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index a4752f3d..bfbb99bb 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -109,12 +109,20 @@ public void deleteStep(Long stepId, User user){ .map(Til::getId) .collect(Collectors.toList()); + List references = referenceRepository.findByStepId(stepId); + List referenceIds = references.stream() + .map(Reference::getId) + .collect(Collectors.toList()); + // 1. Til과 연관된 Comment들을 삭제한다. commentRepository.softDeleteAllCommentsByTilIds(tilIds); // 2. Til들을 삭제한다 tilRepository.softDeleteAllTils(tilIds); + // 3. Reference들을 삭제한다. + referenceRepository.softDeleteAllReferences(referenceIds); + // 3. UserStep을 삭제한다 UserStep userStep = getUserStepByUserIdAndStepId(user.getId(), stepId); userStepRepository.delete(userStep); diff --git a/src/main/java/com/example/tily/step/reference/ReferenceRepository.java b/src/main/java/com/example/tily/step/reference/ReferenceRepository.java index 8fba4d17..8f4fee51 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceRepository.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceRepository.java @@ -2,9 +2,15 @@ import com.example.tily.step.Step; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import java.util.List; public interface ReferenceRepository extends JpaRepository { List findByStepId(Long stepId); -} + + @Modifying + @Query("update Reference r SET r.isDeleted = true WHERE r.isDeleted = false AND r.id IN :referenceIds") + void softDeleteAllReferences(List referenceIds); +} \ No newline at end of file From 869e3c2a91af6ab1cb6de89f9ea31385ae3e4a2a Mon Sep 17 00:00:00 2001 From: suuding Date: Tue, 7 Nov 2023 03:18:58 +0900 Subject: [PATCH 17/66] =?UTF-8?q?feat=20:=20reference=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?,=20=EC=A1=B0=ED=9A=8C=20api=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/step/StepController.java | 5 --- .../step/reference/ReferenceController.java | 35 +++++++++++++++++++ .../tily/step/reference/ReferenceRequest.java | 9 +++++ 3 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/example/tily/step/reference/ReferenceController.java create mode 100644 src/main/java/com/example/tily/step/reference/ReferenceRequest.java diff --git a/src/main/java/com/example/tily/step/StepController.java b/src/main/java/com/example/tily/step/StepController.java index 4799e87e..6da8e275 100644 --- a/src/main/java/com/example/tily/step/StepController.java +++ b/src/main/java/com/example/tily/step/StepController.java @@ -23,11 +23,6 @@ public ResponseEntity createIndividualStep(@RequestBody @Valid StepRequest.Cr return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } - // 특정 step의 참고자료 목록 조회 - @GetMapping("/roadmaps/{roadmapsId}/steps/{stepsId}/references") - public ResponseEntity findReference(@PathVariable Long stepsId, @AuthenticationPrincipal CustomUserDetails userDetails){ - StepResponse.FindReferenceDTO responseDTO = stepService.findReference(stepsId); - return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } // 특정 로드맵의 step 목록 전체 조회 diff --git a/src/main/java/com/example/tily/step/reference/ReferenceController.java b/src/main/java/com/example/tily/step/reference/ReferenceController.java new file mode 100644 index 00000000..439d62d0 --- /dev/null +++ b/src/main/java/com/example/tily/step/reference/ReferenceController.java @@ -0,0 +1,35 @@ +package com.example.tily.step.reference; + +import com.example.tily._core.security.CustomUserDetails; +import com.example.tily._core.utils.ApiUtils; +import org.springframework.validation.Errors; +import com.example.tily.step.StepResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +@RestController +@RequiredArgsConstructor +public class ReferenceController { + + private final ReferenceService referenceService; + + // step의 참고자료 생성하기 + @PostMapping("/roadmaps/{roadmapId}/steps/{stepId}/references") + public ResponseEntity createReference(@RequestBody @Valid ReferenceRequest.CreateReferenceDTO requestDTO, Errors errors, + @PathVariable("roadmapId") Long roadmapId, @PathVariable("stepId") Long stepId, + @AuthenticationPrincipal CustomUserDetails userDetails){ + referenceService.createReference(requestDTO, roadmapId, stepId, userDetails.getUser()); + return ResponseEntity.ok().body(ApiUtils.success(null)); + } + + // step의 참고자료 목록 조회 + @GetMapping("/roadmaps/{roadmapsId}/steps/{stepsId}/references") + public ResponseEntity findReference(@PathVariable Long stepsId, @AuthenticationPrincipal CustomUserDetails userDetails){ + StepResponse.FindReferenceDTO responseDTO = referenceService.findReference(stepsId, userDetails.getUser()); + return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); + } +} diff --git a/src/main/java/com/example/tily/step/reference/ReferenceRequest.java b/src/main/java/com/example/tily/step/reference/ReferenceRequest.java new file mode 100644 index 00000000..f70254c0 --- /dev/null +++ b/src/main/java/com/example/tily/step/reference/ReferenceRequest.java @@ -0,0 +1,9 @@ +package com.example.tily.step.reference; + +import java.time.LocalDateTime; + +public class ReferenceRequest { + + public record CreateReferenceDTO(String category, String link) { + } +} From 7fefd08ecbdb60775804d5eb8f76419e76f60f68 Mon Sep 17 00:00:00 2001 From: suuding Date: Tue, 7 Nov 2023 03:19:47 +0900 Subject: [PATCH 18/66] =?UTF-8?q?feat=20:=20reference=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=ED=95=98=EA=B8=B0,=20=EC=A1=B0=ED=9A=8C=ED=95=98=EA=B8=B0=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tily/step/reference/Reference.java | 4 -- .../tily/step/reference/ReferenceService.java | 69 +++++++++++++++++++ 2 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/example/tily/step/reference/ReferenceService.java diff --git a/src/main/java/com/example/tily/step/reference/Reference.java b/src/main/java/com/example/tily/step/reference/Reference.java index 6ffbcdf1..aed4c83a 100644 --- a/src/main/java/com/example/tily/step/reference/Reference.java +++ b/src/main/java/com/example/tily/step/reference/Reference.java @@ -35,8 +35,4 @@ public Reference(Step step, Long id, String category, String link) { this.category = category; this.link = link; } - - public void update(String link){ - this.link = link; - } } \ No newline at end of file diff --git a/src/main/java/com/example/tily/step/reference/ReferenceService.java b/src/main/java/com/example/tily/step/reference/ReferenceService.java new file mode 100644 index 00000000..a055ac78 --- /dev/null +++ b/src/main/java/com/example/tily/step/reference/ReferenceService.java @@ -0,0 +1,69 @@ +package com.example.tily.step.reference; + +import com.example.tily._core.errors.exception.CustomException; +import com.example.tily._core.errors.exception.ExceptionCode; +import com.example.tily.roadmap.Roadmap; +import com.example.tily.roadmap.RoadmapRepository; +import com.example.tily.step.Step; +import com.example.tily.step.StepRepository; +import com.example.tily.step.StepResponse; +import com.example.tily.user.User; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; + +@Transactional(readOnly = true) +@RequiredArgsConstructor +@Service +public class ReferenceService { + + private final ReferenceRepository referenceRepository; + private final StepRepository stepRepository; + private final RoadmapRepository roadmapRepository; + + // step의 참고자료 생성하기 + @Transactional + public void createReference(ReferenceRequest.CreateReferenceDTO requestDTO, Long roadmapId, Long stepId, User user) { + Roadmap roadmap = roadmapRepository.findById(roadmapId) + .orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); + + Step step = getStepById(stepId); + + Reference reference = Reference.builder() + .step(step) + .category(requestDTO.category()) + .link(requestDTO.link()) + .build(); + referenceRepository.save(reference); + } + + // step의 참고자료 목록 조회하기 + public StepResponse.FindReferenceDTO findReference(Long stepId, User user){ + Step step = getStepById(stepId); + + List references = referenceRepository.findByStepId(stepId); + + List youtubeDTOs = new ArrayList<>(); + List webDTOs = new ArrayList<>(); + + for(Reference reference : references){ + String category = reference.getCategory(); + Long id = reference.getId(); + String link = reference.getLink(); + + if(category.equals("youtube")) + youtubeDTOs.add(new StepResponse.FindReferenceDTO.YoutubeDTO(id, link)); + else if(category.equals("web")) + webDTOs.add(new StepResponse.FindReferenceDTO.WebDTO(id, link)); + } + + return new StepResponse.FindReferenceDTO(step, youtubeDTOs, webDTOs); + } + + private Step getStepById(Long stepId) { + return stepRepository.findById(stepId).orElseThrow(() -> new CustomException(ExceptionCode.STEP_NOT_FOUND)); + } +} From c496afb1f8c495aa02f367846d840fc2040681e0 Mon Sep 17 00:00:00 2001 From: suuding Date: Tue, 7 Nov 2023 03:21:38 +0900 Subject: [PATCH 19/66] =?UTF-8?q?feat=20:=20step=20=EC=83=9D=EC=84=B1=20ap?= =?UTF-8?q?i=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/step/StepController.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/example/tily/step/StepController.java b/src/main/java/com/example/tily/step/StepController.java index 6da8e275..d70b327e 100644 --- a/src/main/java/com/example/tily/step/StepController.java +++ b/src/main/java/com/example/tily/step/StepController.java @@ -23,6 +23,12 @@ public ResponseEntity createIndividualStep(@RequestBody @Valid StepRequest.Cr return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } + // 특정 로드맵의 step 생성 + @PostMapping("/roadmaps/{roadmapId}/steps") + public ResponseEntity createStep(@RequestBody @Valid StepRequest.CreateStepDTO requestDTO, Errors errors, + @PathVariable("roadmapId") Long roadmapId, @AuthenticationPrincipal CustomUserDetails userDetails) { + stepService.createStep(requestDTO, roadmapId, userDetails.getUser()); + return ResponseEntity.ok().body(ApiUtils.success(null)); } // 특정 로드맵의 step 목록 전체 조회 From f56e130c8cdbc7591904957a4f89d95a6d9140b9 Mon Sep 17 00:00:00 2001 From: suuding Date: Tue, 7 Nov 2023 03:21:55 +0900 Subject: [PATCH 20/66] =?UTF-8?q?feat=20:=20step=20=EC=88=98=EC=A0=95=20ap?= =?UTF-8?q?i=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/step/StepController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/example/tily/step/StepController.java b/src/main/java/com/example/tily/step/StepController.java index d70b327e..a4268498 100644 --- a/src/main/java/com/example/tily/step/StepController.java +++ b/src/main/java/com/example/tily/step/StepController.java @@ -37,4 +37,13 @@ public ResponseEntity findAllStep(@PathVariable("roadmapId") Long roadmapId, StepResponse.FindAllStepDTO responseDTO = stepService.findAllStep(roadmapId, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } + + // 특정 로드맵의 step 수정 + @PostMapping("/roadmaps/{roadmapId}/steps/{stepId}") + public ResponseEntity createStep(@RequestBody @Valid StepRequest.UpdateStepDTO requestDTO, Errors errors, + @PathVariable("roadmapId") Long roadmapId, @PathVariable("stepId") Long stepId, + @AuthenticationPrincipal CustomUserDetails userDetails) { + stepService.updateStep(requestDTO, roadmapId, stepId, userDetails.getUser()); + return ResponseEntity.ok().body(ApiUtils.success(null)); + } } \ No newline at end of file From 0170d570b4b18bb4d81fe3233f5ade6664c59d2f Mon Sep 17 00:00:00 2001 From: suuding Date: Tue, 7 Nov 2023 03:22:36 +0900 Subject: [PATCH 21/66] =?UTF-8?q?feat=20:=20step=20=EC=83=9D=EC=84=B1,=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=ED=95=98=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/step/Step.java | 6 +- .../com/example/tily/step/StepRequest.java | 16 ++++- .../com/example/tily/step/StepResponse.java | 6 ++ .../com/example/tily/step/StepService.java | 65 +++++++++++++------ 4 files changed, 70 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/example/tily/step/Step.java b/src/main/java/com/example/tily/step/Step.java index 4dfec685..3d6c4658 100644 --- a/src/main/java/com/example/tily/step/Step.java +++ b/src/main/java/com/example/tily/step/Step.java @@ -42,8 +42,8 @@ public Step(Long id, Roadmap roadmap, String title, String description, LocalDat this.dueDate = dueDate; } - public void update(String title, String description){ - this.title = title; - this.description = description; + public void update(StepRequest.UpdateStepDTO requestDTO){ + this.title = requestDTO.title(); + this.description = requestDTO.description(); } } \ No newline at end of file diff --git a/src/main/java/com/example/tily/step/StepRequest.java b/src/main/java/com/example/tily/step/StepRequest.java index e8090da2..1b4a36cc 100644 --- a/src/main/java/com/example/tily/step/StepRequest.java +++ b/src/main/java/com/example/tily/step/StepRequest.java @@ -1,9 +1,23 @@ package com.example.tily.step; import javax.validation.constraints.NotBlank; +import java.time.LocalDateTime; public class StepRequest { - public record CreateIndividualStepDTO(@NotBlank(message = "스텝 제목을 입력해주세요.") String title) { + public record CreateIndividualStepDTO(@NotBlank(message = "step의 제목을 입력해주세요.") String title) { } + + public record CreateStepDTO( + @NotBlank(message = "step의 제목을 입력해주세요.") + String title, + String description, + LocalDateTime dueDate + ) {} + + public record UpdateStepDTO( + String title, + String description, + LocalDateTime dueDate + ) {} } \ No newline at end of file diff --git a/src/main/java/com/example/tily/step/StepResponse.java b/src/main/java/com/example/tily/step/StepResponse.java index 3d916336..8319ecc6 100644 --- a/src/main/java/com/example/tily/step/StepResponse.java +++ b/src/main/java/com/example/tily/step/StepResponse.java @@ -12,6 +12,12 @@ public CreateIndividualStepDTO(Step step) { } } + public record CreateStepDTO(Long id) { + public CreateStepDTO(Step step) { + this(step.getId()); + } + } + public record FindReferenceDTO(Long id, String description, List youtubes, List webs) { public FindReferenceDTO(Step step, List youtubeDTOs, List webDTOs) { this(step.getId(), step.getDescription(), youtubeDTOs, webDTOs); diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index 458291a0..0cdff795 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -27,7 +27,6 @@ public class StepService { private final RoadmapRepository roadmapRepository; private final StepRepository stepRepository; - private final ReferenceRepository referenceRepository; private final TilRepository tilRepository; private final UserRoadmapRepository userRoadmapRepository; private final UserStepRepository userStepRepository; @@ -51,27 +50,45 @@ public StepResponse.CreateIndividualStepDTO createIndividualStep(Long id, StepRe return new StepResponse.CreateIndividualStepDTO(step); } - // step의 참고자료 목록 조회 - public StepResponse.FindReferenceDTO findReference(Long stepId){ - Step step = getStepById(stepId); + // step 생성하기 + @Transactional + public StepResponse.CreateStepDTO createStep(StepRequest.CreateStepDTO requestDTO, Long roadmapId, User user) { + checkMasterAndManagerPermission(roadmapId, user); // 관리자 권한 확인 + + Roadmap roadmap = roadmapRepository.findById(roadmapId) + .orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); + + Step step = Step.builder() + .roadmap(roadmap) + .title(requestDTO.title()) + .description(requestDTO.description()) + .dueDate(requestDTO.dueDate()) + .build(); + stepRepository.save(step); - List references = referenceRepository.findByStepId(stepId); + // 해당 로드맵에 속한 학생들에 대해, UserStep에 넣기 + List users = userRoadmapRepository.findByRoadmapIdAndIsAcceptTrue(roadmapId).stream().map(UserRoadmap::getUser).toList(); + for (User u : users) { + UserStep userStep = UserStep.builder() + .roadmap(roadmap) + .step(step) + .user(u) + .isSubmit(false) + .build(); + userStepRepository.save(userStep); + } - List youtubeDTOs = new ArrayList<>(); - List webDTOs = new ArrayList<>(); + return new StepResponse.CreateStepDTO(step); + } - for(Reference reference : references){ - String category = reference.getCategory(); - Long id = reference.getId(); - String link = reference.getLink(); + // step 수정하기 + public void updateStep(StepRequest.UpdateStepDTO requestDTO, Long roadmapId, Long stepId, User user) { + checkMasterAndManagerPermission(roadmapId, user); // 관리자 권한 확인 - if(category.equals("youtube")) - youtubeDTOs.add(new StepResponse.FindReferenceDTO.YoutubeDTO(id, link)); - else if(category.equals("web")) - webDTOs.add(new StepResponse.FindReferenceDTO.WebDTO(id, link)); - } + Step step = stepRepository.findById(stepId) + .orElseThrow(() -> new CustomException(ExceptionCode.STEP_NOT_FOUND)); - return new StepResponse.FindReferenceDTO(step, youtubeDTOs, webDTOs); + step.update(requestDTO); } // 로드맵의 step 목록 전체 조회 @@ -99,7 +116,17 @@ private Roadmap getRoadmapById(Long roadmapId) { return roadmapRepository.findById(roadmapId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); } - private Step getStepById(Long stepId) { - return stepRepository.findById(stepId).orElseThrow(() -> new CustomException(ExceptionCode.STEP_NOT_FOUND)); + private String checkMasterAndManagerPermission(Long roadmapId, User user) { // 매니저급만 접근 + UserRoadmap userRoadmap = getUserBelongRoadmap(roadmapId, user.getId()); + + if(!userRoadmap.getRole().equals(GroupRole.ROLE_MASTER.getValue()) && !userRoadmap.getRole().equals(GroupRole.ROLE_MANAGER.getValue())){ + throw new CustomException(ExceptionCode.ROADMAP_FORBIDDEN); + } + return userRoadmap.getRole(); + } + + // 해당 로드맵에 속한 user + private UserRoadmap getUserBelongRoadmap(Long roadmapId, Long userId) { + return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, userId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_BELONG)); } } From d10dbcf0bab649a17dd65ec8e1e82783091f50de Mon Sep 17 00:00:00 2001 From: suuding Date: Tue, 7 Nov 2023 03:23:09 +0900 Subject: [PATCH 22/66] =?UTF-8?q?fix=20:=20=EB=A1=9C=EB=93=9C=EB=A7=B5=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=ED=95=98=EA=B8=B0,=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=ED=95=98=EA=B8=B0=20api=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/roadmap/Roadmap.java | 3 +- .../example/tily/roadmap/RoadmapRequest.java | 4 +- .../example/tily/roadmap/RoadmapService.java | 102 +----------------- 3 files changed, 8 insertions(+), 101 deletions(-) diff --git a/src/main/java/com/example/tily/roadmap/Roadmap.java b/src/main/java/com/example/tily/roadmap/Roadmap.java index 191cdb3c..5445efad 100644 --- a/src/main/java/com/example/tily/roadmap/Roadmap.java +++ b/src/main/java/com/example/tily/roadmap/Roadmap.java @@ -60,10 +60,9 @@ public Roadmap(Long id, User creator, Category category, String name, String des this.image = image; } - public void update(RoadmapRequest.RoadmapDTO roadmap){ + public void update(RoadmapRequest.UpdateGroupRoadmapDTO roadmap){ this.name = roadmap.name(); this.description = roadmap.description(); - this.code = roadmap.code(); this.isPublic = roadmap.isPublic(); this.isRecruit = roadmap.isRecruit(); } diff --git a/src/main/java/com/example/tily/roadmap/RoadmapRequest.java b/src/main/java/com/example/tily/roadmap/RoadmapRequest.java index 07f6cccb..fadb0373 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapRequest.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapRequest.java @@ -15,13 +15,13 @@ public record CreateIndividualRoadmapDTO(@NotBlank(message = "이름을 입력 @Size(min=2, max=20, message = "이름은 2자에서 20자 이내여야 합니다.") String name) { } - public record CreateGroupRoadmapDTO(RoadmapDTO roadmap, List steps) { + public record CreateGroupRoadmapDTO(String name, String description, Boolean isPublic) { } public record CreateTilyRoadmapDTO(RoadmapDTO roadmap, List steps) { } - public record UpdateGroupRoadmapDTO(RoadmapDTO roadmap, List steps) { + public record UpdateGroupRoadmapDTO(String name, String description, Boolean isPublic, Boolean isRecruit) { } public record RoadmapDTO(@NotBlank(message = "이름을 입력해주세요.") String name, String description, String code, Boolean isPublic, Boolean isRecruit){ diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index 73a3d9a8..a9d3324f 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -64,56 +64,16 @@ public RoadmapResponse.CreateRoadmapDTO createGroupRoadmap(RoadmapRequest.Create Roadmap roadmap = Roadmap.builder() .creator(user) .category(Category.CATEGORY_GROUP) - .name(requestDTO.roadmap().name()) - .description(requestDTO.roadmap().description()) - .isPublic(requestDTO.roadmap().isPublic()) // 공개여부 + .name(requestDTO.name()) + .description(requestDTO.description()) + .isPublic(requestDTO.isPublic()) // 공개여부 .currentNum(1L) .code(generateRandomCode()) .isRecruit(true) // 모집여부 - .stepNum(requestDTO.steps().size()) + .stepNum(0) .build(); roadmapRepository.save(roadmap); - List stepDTOS = requestDTO.steps(); - for(RoadmapRequest.StepDTO stepDTO : stepDTOS){ - // step 저장 - Step step = Step.builder() - .roadmap(roadmap) - .title(stepDTO.title()) - .description(stepDTO.description()) - .dueDate(stepDTO.dueDate()!=null ? stepDTO.dueDate() : null) - .build(); - stepRepository.save(step); - - UserStep userStep = UserStep.builder() - .roadmap(roadmap) - .step(step) - .user(user) - .isSubmit(false) - .build(); - userStepRepository.save(userStep); - - // reference 저장 - RoadmapRequest.ReferenceDTOs referenceDTOs = stepDTO.references(); - List references = new ArrayList<>(); - - // (1) youtube - List youtubeDTOs = referenceDTOs.youtube(); - for(RoadmapRequest.ReferenceDTO youtubeDTO : youtubeDTOs){ - Reference reference = Reference.builder().step(step).category("youtube").link(youtubeDTO.link()).build(); - references.add(reference); - } - - // (2) reference - List webDTOs = referenceDTOs.web(); - for(RoadmapRequest.ReferenceDTO webDTO : webDTOs){ - Reference reference = Reference.builder().step(step).category("web").link(webDTO.link()).build(); - references.add(reference); - } - - referenceRepository.saveAll(references); - } - UserRoadmap userRoadmap = UserRoadmap.builder() .roadmap(roadmap) .user(user) @@ -259,59 +219,7 @@ public void updateGroupRoadmap(Long id, RoadmapRequest.UpdateGroupRoadmapDTO req .orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); // roadmap update - roadmap.update(requestDTO.roadmap()); - - // step update - List stepDTOs = requestDTO.steps(); - for(RoadmapRequest.StepDTO stepDTO : stepDTOs){ - Step step = stepRepository.findById(stepDTO.id()).orElse(null); - - // 새로운 step - if (step == null) { - Step newStep = Step.builder() - .roadmap(roadmap) - .title(stepDTO.title()) - .description(stepDTO.description()) - .dueDate(stepDTO.dueDate()!=null ? stepDTO.dueDate() : null) - .build(); - Step newStep1 = stepRepository.save(newStep); - - // 로드맵에 속한 사람들에게 userstep에 넣어야함 - List users = userRoadmapRepository.findByRoadmapIdAndIsAcceptTrue(id).stream().map(UserRoadmap::getUser).toList(); - for (User u : users) { - UserStep userStep = UserStep.builder() - .roadmap(roadmap) - .step(newStep1) - .user(u) - .isSubmit(false) - .build(); - userStepRepository.save(userStep); - } - } else { - step.update(stepDTO.title(),stepDTO.description()); - } - - // reference 업데이트 - for(RoadmapRequest.ReferenceDTO web : stepDTO.references().web()){ - if (web.id() == null) { - Reference newReference = Reference.builder().step(step).category("web").link(web.link()).build(); - referenceRepository.save(newReference); - } else { - Reference reference = referenceRepository.findById(web.id()).orElse(null); - reference.update(web.link()); - } - } - - for(RoadmapRequest.ReferenceDTO youtube : stepDTO.references().youtube()){ - if (youtube.id() == null) { - Reference newReference = Reference.builder().step(step).category("youtube").link(youtube.link()).build(); - referenceRepository.save(newReference); - } else { - Reference reference = referenceRepository.findById(youtube.id()).orElse(null); - reference.update(youtube.link()); - } - } - } + roadmap.update(requestDTO); } public RoadmapResponse.FindAllMyRoadmapDTO findAllMyRoadmaps(User user) { From 34be9017557e0fedd3535f757a2f798fe8ce1b36 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 09:04:07 +0900 Subject: [PATCH 23/66] =?UTF-8?q?feat:=20Til=20soft/delete=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/comment/CommentRepository.java | 4 ++++ .../java/com/example/tily/step/StepService.java | 4 ++-- src/main/java/com/example/tily/til/TilService.java | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/tily/comment/CommentRepository.java b/src/main/java/com/example/tily/comment/CommentRepository.java index 1bc15fba..817433aa 100644 --- a/src/main/java/com/example/tily/comment/CommentRepository.java +++ b/src/main/java/com/example/tily/comment/CommentRepository.java @@ -15,4 +15,8 @@ public interface CommentRepository extends JpaRepository { @Modifying @Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.til.id IN :tilIds") void softDeleteAllCommentsByTilIds(List tilIds); + + @Modifying + @Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.id IN :commentIds") + void softDeleteAllComments(List tilIds); } diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index bfbb99bb..7858c39a 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -123,11 +123,11 @@ public void deleteStep(Long stepId, User user){ // 3. Reference들을 삭제한다. referenceRepository.softDeleteAllReferences(referenceIds); - // 3. UserStep을 삭제한다 + // 4. UserStep을 삭제한다 UserStep userStep = getUserStepByUserIdAndStepId(user.getId(), stepId); userStepRepository.delete(userStep); - // 4. Step을 삭제한다 + // 5. Step을 삭제한다 stepRepository.delete(step); } diff --git a/src/main/java/com/example/tily/til/TilService.java b/src/main/java/com/example/tily/til/TilService.java index 0b5f7745..1e06929f 100644 --- a/src/main/java/com/example/tily/til/TilService.java +++ b/src/main/java/com/example/tily/til/TilService.java @@ -148,6 +148,15 @@ public void deleteTil(Long tilId, User user) { if (checkTilWriterEqualUser(til, user)) throw new CustomException(ExceptionCode.TIL_DELETE_FORBIDDEN); + List comments = getCommentByStepId(tilId); + List commentIds = comments.stream() + .map(Comment::getId) + .collect(Collectors.toList()); + + // 1. Til과 연관된 Comment들을 삭제한다. + commentRepository.softDeleteAllComments(commentIds); + + // 2. Til을 삭제한다. tilRepository.deleteById(tilId); } @@ -187,6 +196,10 @@ private boolean checkTilWriterEqualUser(Til til, User user) { return !til.getWriter().getId().equals(user.getId()); } + private List getCommentByStepId(Long tilId) { + return commentRepository.findByTilId(tilId); + } + // 사용자가 로드맵에 속했는지 private UserRoadmap getUserIncludeRoadmap(Long roadmapId, Long userId) { return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, userId) From 3c5beaeb3dd7dd5eddec392ed55a15d837b88120 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 12:29:07 +0900 Subject: [PATCH 24/66] =?UTF-8?q?feat:=20Roadmap=20soft/delete=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tily/comment/CommentRepository.java | 8 ++-- .../tily/roadmap/RoadmapController.java | 7 +++ .../example/tily/roadmap/RoadmapService.java | 48 +++++++++++++++++++ .../relation/UserRoadmapRepository.java | 5 ++ .../com/example/tily/step/StepRepository.java | 7 ++- .../com/example/tily/step/StepService.java | 16 ++----- .../step/reference/ReferenceRepository.java | 9 ++-- .../step/relation/UserStepRepository.java | 9 ++++ .../com/example/tily/til/TilRepository.java | 5 +- .../java/com/example/tily/til/TilService.java | 7 +-- 10 files changed, 91 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/example/tily/comment/CommentRepository.java b/src/main/java/com/example/tily/comment/CommentRepository.java index 817433aa..cfc6e0aa 100644 --- a/src/main/java/com/example/tily/comment/CommentRepository.java +++ b/src/main/java/com/example/tily/comment/CommentRepository.java @@ -13,10 +13,10 @@ public interface CommentRepository extends JpaRepository { List findByTilId(@Param("tilId") Long tilId); @Modifying - @Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.til.id IN :tilIds") - void softDeleteAllCommentsByTilIds(List tilIds); + @Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.til.id = :tilId") + void softDeleteCommentsByTilId(Long tilId); @Modifying - @Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.id IN :commentIds") - void softDeleteAllComments(List tilIds); + @Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.til.id IN :tilIds") + void softDeleteCommentsByTilIds(List tilIds); } diff --git a/src/main/java/com/example/tily/roadmap/RoadmapController.java b/src/main/java/com/example/tily/roadmap/RoadmapController.java index f7430729..2cb96d71 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapController.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapController.java @@ -148,4 +148,11 @@ public ResponseEntity findTilOfStep(@PathVariable Long groupId, @PathVariable RoadmapResponse.FindTilOfStepDTO responseDTO = roadmapService.findTilOfStep(groupId, stepId, isSubmit, isMember, name); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } + + // 그룹 로드맵 삭제 + @DeleteMapping("/roadmaps/{id}") + public ResponseEntity deleteRoadmap(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ + roadmapService.deleteRoadmap(id, userDetails.getUser()); + return ResponseEntity.ok().body(null); + } } \ No newline at end of file diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index 74ee4208..eca78952 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -2,6 +2,7 @@ import com.example.tily._core.errors.exception.CustomException; import com.example.tily._core.errors.exception.ExceptionCode; +import com.example.tily.comment.CommentRepository; import com.example.tily.roadmap.relation.GroupRole; import com.example.tily.roadmap.relation.UserRoadmap; import com.example.tily.roadmap.relation.UserRoadmapRepository; @@ -35,6 +36,7 @@ public class RoadmapService { private final TilRepository tilRepository; private final UserRoadmapRepository userRoadmapRepository; private final UserStepRepository userStepRepository; + private final CommentRepository commentRepository; @Transactional public RoadmapResponse.CreateRoadmapDTO createIndividualRoadmap(RoadmapRequest.CreateIndividualRoadmapDTO requestDTO, User user){ @@ -541,6 +543,44 @@ public RoadmapResponse.FindTilOfStepDTO findTilOfStep(Long groupsId, Long stepId return new RoadmapResponse.FindTilOfStepDTO(members); } + @Transactional + public void deleteRoadmap(Long roadmapId, User user){ + Roadmap roadmap = getRoadmapById(roadmapId); + + checkMasterAndManagerPermission(roadmapId, user); + + List tils = getTilsByRoadmapId(roadmapId); + List tilIds = tils.stream() + .map(Til::getId) + .collect(Collectors.toList()); + + List steps = getStepsByRoadmapId(roadmapId); + List stepIds = steps.stream() + .map(Step::getId) + .collect(Collectors.toList()); + + // 1. Til과 연관된 Comment들을 삭제한다. + commentRepository.softDeleteCommentsByTilIds(tilIds); + + // 2. Til을 삭제한다. + tilRepository.softDeleteTilsByTilIds(tilIds); + + // 3. Reference들을 삭제한다 + referenceRepository.softDeleteReferenceByStepIds(stepIds); + + // 4. Step들을 삭제한다. + stepRepository.softDeleteStepByStepIds(stepIds); + + // 5. UserStep들을 삭제한다. + userStepRepository.softDeleteUserStepByStepIds(stepIds); + + // 6. UserRoadmap을 삭제한다 + userRoadmapRepository.softDeleteUserRoadmapByRoadmapId(roadmapId); + + // 7. Roadmap을 삭제한다 + roadmapRepository.delete(roadmap); + } + private static String generateRandomCode() { String upperAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String lowerAlphabet = "abcdefghijklmnopqrstuvwxyz"; @@ -595,6 +635,14 @@ private Roadmap getRoadmapById(Long roadmapId) { return roadmapRepository.findById(roadmapId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); } + private List getStepsByRoadmapId(Long roadmapId){ + return stepRepository.findByRoadmapId(roadmapId); + } + + private List getTilsByRoadmapId(Long roadmapId){ + return tilRepository.findByRoadmapId(roadmapId); + } + // 해당 로드맵에 속하지 않은 user private UserRoadmap getUserNotBelongRoadmap(Long roadmapId, Long userId) { return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptFalse(roadmapId, userId).orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_FOUND)); diff --git a/src/main/java/com/example/tily/roadmap/relation/UserRoadmapRepository.java b/src/main/java/com/example/tily/roadmap/relation/UserRoadmapRepository.java index f9b36c81..6a361d5b 100644 --- a/src/main/java/com/example/tily/roadmap/relation/UserRoadmapRepository.java +++ b/src/main/java/com/example/tily/roadmap/relation/UserRoadmapRepository.java @@ -2,6 +2,7 @@ import com.example.tily.roadmap.Roadmap; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -26,4 +27,8 @@ public interface UserRoadmapRepository extends JpaRepository @Query("select ur from UserRoadmap ur where ur.roadmap.id=:roadmapId and (:name is null or ur.user.name like %:name%)") List findByRoadmapIdAndIsAcceptTrueAndName(@Param("roadmapId") Long roadmapId, @Param("name") String name); + + @Modifying + @Query("update UserRoadmap ur SET ur.isDeleted = true WHERE ur.isDeleted = false AND ur.roadmap.id IN :roadmapId") + void softDeleteUserRoadmapByRoadmapId(Long roadmapId); } diff --git a/src/main/java/com/example/tily/step/StepRepository.java b/src/main/java/com/example/tily/step/StepRepository.java index 4bebcb3a..8ef75b54 100644 --- a/src/main/java/com/example/tily/step/StepRepository.java +++ b/src/main/java/com/example/tily/step/StepRepository.java @@ -1,8 +1,7 @@ package com.example.tily.step; -import com.example.tily.roadmap.Roadmap; -import com.example.tily.step.reference.Reference; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -20,4 +19,8 @@ public interface StepRepository extends JpaRepository { @Query("select s from Step s join fetch s.roadmap where s.roadmap.id=:roadmapId") List findByRoadmapId(@Param("roadmapId") Long roadmapId); + + @Modifying + @Query("update Step s SET s.isDeleted = true WHERE s.isDeleted = false AND s.id IN :stepIds") + void softDeleteStepByStepIds(List stepIds); } diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index 7858c39a..7a7a9fce 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -109,23 +109,17 @@ public void deleteStep(Long stepId, User user){ .map(Til::getId) .collect(Collectors.toList()); - List references = referenceRepository.findByStepId(stepId); - List referenceIds = references.stream() - .map(Reference::getId) - .collect(Collectors.toList()); - // 1. Til과 연관된 Comment들을 삭제한다. - commentRepository.softDeleteAllCommentsByTilIds(tilIds); + commentRepository.softDeleteCommentsByTilIds(tilIds); // 2. Til들을 삭제한다 - tilRepository.softDeleteAllTils(tilIds); + tilRepository.softDeleteTilsByTilIds(tilIds); // 3. Reference들을 삭제한다. - referenceRepository.softDeleteAllReferences(referenceIds); + referenceRepository.softDeleteReferenceByStepId(stepId); // 4. UserStep을 삭제한다 - UserStep userStep = getUserStepByUserIdAndStepId(user.getId(), stepId); - userStepRepository.delete(userStep); + userStepRepository.softDeleteUserStepByStepId(stepId); // 5. Step을 삭제한다 stepRepository.delete(step); @@ -165,7 +159,7 @@ private UserRoadmap getUserBelongRoadmap(Long roadmapId, Long userId) { return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, userId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_BELONG)); } - private UserStep getUserStepByUserIdAndStepId(Long userId, Long stepId){ + private UserStep getUserStep(Long userId, Long stepId){ return userStepRepository.findByUserIdAndStepId(userId, stepId).orElseThrow(() -> new CustomException(ExceptionCode.STEP_NOT_INCLUDE)); } } diff --git a/src/main/java/com/example/tily/step/reference/ReferenceRepository.java b/src/main/java/com/example/tily/step/reference/ReferenceRepository.java index 8f4fee51..e0b005ca 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceRepository.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceRepository.java @@ -1,6 +1,5 @@ package com.example.tily.step.reference; -import com.example.tily.step.Step; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -11,6 +10,10 @@ public interface ReferenceRepository extends JpaRepository { List findByStepId(Long stepId); @Modifying - @Query("update Reference r SET r.isDeleted = true WHERE r.isDeleted = false AND r.id IN :referenceIds") - void softDeleteAllReferences(List referenceIds); + @Query("update Reference r SET r.isDeleted = true WHERE r.isDeleted = false AND r.step.id IN :stepIds") + void softDeleteReferenceByStepIds(List stepIds); // 여러 step에 대한 reference 삭제 + + @Modifying + @Query("update Reference r SET r.isDeleted = true WHERE r.isDeleted = false AND r.step.id = :stepId") + void softDeleteReferenceByStepId(Long stepId); // 하나의 step에 대한 reference 삭제 } \ No newline at end of file diff --git a/src/main/java/com/example/tily/step/relation/UserStepRepository.java b/src/main/java/com/example/tily/step/relation/UserStepRepository.java index a97abefe..59239923 100644 --- a/src/main/java/com/example/tily/step/relation/UserStepRepository.java +++ b/src/main/java/com/example/tily/step/relation/UserStepRepository.java @@ -1,6 +1,7 @@ package com.example.tily.step.relation; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -22,4 +23,12 @@ List findAllByStepIdAndIsSubmitAndName(@Param("stepId") Long stepId, @Param("name") String name); Optional findByStepIdAndUserIdAndIsSubmitTrue(Long stepId, Long userId); + + @Modifying + @Query("update UserStep us SET us.isDeleted = true WHERE us.isDeleted = false AND us.step.id IN :stepIds") + void softDeleteUserStepByStepIds(List stepIds); // 여러 step들에 대한 UserStep 삭제 + + @Modifying + @Query("update UserStep us SET us.isDeleted = true WHERE us.isDeleted = false AND us.step.id = :stepId") + void softDeleteUserStepByStepId(Long stepId); // 하나의 step에 대한 UserStep 삭제 } diff --git a/src/main/java/com/example/tily/til/TilRepository.java b/src/main/java/com/example/tily/til/TilRepository.java index 75c67ddd..de53c0ab 100644 --- a/src/main/java/com/example/tily/til/TilRepository.java +++ b/src/main/java/com/example/tily/til/TilRepository.java @@ -6,9 +6,7 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import org.springframework.web.bind.annotation.RequestParam; -import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -57,6 +55,5 @@ List findTilsByUserIdAndDateRange(@Param("userId") Long userId, @Modifying @Query("update Til t SET t.isDeleted = true WHERE t.isDeleted = false AND t.id IN :tilIds") - void softDeleteAllTils(List tilIds); - + void softDeleteTilsByTilIds(List tilIds); } diff --git a/src/main/java/com/example/tily/til/TilService.java b/src/main/java/com/example/tily/til/TilService.java index 1e06929f..30f80845 100644 --- a/src/main/java/com/example/tily/til/TilService.java +++ b/src/main/java/com/example/tily/til/TilService.java @@ -148,13 +148,8 @@ public void deleteTil(Long tilId, User user) { if (checkTilWriterEqualUser(til, user)) throw new CustomException(ExceptionCode.TIL_DELETE_FORBIDDEN); - List comments = getCommentByStepId(tilId); - List commentIds = comments.stream() - .map(Comment::getId) - .collect(Collectors.toList()); - // 1. Til과 연관된 Comment들을 삭제한다. - commentRepository.softDeleteAllComments(commentIds); + commentRepository.softDeleteCommentsByTilId(tilId); // 2. Til을 삭제한다. tilRepository.deleteById(tilId); From 0a43264d1e32577613d4f43317091977af8d2296 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 20:14:04 +0900 Subject: [PATCH 25/66] =?UTF-8?q?feat:=20User=20soft/delete=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tily/roadmap/RoadmapRepository.java | 5 ++ .../example/tily/roadmap/RoadmapService.java | 12 +-- .../relation/UserRoadmapRepository.java | 7 ++ .../com/example/tily/step/StepRepository.java | 3 + .../com/example/tily/step/StepService.java | 4 - .../step/relation/UserStepRepository.java | 7 ++ .../com/example/tily/til/TilRepository.java | 2 + .../com/example/tily/user/UserController.java | 8 +- .../com/example/tily/user/UserService.java | 88 +++++++++++++++++++ 9 files changed, 125 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/example/tily/roadmap/RoadmapRepository.java b/src/main/java/com/example/tily/roadmap/RoadmapRepository.java index 79bb2b38..297a0f52 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapRepository.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapRepository.java @@ -4,6 +4,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -23,4 +24,8 @@ public interface RoadmapRepository extends JpaRepository { Slice findAllByOrderByCreatedDateDesc(@Param("category") Category category, @Param("name") String name, Pageable pageable); Optional findByCode(String code); + + @Modifying + @Query("update Roadmap r SET r.isDeleted = true WHERE r.isDeleted = false AND r.id IN :roadmapIds") + void softDeleteRoadmapByRoadmapIds(List roadmapIds); } diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index eca78952..a46f5601 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -549,23 +549,23 @@ public void deleteRoadmap(Long roadmapId, User user){ checkMasterAndManagerPermission(roadmapId, user); + // 1. Til과 연관된 Comment들을 삭제한다. List tils = getTilsByRoadmapId(roadmapId); List tilIds = tils.stream() .map(Til::getId) .collect(Collectors.toList()); - List steps = getStepsByRoadmapId(roadmapId); - List stepIds = steps.stream() - .map(Step::getId) - .collect(Collectors.toList()); - - // 1. Til과 연관된 Comment들을 삭제한다. commentRepository.softDeleteCommentsByTilIds(tilIds); // 2. Til을 삭제한다. tilRepository.softDeleteTilsByTilIds(tilIds); // 3. Reference들을 삭제한다 + List steps = getStepsByRoadmapId(roadmapId); + List stepIds = steps.stream() + .map(Step::getId) + .collect(Collectors.toList()); + referenceRepository.softDeleteReferenceByStepIds(stepIds); // 4. Step들을 삭제한다. diff --git a/src/main/java/com/example/tily/roadmap/relation/UserRoadmapRepository.java b/src/main/java/com/example/tily/roadmap/relation/UserRoadmapRepository.java index 6a361d5b..dbd06e40 100644 --- a/src/main/java/com/example/tily/roadmap/relation/UserRoadmapRepository.java +++ b/src/main/java/com/example/tily/roadmap/relation/UserRoadmapRepository.java @@ -1,5 +1,6 @@ package com.example.tily.roadmap.relation; +import com.example.tily.roadmap.Category; import com.example.tily.roadmap.Roadmap; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; @@ -31,4 +32,10 @@ public interface UserRoadmapRepository extends JpaRepository @Modifying @Query("update UserRoadmap ur SET ur.isDeleted = true WHERE ur.isDeleted = false AND ur.roadmap.id IN :roadmapId") void softDeleteUserRoadmapByRoadmapId(Long roadmapId); + + @Modifying + @Query("update UserRoadmap ur SET ur.isDeleted = true WHERE ur.isDeleted = false AND ur.id IN :userRoadmapIds") + void softDeleteUserRoadmapByUserRoadmapIds(List userRoadmapIds); + + List findByUserId(Long userId); } diff --git a/src/main/java/com/example/tily/step/StepRepository.java b/src/main/java/com/example/tily/step/StepRepository.java index 8ef75b54..06dc7d3a 100644 --- a/src/main/java/com/example/tily/step/StepRepository.java +++ b/src/main/java/com/example/tily/step/StepRepository.java @@ -20,6 +20,9 @@ public interface StepRepository extends JpaRepository { @Query("select s from Step s join fetch s.roadmap where s.roadmap.id=:roadmapId") List findByRoadmapId(@Param("roadmapId") Long roadmapId); + @Query("SELECT s FROM Step s WHERE s.roadmap.id IN :roadmapIds") + List findStepsByRoadmapIds(@Param("roadmapIds") List roadmapIds); + @Modifying @Query("update Step s SET s.isDeleted = true WHERE s.isDeleted = false AND s.id IN :stepIds") void softDeleteStepByStepIds(List stepIds); diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index 7a7a9fce..3de79be9 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -158,8 +158,4 @@ private Reference getReferenceById(Long referenceId){ private UserRoadmap getUserBelongRoadmap(Long roadmapId, Long userId) { return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, userId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_BELONG)); } - - private UserStep getUserStep(Long userId, Long stepId){ - return userStepRepository.findByUserIdAndStepId(userId, stepId).orElseThrow(() -> new CustomException(ExceptionCode.STEP_NOT_INCLUDE)); - } } diff --git a/src/main/java/com/example/tily/step/relation/UserStepRepository.java b/src/main/java/com/example/tily/step/relation/UserStepRepository.java index 59239923..6bf97262 100644 --- a/src/main/java/com/example/tily/step/relation/UserStepRepository.java +++ b/src/main/java/com/example/tily/step/relation/UserStepRepository.java @@ -1,5 +1,6 @@ package com.example.tily.step.relation; +import com.example.tily.roadmap.relation.UserRoadmap; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -31,4 +32,10 @@ List findAllByStepIdAndIsSubmitAndName(@Param("stepId") Long stepId, @Modifying @Query("update UserStep us SET us.isDeleted = true WHERE us.isDeleted = false AND us.step.id = :stepId") void softDeleteUserStepByStepId(Long stepId); // 하나의 step에 대한 UserStep 삭제 + + @Modifying + @Query("update UserStep us SET us.isDeleted = true WHERE us.isDeleted = false AND us.id IN :userStepIds") + void softDeleteUserStepByUserStepIds(List userStepIds); + + List findByUserId(Long userId); } diff --git a/src/main/java/com/example/tily/til/TilRepository.java b/src/main/java/com/example/tily/til/TilRepository.java index de53c0ab..e2b1822f 100644 --- a/src/main/java/com/example/tily/til/TilRepository.java +++ b/src/main/java/com/example/tily/til/TilRepository.java @@ -41,6 +41,8 @@ Slice findAllByDateByOrderByCreatedDateDesc(@Param("userId") Long userId, List findByStepId(Long stepId); + List findByUserId(Long userId); + @Query("select t from Til t where t.writer.id=:userId and t.step.id=:stepId") Til findByStepIdAndUserId(@Param("stepId") Long stepId, @Param("userId") Long userId); diff --git a/src/main/java/com/example/tily/user/UserController.java b/src/main/java/com/example/tily/user/UserController.java index b892ad80..81c6370b 100644 --- a/src/main/java/com/example/tily/user/UserController.java +++ b/src/main/java/com/example/tily/user/UserController.java @@ -99,6 +99,13 @@ public ResponseEntity gardens(@AuthenticationPrincipal CustomUserDetails user return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } + // 회원 탈퇴하기 + @DeleteMapping("/users") + public ResponseEntity withdrawMembership(@AuthenticationPrincipal CustomUserDetails userDetails){ + userService.withdrawMembership(userDetails.getUser()); + return ResponseEntity.ok().body(ApiUtils.success(null)); + } + public ResponseCookie setRefreshTokenCookie(String refreshToken) { return ResponseCookie.from("refreshToken", refreshToken) .httpOnly(true) @@ -107,5 +114,4 @@ public ResponseCookie setRefreshTokenCookie(String refreshToken) { .maxAge(JWTProvider.REFRESH_EXP) .build(); } - } diff --git a/src/main/java/com/example/tily/user/UserService.java b/src/main/java/com/example/tily/user/UserService.java index ffc9bb84..1b0d4f69 100644 --- a/src/main/java/com/example/tily/user/UserService.java +++ b/src/main/java/com/example/tily/user/UserService.java @@ -5,6 +5,17 @@ import com.auth0.jwt.interfaces.DecodedJWT; import com.example.tily._core.security.JWTProvider; import com.example.tily._core.utils.RedisUtils; +import com.example.tily.comment.CommentRepository; +import com.example.tily.roadmap.Category; +import com.example.tily.roadmap.Roadmap; +import com.example.tily.roadmap.RoadmapRepository; +import com.example.tily.roadmap.relation.UserRoadmap; +import com.example.tily.roadmap.relation.UserRoadmapRepository; +import com.example.tily.step.Step; +import com.example.tily.step.StepRepository; +import com.example.tily.step.reference.ReferenceRepository; +import com.example.tily.step.relation.UserStep; +import com.example.tily.step.relation.UserStepRepository; import com.example.tily.til.Til; import com.example.tily.til.TilRepository; import lombok.RequiredArgsConstructor; @@ -30,6 +41,13 @@ public class UserService { private final JavaMailSender javaMailSender; private final RedisUtils redisUtils; private final TilRepository tilRepository; + private final UserRoadmapRepository userRoadmapRepository; + private final UserStepRepository userStepRepository; + private final RoadmapRepository roadmapRepository; + private final CommentRepository commentRepository; + private final StepRepository stepRepository; + private final ReferenceRepository referenceRepository; + private String defaultImage = "user/profile-user.jpg"; // (회원가입) 이메일 중복 체크 후 인증코드 전송 @@ -162,6 +180,65 @@ public UserResponse.ViewGardensDTO viewGardens(User user) { return new UserResponse.ViewGardensDTO(gardens); } + // 회원 탈퇴하기 + public void withdrawMembership(User user){ + // 1. 유저가 작성한 Comment들 삭제 + List tils = getTilByUserId(user.getId()); + List tilIds = tils.stream() + .map(Til::getId) + .collect(Collectors.toList()); + + commentRepository.softDeleteCommentsByTilIds(tilIds); + + // 2. 유저가 작성한 Til 삭제 + tilRepository.softDeleteTilsByTilIds(tilIds); + + // 3. UserStep들을 삭제 + List userSteps = getUserStepByUserId(user.getId()); + List userStepIds = userSteps.stream() + .map(UserStep::getId) + .collect(Collectors.toList()); + + userStepRepository.softDeleteUserStepByUserStepIds(userStepIds); + + // 4. 유저가 만든 Step들을 삭제 + List steps = userSteps.stream() + .map(userStep -> userStep.getStep()) + .collect(Collectors.toList()); + + List stepIds = steps.stream() + .map(Step::getId) + .collect(Collectors.toList()); + + stepRepository.softDeleteStepByStepIds(stepIds); + + // 5. 유저가 작성한 Reference들을 삭제 + referenceRepository.softDeleteReferenceByStepIds(stepIds); + + // 6. UserRoadmap 삭제 + List userRoadmaps = getUserRoadmapByUserId(user.getId()); + List userRoadmapIds = userRoadmaps.stream() + .map(UserRoadmap::getId) + .collect(Collectors.toList()); + + userRoadmapRepository.softDeleteUserRoadmapByUserRoadmapIds(userRoadmapIds); + + // 7. 유저가 만든 로드맵 삭제 + List roadmaps = userRoadmaps.stream() + .map(userRoadmap -> userRoadmap.getRoadmap()) + .filter(roadmap -> roadmap.getCreator().getId().equals(user.getId())) + .collect(Collectors.toList()); + + List roadmapIds = roadmaps.stream() + .map(Roadmap::getId) + .collect(Collectors.toList()); + + roadmapRepository.softDeleteRoadmapByRoadmapIds(roadmapIds); + + // 8. 유저 삭제 + userRepository.delete(user); + } + ////////////// // 해당 이메일로 인증코드 전송 @@ -236,4 +313,15 @@ private User findById(Long id) { return userRepository.findById(id).orElseThrow(()->new CustomException(ExceptionCode.USER_NOT_FOUND)); } + private List getUserRoadmapByUserId(Long userId) { + return userRoadmapRepository.findByUserId(userId); + } + + private List getUserStepByUserId(Long userId) { + return userStepRepository.findByUserId(userId); + } + + private List getTilByUserId(Long userId){ + return tilRepository.findByUserId(userId); + } } From 81a1a41ef9433e7e90c5de092fbd28b5226188aa Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 20:20:31 +0900 Subject: [PATCH 26/66] =?UTF-8?q?fix:=20=ED=95=84=EC=9A=94=EC=97=86?= =?UTF-8?q?=EB=8A=94=20soft=20delete=20=ED=95=A8=EC=88=98=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/comment/CommentController.java | 1 + src/main/java/com/example/tily/comment/CommentService.java | 2 +- src/main/java/com/example/tily/step/StepRepository.java | 3 --- src/main/java/com/example/tily/til/TilController.java | 1 + 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/tily/comment/CommentController.java b/src/main/java/com/example/tily/comment/CommentController.java index 8977c47f..011eadef 100644 --- a/src/main/java/com/example/tily/comment/CommentController.java +++ b/src/main/java/com/example/tily/comment/CommentController.java @@ -35,6 +35,7 @@ public ResponseEntity updateComment(@PathVariable("roadmapId") Long roadmapId return ResponseEntity.ok().body(ApiUtils.success(null)); } + // API 주소 수정 필요 @DeleteMapping("/roadmaps/{roadmapId}/steps/{stepId}/tils/{tilId}/comments/{commentId}") public ResponseEntity deleteComment(@PathVariable("roadmapId") Long roadmapId, @PathVariable("stepId")Long stepId, @PathVariable("tilId") Long tilId, @PathVariable("commentId") Long commentId, diff --git a/src/main/java/com/example/tily/comment/CommentService.java b/src/main/java/com/example/tily/comment/CommentService.java index bf1f9648..ffe4dcf0 100644 --- a/src/main/java/com/example/tily/comment/CommentService.java +++ b/src/main/java/com/example/tily/comment/CommentService.java @@ -75,6 +75,6 @@ public void deleteComment(Long id, User user) { } alarmRepository.deleteByCommentId(id); - commentRepository.deleteById(id); + commentRepository.deleteById(id); // soft delete 적용됨 } } diff --git a/src/main/java/com/example/tily/step/StepRepository.java b/src/main/java/com/example/tily/step/StepRepository.java index 06dc7d3a..8ef75b54 100644 --- a/src/main/java/com/example/tily/step/StepRepository.java +++ b/src/main/java/com/example/tily/step/StepRepository.java @@ -20,9 +20,6 @@ public interface StepRepository extends JpaRepository { @Query("select s from Step s join fetch s.roadmap where s.roadmap.id=:roadmapId") List findByRoadmapId(@Param("roadmapId") Long roadmapId); - @Query("SELECT s FROM Step s WHERE s.roadmap.id IN :roadmapIds") - List findStepsByRoadmapIds(@Param("roadmapIds") List roadmapIds); - @Modifying @Query("update Step s SET s.isDeleted = true WHERE s.isDeleted = false AND s.id IN :stepIds") void softDeleteStepByStepIds(List stepIds); diff --git a/src/main/java/com/example/tily/til/TilController.java b/src/main/java/com/example/tily/til/TilController.java index 849ba3f4..01b7b5df 100644 --- a/src/main/java/com/example/tily/til/TilController.java +++ b/src/main/java/com/example/tily/til/TilController.java @@ -58,6 +58,7 @@ public ResponseEntity submitTil(@PathVariable("roadmapId") Long roadmapId, return ResponseEntity.ok().body(ApiUtils.success(null)); } + // API 주소 수정 필요 @DeleteMapping("/roadmaps/{roadmapId}/steps/{stepId}/tils/{tilId}") public ResponseEntity deleteTil(@PathVariable("roadmapId") Long roadmapId, @PathVariable("stepId")Long stepId, From 0a14631bebf14ad2ce6058428b5cdeb66059dfd7 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Tue, 7 Nov 2023 21:00:42 +0900 Subject: [PATCH 27/66] =?UTF-8?q?fix:=20softDeleteUserRoadmapByRoadmapId?= =?UTF-8?q?=20=EC=BF=BC=EB=A6=AC=EB=AC=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/tily/roadmap/relation/UserRoadmapRepository.java | 2 +- src/main/java/com/example/tily/til/TilService.java | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/main/java/com/example/tily/roadmap/relation/UserRoadmapRepository.java b/src/main/java/com/example/tily/roadmap/relation/UserRoadmapRepository.java index dbd06e40..8644d193 100644 --- a/src/main/java/com/example/tily/roadmap/relation/UserRoadmapRepository.java +++ b/src/main/java/com/example/tily/roadmap/relation/UserRoadmapRepository.java @@ -30,7 +30,7 @@ public interface UserRoadmapRepository extends JpaRepository List findByRoadmapIdAndIsAcceptTrueAndName(@Param("roadmapId") Long roadmapId, @Param("name") String name); @Modifying - @Query("update UserRoadmap ur SET ur.isDeleted = true WHERE ur.isDeleted = false AND ur.roadmap.id IN :roadmapId") + @Query("update UserRoadmap ur SET ur.isDeleted = true WHERE ur.isDeleted = false AND ur.roadmap.id = :roadmapId") void softDeleteUserRoadmapByRoadmapId(Long roadmapId); @Modifying diff --git a/src/main/java/com/example/tily/til/TilService.java b/src/main/java/com/example/tily/til/TilService.java index 30f80845..0ae68ab3 100644 --- a/src/main/java/com/example/tily/til/TilService.java +++ b/src/main/java/com/example/tily/til/TilService.java @@ -191,10 +191,6 @@ private boolean checkTilWriterEqualUser(Til til, User user) { return !til.getWriter().getId().equals(user.getId()); } - private List getCommentByStepId(Long tilId) { - return commentRepository.findByTilId(tilId); - } - // 사용자가 로드맵에 속했는지 private UserRoadmap getUserIncludeRoadmap(Long roadmapId, Long userId) { return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, userId) From 77266385495eb80751f70601b61c00497922b136 Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 01:33:51 +0900 Subject: [PATCH 28/66] =?UTF-8?q?fix=20:=20api=20=EC=95=9E=EC=97=90=20/api?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/alarm/AlarmController.java | 1 + src/main/java/com/example/tily/comment/CommentController.java | 1 + src/main/java/com/example/tily/image/ImageController.java | 1 + src/main/java/com/example/tily/roadmap/RoadmapController.java | 1 + src/main/java/com/example/tily/step/StepController.java | 1 + src/main/java/com/example/tily/til/TilController.java | 1 + src/main/java/com/example/tily/user/UserController.java | 1 + 7 files changed, 7 insertions(+) diff --git a/src/main/java/com/example/tily/alarm/AlarmController.java b/src/main/java/com/example/tily/alarm/AlarmController.java index 696792cd..317a27f1 100644 --- a/src/main/java/com/example/tily/alarm/AlarmController.java +++ b/src/main/java/com/example/tily/alarm/AlarmController.java @@ -11,6 +11,7 @@ @RestController @RequiredArgsConstructor +@RequestMapping("/api") public class AlarmController { private final AlarmService alarmService; diff --git a/src/main/java/com/example/tily/comment/CommentController.java b/src/main/java/com/example/tily/comment/CommentController.java index 8977c47f..922d23f9 100644 --- a/src/main/java/com/example/tily/comment/CommentController.java +++ b/src/main/java/com/example/tily/comment/CommentController.java @@ -11,6 +11,7 @@ @RestController @RequiredArgsConstructor +@RequestMapping("/api") public class CommentController { private final CommentService commentService; diff --git a/src/main/java/com/example/tily/image/ImageController.java b/src/main/java/com/example/tily/image/ImageController.java index f3f3cc97..8bc8ab9d 100644 --- a/src/main/java/com/example/tily/image/ImageController.java +++ b/src/main/java/com/example/tily/image/ImageController.java @@ -10,6 +10,7 @@ @RestController @RequiredArgsConstructor +@RequestMapping("/api") public class ImageController { final private ImageService imageService; diff --git a/src/main/java/com/example/tily/roadmap/RoadmapController.java b/src/main/java/com/example/tily/roadmap/RoadmapController.java index f7430729..1d261223 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapController.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapController.java @@ -12,6 +12,7 @@ @RestController @RequiredArgsConstructor +@RequestMapping("/api") public class RoadmapController { private final RoadmapService roadmapService; diff --git a/src/main/java/com/example/tily/step/StepController.java b/src/main/java/com/example/tily/step/StepController.java index 4799e87e..71000274 100644 --- a/src/main/java/com/example/tily/step/StepController.java +++ b/src/main/java/com/example/tily/step/StepController.java @@ -12,6 +12,7 @@ @RestController @RequiredArgsConstructor +@RequestMapping("/api") public class StepController { private final StepService stepService; diff --git a/src/main/java/com/example/tily/til/TilController.java b/src/main/java/com/example/tily/til/TilController.java index 849ba3f4..5d1ec873 100644 --- a/src/main/java/com/example/tily/til/TilController.java +++ b/src/main/java/com/example/tily/til/TilController.java @@ -12,6 +12,7 @@ @RestController @RequiredArgsConstructor +@RequestMapping("/api") public class TilController { private final TilService tilService; diff --git a/src/main/java/com/example/tily/user/UserController.java b/src/main/java/com/example/tily/user/UserController.java index b892ad80..b9a4d65c 100644 --- a/src/main/java/com/example/tily/user/UserController.java +++ b/src/main/java/com/example/tily/user/UserController.java @@ -16,6 +16,7 @@ @RequiredArgsConstructor @RestController +@RequestMapping("/api") public class UserController { private final UserService userService; From 7cb3817fea37b4f082892715a2c65a29be802355 Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 03:45:02 +0900 Subject: [PATCH 29/66] =?UTF-8?q?feat=20:=20=EC=9D=91=EB=8B=B5=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EC=83=9D=EC=84=B1=EC=9E=90=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/tily/_core/utils/ApiUtils.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/tily/_core/utils/ApiUtils.java b/src/main/java/com/example/tily/_core/utils/ApiUtils.java index 86f6031c..0e2e47a2 100644 --- a/src/main/java/com/example/tily/_core/utils/ApiUtils.java +++ b/src/main/java/com/example/tily/_core/utils/ApiUtils.java @@ -12,6 +12,10 @@ public static ApiResult success(T result) { return new ApiResult<>(true, 200, "ok", result); } + public static ApiResult success(HttpStatus httpStatus, T result) { + return new ApiResult<>(true, httpStatus.value(), httpStatus.getReasonPhrase(), result); + } + public static ApiResult error(String message, HttpStatus httpStatus) { return new ApiResult<>(false, httpStatus.value(), message, null); } @@ -23,10 +27,4 @@ public static class ApiResult { private final String message; private final T result; } - -// @Getter @Setter @AllArgsConstructor -// public static class ApiError { -// private final String message; -// private final int status; -// } } From 5818ffbb379723f8076eff09ddec079bcb3bda42 Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 03:45:36 +0900 Subject: [PATCH 30/66] =?UTF-8?q?refactor=20:=20TilController=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/til/TilController.java | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/example/tily/til/TilController.java b/src/main/java/com/example/tily/til/TilController.java index 5d1ec873..f21c0ad9 100644 --- a/src/main/java/com/example/tily/til/TilController.java +++ b/src/main/java/com/example/tily/til/TilController.java @@ -3,6 +3,7 @@ import com.example.tily._core.security.CustomUserDetails; import com.example.tily._core.utils.ApiUtils; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.validation.Errors; @@ -17,59 +18,54 @@ public class TilController { private final TilService tilService; - @PostMapping("/roadmaps/{roadmapId}/steps/{stepId}/tils") - public ResponseEntity createTil(@PathVariable("roadmapId") Long roadmapId, - @PathVariable("stepId") Long stepId, - @RequestBody @Valid TilRequest.CreateTilDTO requestDTO, Errors errors, + // til 생성하기 + @PostMapping("/tils") + public ResponseEntity createTil(@RequestBody @Valid TilRequest.CreateTilDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) { - TilResponse.CreateTilDTO responseDTO = tilService.createTil(requestDTO, roadmapId, stepId, userDetails.getUser()); - return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); + TilResponse.CreateTilDTO responseDTO = tilService.createTil(requestDTO, userDetails.getUser()); + return ResponseEntity.ok().body(ApiUtils.success(HttpStatus.CREATED, responseDTO)); } - @PatchMapping("/roadmaps/{roadmapId}/steps/{stepId}/tils/{tilId}") - public ResponseEntity updateTil(@PathVariable("roadmapId") Long roadmapId, - @PathVariable("stepId") Long stepId, - @PathVariable("tilId") Long tilId, - @RequestBody @Valid TilRequest.UpdateTilDTO requestDTO, Errors errors, - @AuthenticationPrincipal CustomUserDetails userDetails) { + // til 조회하기 + @GetMapping("/tils/{id}") + public ResponseEntity viewTil(@PathVariable Long id, + @AuthenticationPrincipal CustomUserDetails userDetails) { - tilService.updateTil(requestDTO, tilId, userDetails.getUser()); - return ResponseEntity.ok().body(ApiUtils.success(null)); + TilResponse.ViewDTO responseDTO = tilService.viewTil(id, userDetails.getUser()); + return ResponseEntity.ok(ApiUtils.success(responseDTO)); } - @GetMapping("/roadmaps/{roadmapId}/steps/{stepId}/tils/{tilId}") - public ResponseEntity viewTil(@PathVariable("roadmapId") Long roadmapId, - @PathVariable("stepId")Long stepId, - @PathVariable("tilId") Long tilId, - @AuthenticationPrincipal CustomUserDetails userDetails) { + // til 수정하기 (저장하기) + @PatchMapping("/tils/{id}") + public ResponseEntity updateTil(@PathVariable Long id, + @RequestBody @Valid TilRequest.UpdateTilDTO requestDTO, Errors errors, + @AuthenticationPrincipal CustomUserDetails userDetails) { - TilResponse.ViewDTO responseDTO = tilService.viewTil(roadmapId, stepId, tilId, userDetails.getUser()); - return ResponseEntity.ok(ApiUtils.success(responseDTO)); + tilService.updateTil(requestDTO, id, userDetails.getUser()); + return ResponseEntity.ok().body(ApiUtils.success(null)); } - @PostMapping("/roadmaps/{roadmapId}/steps/{stepId}/tils/{tilId}") - public ResponseEntity submitTil(@PathVariable("roadmapId") Long roadmapId, - @PathVariable("stepId")Long stepId, - @PathVariable("tilId") Long tilId, + // til 제출하기 + @PostMapping("/tils/{id}") + public ResponseEntity submitTil(@PathVariable Long id, @RequestBody @Valid TilRequest.SubmitTilDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails) { - tilService.submitTil(requestDTO, roadmapId, stepId, tilId, userDetails.getUser()); + tilService.submitTil(requestDTO, id, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(null)); } - @DeleteMapping("/roadmaps/{roadmapId}/steps/{stepId}/tils/{tilId}") - public ResponseEntity deleteTil(@PathVariable("roadmapId") Long roadmapId, - @PathVariable("stepId")Long stepId, - @PathVariable("tilId") Long tilId, + // til 삭제하기 + @DeleteMapping("/tils/{id}") + public ResponseEntity deleteTil(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails) { - tilService.deleteTil(tilId, userDetails.getUser()); + tilService.deleteTil(id, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(null)); } - // 나의 틸 목록 전체 조회하기 + // 나의 til 목록 전체 조회하기 @GetMapping("/tils/my") public ResponseEntity findAllMyTil(@RequestParam(value = "roadmapId", required = false) Long roadmapId, @RequestParam(value = "date", required = false) String date, From 69d6022200ea3eeb30b9ad1500ea8bc4544475fe Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 03:50:35 +0900 Subject: [PATCH 31/66] =?UTF-8?q?refactor=20:=20TilService=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/tily/til/TilService.java | 96 +++++++++---------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/example/tily/til/TilService.java b/src/main/java/com/example/tily/til/TilService.java index 0b5f7745..5bf4a772 100644 --- a/src/main/java/com/example/tily/til/TilService.java +++ b/src/main/java/com/example/tily/til/TilService.java @@ -45,16 +45,22 @@ public class TilService { // til 생성하기 @Transactional - public TilResponse.CreateTilDTO createTil(TilRequest.CreateTilDTO requestDTO, Long roadmapId, Long stepId, User user) { + public TilResponse.CreateTilDTO createTil(TilRequest.CreateTilDTO requestDTO, User user) { - Roadmap roadmap = getRoadmapById(roadmapId); + Long roadmapId = requestDTO.roadmapId(); + Long stepId = requestDTO.stepId(); - Step step = getStepById(stepId); + Roadmap roadmap = roadmapRepository.findById(roadmapId) + .orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); + Step step = stepRepository.findById(stepId) + .orElseThrow(() -> new CustomException(ExceptionCode.STEP_NOT_FOUND)); + + // step이 roadmap에 속했는지 확인 if (!step.getRoadmap().equals(roadmap)) throw new CustomException(ExceptionCode.STEP_NOT_INCLUDE); - getUserIncludeRoadmap(roadmapId, user.getId()); + getUserBelongRoadmap(roadmapId, user.getId()); // 사용자가 이미 step에 대한 til을 생성한 경우 Til til = tilRepository.findByStepIdAndUserId(stepId, user.getId()); @@ -74,28 +80,16 @@ public TilResponse.CreateTilDTO createTil(TilRequest.CreateTilDTO requestDTO, Lo return new TilResponse.CreateTilDTO(newTil); } - // til 저장하기 - @Transactional - public void updateTil(TilRequest.UpdateTilDTO requestDTO, Long id, User user) { - - Til til = getTilById(id); - - if (checkTilWriterEqualUser(til, user)) - throw new CustomException(ExceptionCode.TIL_UPDATE_FORBIDDEN); - - til.updateContent(requestDTO.content()); - } - - public TilResponse.ViewDTO viewTil (Long roadmapId, Long stepId, Long tilId, User user) { + // til 조회하기 + public TilResponse.ViewDTO viewTil (Long tilId, User user) { Til til = getTilById(tilId); - Step step = getStepById(stepId); - - Roadmap roadmap = getRoadmapById(roadmapId); + Step step = til.getStep(); + //Roadmap roadmap = til.getRoadmap(); - // roadmap 에 속한 사람만 볼 수 있음 (roadmap에 속하면 userstep에 넣어짐) -> getUserIncludeRoadmap 대신 사용 가능 - UserStep userStep = userStepRepository.findByUserIdAndStepId(user.getId(), stepId) + // roadmap 에 속한 사람만 볼 수 있음 (roadmap에 속하면 userstep에 넣어짐) -> getUserBelongRoadmap 대신 사용 가능 + UserStep userStep = userStepRepository.findByUserIdAndStepId(user.getId(), step.getId()) .orElseThrow(() -> new CustomException(ExceptionCode.TIL_VIEW_FORBIDDEN)); Map maps = new HashMap<>(); @@ -103,34 +97,46 @@ public TilResponse.ViewDTO viewTil (Long roadmapId, Long stepId, Long tilId, Use for (Comment comment : comments) { maps.put(comment, user.getId().equals(comment.getWriter().getId())); } + //commentRepository.findByTilId(tilId).stream().map(c -> maps.put(c, user.getId().equals(c.getWriter().getId()))); - List commentDTOs = comments.stream().map(c -> new TilResponse.ViewDTO.CommentDTO(c, maps.get(c))).collect(Collectors.toList()); + List commentDTOs = comments.stream() + .map(c -> new TilResponse.ViewDTO.CommentDTO(c, maps.get(c))).collect(Collectors.toList()); return new TilResponse.ViewDTO(step, til, userStep.getIsSubmit(), commentDTOs); } - + // til 수정하기 (저장하기) @Transactional - public void submitTil(TilRequest.SubmitTilDTO requestDTO, Long roadmapId, Long stepId, Long tilId, User user) { + public void updateTil(TilRequest.UpdateTilDTO requestDTO, Long tilId, User user) { Til til = getTilById(tilId); - Step step = getStepById(stepId); + checkTilWriterEqualUser(til, user); - Roadmap roadmap = getRoadmapById(roadmapId); + til.updateContent(requestDTO.content()); + } - if (checkTilWriterEqualUser(til, user)) - throw new CustomException(ExceptionCode.TIL_SUBMIT_FORBIDDEN); + // til 제출하기 + @Transactional + public void submitTil(TilRequest.SubmitTilDTO requestDTO, Long tilId, User user) { + + Til til = getTilById(tilId); - // 사용자가 그룹에 속했는지 확인 - UserRoadmap userRoadmap = getUserIncludeRoadmap(roadmapId, user.getId()); + Step step = til.getStep(); + Roadmap roadmap = til.getRoadmap(); - // UserStep 조회 -> 사용자가 로드맵에 속했는지, 제출했는지 확인 - UserStep userstep = userStepRepository.findByUserIdAndStepId(user.getId(), stepId) + checkTilWriterEqualUser(til, user); + + // 사용자가 로드맵에 속했는지 확인 + UserRoadmap userRoadmap = getUserBelongRoadmap(roadmap.getId(), user.getId()); + + UserStep userstep = userStepRepository.findByUserIdAndStepId(user.getId(), step.getId()) .orElseThrow(()-> new CustomException(ExceptionCode.TIL_SUBMIT_FORBIDDEN)); + + // 이미 제출한 경우 if (userstep.getIsSubmit().equals(true)) throw new CustomException(ExceptionCode.TIL_ALREADY_SUBMIT); - // 제출 시간 지났는데 제출하려고할때 + // 제출 시간 지났는데 제출하는 경우 LocalDateTime now = LocalDateTime.now(); if (step.getDueDate()!=null && now.isAfter(step.getDueDate())) throw new CustomException(ExceptionCode.TIL_END_DUEDATE); @@ -138,19 +144,20 @@ public void submitTil(TilRequest.SubmitTilDTO requestDTO, Long roadmapId, Long s til.submitTil(requestDTO.submitContent()); // 내용, 제출 내용 저장 userstep.submit(); // 제출 여부(완료) 저장 - userRoadmap.updateProgress(calProgress(roadmapId, user.getId())); // 진도율 저장 + userRoadmap.updateProgress(calProgress(roadmap.getId(), user.getId())); // 진도율 저장 } @Transactional public void deleteTil(Long tilId, User user) { + Til til = getTilById(tilId); - if (checkTilWriterEqualUser(til, user)) - throw new CustomException(ExceptionCode.TIL_DELETE_FORBIDDEN); + checkTilWriterEqualUser(til, user); tilRepository.deleteById(tilId); } + // 나의 til 목록 전체 조회하기 public TilResponse.FindAllDTO findAllMyTil(Long roadmapId, String date, String title, int page, int size, User user) { Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "createdDate")); @@ -171,24 +178,17 @@ public TilResponse.FindAllDTO findAllMyTil(Long roadmapId, String date, String t return new TilResponse.FindAllDTO(tilDTOs, tils.hasNext()); } - private Roadmap getRoadmapById(Long roadmapId) { - return roadmapRepository.findById(roadmapId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); - } - - private Step getStepById(Long stepId) { - return stepRepository.findById(stepId).orElseThrow(() -> new CustomException(ExceptionCode.STEP_NOT_FOUND)); - } - private Til getTilById(Long tilId) { return tilRepository.findById(tilId).orElseThrow(() -> new CustomException(ExceptionCode.TIL_NOT_FOUND)); } - private boolean checkTilWriterEqualUser(Til til, User user) { - return !til.getWriter().getId().equals(user.getId()); + private void checkTilWriterEqualUser(Til til, User user) { + if (!til.getWriter().getId().equals(user.getId())) + throw new CustomException(ExceptionCode.TIL_FORBIDDEN); } // 사용자가 로드맵에 속했는지 - private UserRoadmap getUserIncludeRoadmap(Long roadmapId, Long userId) { + private UserRoadmap getUserBelongRoadmap(Long roadmapId, Long userId) { return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, userId) .orElseThrow(() -> new CustomException(ExceptionCode.TIL_ROADMAP_FORBIDDEN)); } From ff1e954fd9534186bbb78004a825998ab7867193 Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 03:51:10 +0900 Subject: [PATCH 32/66] =?UTF-8?q?refactor=20:=20Til=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_core/errors/exception/ExceptionCode.java | 3 ++- .../com/example/tily/til/TilRepository.java | 25 ++++++++----------- .../java/com/example/tily/til/TilRequest.java | 17 ++++++++----- .../java/com/example/tily/til/TilService.java | 4 +-- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java b/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java index c1771d33..a7d0e19e 100644 --- a/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java +++ b/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java @@ -33,10 +33,11 @@ public enum ExceptionCode { TIL_ALREADY_SUBMIT(HttpStatus.BAD_REQUEST, "이미 til을 제출하였습니다."), TIL_DELETE_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 til을 삭제할 권한이 없습니다."), TIL_END_DUEDATE(HttpStatus.BAD_REQUEST, "제출 시간이 지나 til을 제출할 수 없습니다."), + TIL_FORBIDDEN(HttpStatus.FORBIDDEN, "til에 대한 권한이 없습니다."), // roadmap 관련 에러 ROADMAP_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 roadmap을 찾을 수 없습니다."), - ROADMAP_NOT_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 로드냅에 속하지 않았습니다."), + ROADMAP_NOT_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 로드맵에 속하지 않았습니다."), ROADMAP_NOT_BELONG(HttpStatus.NOT_FOUND, "해당 reoadmap에 속하지 않습니다."), ROADMAP_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 roadmap을 조회할 권한이 없습니다."), ROADMAP_SUBMIT_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 til을 제출할 권한이 없습니다."), diff --git a/src/main/java/com/example/tily/til/TilRepository.java b/src/main/java/com/example/tily/til/TilRepository.java index 08185eb7..25ba0591 100644 --- a/src/main/java/com/example/tily/til/TilRepository.java +++ b/src/main/java/com/example/tily/til/TilRepository.java @@ -14,22 +14,22 @@ public interface TilRepository extends JpaRepository{ - Til findFirstByOrderByUpdatedDateDesc(); - @Query("select t from Til t where t.writer.id=:userId and t.roadmap.id=:roadmapId order by t.updatedDate desc") List findByUserIdByOrderByUpdatedDateDesc(@Param("roadmapId") Long roadmapId, @Param("userId") Long userId); + @Query("select t from Til t join fetch t.writer where t.id=:id") Optional findById(Long id); - @Query("select t from Til t where t.writer.id=:userId " + - "and (:roadmapId is null or t.roadmap.id=:roadmapId)" + - "and (:title is null or t.title like %:title%)") + @Query("select t from Til t " + + "where t.writer.id=:userId " + + "and (:roadmapId is null or t.roadmap.id=:roadmapId) " + + "and (:title is null or t.title like %:title%)") Slice findAllByOrderByCreatedDateDesc(@Param("userId") Long userId, @Param("roadmapId") Long roadmapId, @Param("title") String title, Pageable pageable); - - @Query("select t from Til t where t.writer.id=:userId " + + @Query("select t from Til t " + + "where t.writer.id=:userId " + "and (:roadmapId is null or t.roadmap.id=:roadmapId)" + "and (:startDate <= t.createdDate and t.createdDate<= :endDate)" + "and (:title is null or t.title like %:title%)") @@ -40,18 +40,13 @@ Slice findAllByDateByOrderByCreatedDateDesc(@Param("userId") Long userId, @Param("title") String title, Pageable pageable); - List findByStepId(Long stepId); - @Query("select t from Til t where t.writer.id=:userId and t.step.id=:stepId") Til findByStepIdAndUserId(@Param("stepId") Long stepId, @Param("userId") Long userId); - @Query("select t from Til t where t.roadmap.id=:roadmapId") - List findByRoadmapId(@Param("roadmapId") Long roadmapId); - - @Query("SELECT t FROM Til t where t.writer.id=:userId " + + @Query("SELECT t FROM Til t " + + "where t.writer.id=:userId " + "and (:startDate <= t.createdDate and t.createdDate<= :endDate)") List findTilsByUserIdAndDateRange(@Param("userId") Long userId, @Param("startDate") LocalDateTime startDate, - @Param("endDate") LocalDateTime endDate); - + @Param("endDate") LocalDateTime endDate); } diff --git a/src/main/java/com/example/tily/til/TilRequest.java b/src/main/java/com/example/tily/til/TilRequest.java index 247cb49e..ab8cf508 100644 --- a/src/main/java/com/example/tily/til/TilRequest.java +++ b/src/main/java/com/example/tily/til/TilRequest.java @@ -8,12 +8,17 @@ public class TilRequest { - public record CreateTilDTO(@NotBlank(message = "TIL 제목을 입력해주세요.") String title) { - } + public record CreateTilDTO( + Long roadmapId, + Long stepId, + @NotBlank(message = "TIL 제목을 입력해주세요.") String title + ) { } - public record UpdateTilDTO(@NotBlank(message = "TIL 내용을 입력해주세요.") String content) { - } + public record UpdateTilDTO( + @NotBlank(message = "TIL 내용을 입력해주세요.") String content + ) { } - public record SubmitTilDTO(@NotBlank(message = "TIL 내용을 입력해주세요.") String submitContent){ - } + public record SubmitTilDTO( + @NotBlank(message = "TIL 내용을 입력해주세요.") String submitContent + ){ } } diff --git a/src/main/java/com/example/tily/til/TilService.java b/src/main/java/com/example/tily/til/TilService.java index 5bf4a772..f49b0989 100644 --- a/src/main/java/com/example/tily/til/TilService.java +++ b/src/main/java/com/example/tily/til/TilService.java @@ -86,7 +86,6 @@ public TilResponse.ViewDTO viewTil (Long tilId, User user) { Til til = getTilById(tilId); Step step = til.getStep(); - //Roadmap roadmap = til.getRoadmap(); // roadmap 에 속한 사람만 볼 수 있음 (roadmap에 속하면 userstep에 넣어짐) -> getUserBelongRoadmap 대신 사용 가능 UserStep userStep = userStepRepository.findByUserIdAndStepId(user.getId(), step.getId()) @@ -132,7 +131,7 @@ public void submitTil(TilRequest.SubmitTilDTO requestDTO, Long tilId, User user) UserStep userstep = userStepRepository.findByUserIdAndStepId(user.getId(), step.getId()) .orElseThrow(()-> new CustomException(ExceptionCode.TIL_SUBMIT_FORBIDDEN)); - // 이미 제출한 경우 + // 이미 til을 제출한 경우 if (userstep.getIsSubmit().equals(true)) throw new CustomException(ExceptionCode.TIL_ALREADY_SUBMIT); @@ -141,7 +140,6 @@ public void submitTil(TilRequest.SubmitTilDTO requestDTO, Long tilId, User user) if (step.getDueDate()!=null && now.isAfter(step.getDueDate())) throw new CustomException(ExceptionCode.TIL_END_DUEDATE); - til.submitTil(requestDTO.submitContent()); // 내용, 제출 내용 저장 userstep.submit(); // 제출 여부(완료) 저장 userRoadmap.updateProgress(calProgress(roadmap.getId(), user.getId())); // 진도율 저장 From 9845516dc4d9901512b5dbed9d5b2050352a9dc7 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:17:34 +0900 Subject: [PATCH 33/66] =?UTF-8?q?fix:=20CommentRequest=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20DTO=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/comment/CommentRequest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/tily/comment/CommentRequest.java b/src/main/java/com/example/tily/comment/CommentRequest.java index a9fcd4e6..229dbd9c 100644 --- a/src/main/java/com/example/tily/comment/CommentRequest.java +++ b/src/main/java/com/example/tily/comment/CommentRequest.java @@ -4,7 +4,7 @@ public class CommentRequest { - public record CreateCommentDTO(@NotBlank(message = "댓글 내용을 입력해주세요.") String content) { + public record CreateCommentDTO(Long roadmapId, Long stepId, Long tilId, @NotBlank(message = "댓글 내용을 입력해주세요.") String content) { } public record UpdateCommentDTO(@NotBlank(message = "댓글 내용을 입력해주세요.") String content) { From 07e27dda9b98072054e048d857898159169790ce Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:22:58 +0900 Subject: [PATCH 34/66] =?UTF-8?q?fix:=20CommentController=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tily/comment/CommentController.java | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/example/tily/comment/CommentController.java b/src/main/java/com/example/tily/comment/CommentController.java index 011eadef..d4b0c84b 100644 --- a/src/main/java/com/example/tily/comment/CommentController.java +++ b/src/main/java/com/example/tily/comment/CommentController.java @@ -15,33 +15,26 @@ public class CommentController { private final CommentService commentService; - @PostMapping("/roadmaps/{roadmapId}/steps/{stepId}/tils/{tilId}/comments") - public ResponseEntity createComment(@PathVariable("roadmapId") Long roadmapId, @PathVariable("stepId") Long stepId, - @PathVariable("tilId") Long tilId , - @RequestBody @Valid CommentRequest.CreateCommentDTO requestDTO, + @PostMapping("/comments") + public ResponseEntity createComment(@RequestBody @Valid CommentRequest.CreateCommentDTO requestDTO, @AuthenticationPrincipal CustomUserDetails userDetails) { - CommentResponse.CreateCommentDTO responseDTO = commentService.createComment(requestDTO, - roadmapId, stepId, tilId, userDetails.getUser()); + CommentResponse.CreateCommentDTO responseDTO = commentService.createComment(requestDTO, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } - @PatchMapping("/roadmaps/{roadmapId}/steps/{stepId}/tils/{tilId}/comments/{commentId}") - public ResponseEntity updateComment(@PathVariable("roadmapId") Long roadmapId, @PathVariable("stepId") Long stepId, - @PathVariable("tilId") Long tilId, @PathVariable("commentId") Long commentId, - @RequestBody @Valid CommentRequest.UpdateCommentDTO requestDTO, - @AuthenticationPrincipal CustomUserDetails userDetails) { - commentService.updateComment(requestDTO, commentId, userDetails.getUser()); + @PatchMapping("/comments/{id}") + public ResponseEntity updateComment(@PathVariable("id") Long id, @RequestBody @Valid CommentRequest.UpdateCommentDTO requestDTO, + @AuthenticationPrincipal CustomUserDetails userDetails) { + commentService.updateComment(requestDTO, id, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(null)); } - // API 주소 수정 필요 - @DeleteMapping("/roadmaps/{roadmapId}/steps/{stepId}/tils/{tilId}/comments/{commentId}") - public ResponseEntity deleteComment(@PathVariable("roadmapId") Long roadmapId, @PathVariable("stepId")Long stepId, - @PathVariable("tilId") Long tilId, @PathVariable("commentId") Long commentId, + @DeleteMapping("/comments/{id}") + public ResponseEntity deleteComment(@PathVariable("id") Long id, @AuthenticationPrincipal CustomUserDetails userDetails) { - commentService.deleteComment(commentId, userDetails.getUser()); + commentService.deleteComment(id, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(null)); } } \ No newline at end of file From a82161482985ceb6499f9e159b6296d65a5b85ac Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:27:08 +0900 Subject: [PATCH 35/66] =?UTF-8?q?fix:=20CommentService=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/comment/CommentService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/tily/comment/CommentService.java b/src/main/java/com/example/tily/comment/CommentService.java index 29a605ee..2689df74 100644 --- a/src/main/java/com/example/tily/comment/CommentService.java +++ b/src/main/java/com/example/tily/comment/CommentService.java @@ -26,8 +26,10 @@ public class CommentService { private final AlarmRepository alarmRepository; @Transactional - public CommentResponse.CreateCommentDTO createComment(CommentRequest.CreateCommentDTO requestDTO, - Long roadmapId, Long stepId, Long tilId, User user) { + public CommentResponse.CreateCommentDTO createComment(CommentRequest.CreateCommentDTO requestDTO, User user) { + Long roadmapId = requestDTO.roadmapId(); + Long stepId = requestDTO.stepId(); + Long tilId = requestDTO.tilId(); Roadmap roadmap = roadmapRepository.findById(roadmapId) .orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); From b25c14eac35aaaf8dc21b6b0de67be011ec191e8 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:30:07 +0900 Subject: [PATCH 36/66] =?UTF-8?q?fix:=20ImageController=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/tily/image/ImageController.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/tily/image/ImageController.java b/src/main/java/com/example/tily/image/ImageController.java index f3f3cc97..9fd2bb62 100644 --- a/src/main/java/com/example/tily/image/ImageController.java +++ b/src/main/java/com/example/tily/image/ImageController.java @@ -14,14 +14,14 @@ public class ImageController { final private ImageService imageService; // 폴더 별로 관리 하기 위해 나눔(user, roadmap, post) - @GetMapping("/user/{userId}/image") + @GetMapping("/image/user/{userId}") public ResponseEntity findUserImage(@PathVariable Long userId){ ImageResponse.UserImageDTO responseDTO = imageService.findUserImage(userId); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } - @PostMapping("/user/{userId}/image") + @PostMapping("/image/user/{userId}") public ResponseEntity uploadUserImage(@PathVariable Long userId, @RequestParam("image") MultipartFile file, @AuthenticationPrincipal CustomUserDetails userDetails) { @@ -30,14 +30,14 @@ public ResponseEntity uploadUserImage(@PathVariable Long userId, @RequestPara return ResponseEntity.ok().body(ApiUtils.success(null)); } - @GetMapping("/roadmap/{roadmapId}/image") + @GetMapping("/image/roadmap/{roadmapId}") public ResponseEntity findRoadmapImage(@PathVariable Long roadmapId){ ImageResponse.RoadmapImageDTO responseDTO = imageService.findRoadmapImage(roadmapId); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } - @PostMapping("/roadmap/{roadmapId}/image") + @PostMapping("/image/roadmap/{roadmapId}") public ResponseEntity uploadRoadmapImage(@PathVariable Long roadmapId, @RequestParam("image") MultipartFile file) { @@ -46,7 +46,7 @@ public ResponseEntity uploadRoadmapImage(@PathVariable Long roadmapId, return ResponseEntity.ok().body(ApiUtils.success(null)); } - @PostMapping("/image/post") + @PostMapping("/image/write") public ResponseEntity postImage(@RequestParam("image") MultipartFile file){ ImageResponse.PostImageDTO responseDTO = imageService.postImage(file); From 57c3c8e3d5a3b5eda6329070d5980fab8e5f181a Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:36:41 +0900 Subject: [PATCH 37/66] =?UTF-8?q?fix:=20ReferenceRequest=20=EC=9A=94?= =?UTF-8?q?=EC=B2=AD=20DTO=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../step/reference/ReferenceController.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/example/tily/step/reference/ReferenceController.java b/src/main/java/com/example/tily/step/reference/ReferenceController.java index d4014af8..210a31ab 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceController.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceController.java @@ -18,25 +18,25 @@ public class ReferenceController { private final ReferenceService referenceService; // step의 참고자료 생성하기 - @PostMapping("/roadmaps/{roadmapId}/steps/{stepId}/references") + @PostMapping("/references") public ResponseEntity createReference(@RequestBody @Valid ReferenceRequest.CreateReferenceDTO requestDTO, Errors errors, - @PathVariable("roadmapId") Long roadmapId, @PathVariable("stepId") Long stepId, @AuthenticationPrincipal CustomUserDetails userDetails){ - referenceService.createReference(requestDTO, roadmapId, stepId, userDetails.getUser()); + referenceService.createReference(requestDTO, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(null)); } // step의 참고자료 목록 조회 - @GetMapping("/roadmaps/{roadmapsId}/steps/{stepsId}/references") - public ResponseEntity findReference(@PathVariable Long stepsId, @AuthenticationPrincipal CustomUserDetails userDetails){ - StepResponse.FindReferenceDTO responseDTO = referenceService.findReference(stepsId, userDetails.getUser()); + @GetMapping("/references") + public ResponseEntity findReference(@RequestBody @Valid ReferenceRequest.FindReferenceDTO requestDTO, + @AuthenticationPrincipal CustomUserDetails userDetails){ + StepResponse.FindReferenceDTO responseDTO = referenceService.findReference(requestDTO, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } // 참고자료 삭제 - @DeleteMapping("/reference/{referenceId}") - public ResponseEntity deleteReference(@PathVariable Long referenceId, @AuthenticationPrincipal CustomUserDetails userDetails) { - referenceService.deleteReference(referenceId, userDetails.getUser()); + @DeleteMapping("/reference/{id}") + public ResponseEntity deleteReference(@PathVariable("id") Long id, @AuthenticationPrincipal CustomUserDetails userDetails) { + referenceService.deleteReference(id, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(null)); } From efb159fcd52b609e63ae4a764445ab199864fec3 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:37:09 +0900 Subject: [PATCH 38/66] =?UTF-8?q?fix:=20ReferenceController=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/tily/step/reference/ReferenceRequest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/example/tily/step/reference/ReferenceRequest.java b/src/main/java/com/example/tily/step/reference/ReferenceRequest.java index f70254c0..7beb26f8 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceRequest.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceRequest.java @@ -3,6 +3,8 @@ import java.time.LocalDateTime; public class ReferenceRequest { + public record FindReferenceDTO(Long stepId){ + } public record CreateReferenceDTO(String category, String link) { } From 2e32bbc4d4769f5582da0f573fc9a7f177080c0a Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Wed, 8 Nov 2023 09:44:15 +0900 Subject: [PATCH 39/66] =?UTF-8?q?fix:=20ReferenceService=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/tily/step/reference/ReferenceRequest.java | 2 +- .../example/tily/step/reference/ReferenceService.java | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/example/tily/step/reference/ReferenceRequest.java b/src/main/java/com/example/tily/step/reference/ReferenceRequest.java index 7beb26f8..c7f5fac1 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceRequest.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceRequest.java @@ -6,6 +6,6 @@ public class ReferenceRequest { public record FindReferenceDTO(Long stepId){ } - public record CreateReferenceDTO(String category, String link) { + public record CreateReferenceDTO(Long stepId, String category, String link) { } } diff --git a/src/main/java/com/example/tily/step/reference/ReferenceService.java b/src/main/java/com/example/tily/step/reference/ReferenceService.java index 672a68b4..0e688fae 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceService.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceService.java @@ -25,15 +25,12 @@ public class ReferenceService { private final ReferenceRepository referenceRepository; private final StepRepository stepRepository; - private final RoadmapRepository roadmapRepository; private final UserRoadmapRepository userRoadmapRepository; // step의 참고자료 생성하기 @Transactional - public void createReference(ReferenceRequest.CreateReferenceDTO requestDTO, Long roadmapId, Long stepId, User user) { - Roadmap roadmap = roadmapRepository.findById(roadmapId) - .orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); - + public void createReference(ReferenceRequest.CreateReferenceDTO requestDTO, User user) { + Long stepId = requestDTO.stepId(); Step step = getStepById(stepId); Reference reference = Reference.builder() @@ -41,11 +38,13 @@ public void createReference(ReferenceRequest.CreateReferenceDTO requestDTO, Long .category(requestDTO.category()) .link(requestDTO.link()) .build(); + referenceRepository.save(reference); } // step의 참고자료 목록 조회하기 - public StepResponse.FindReferenceDTO findReference(Long stepId, User user){ + public StepResponse.FindReferenceDTO findReference(ReferenceRequest.FindReferenceDTO requestDTO, User user){ + Long stepId = requestDTO.stepId(); Step step = getStepById(stepId); List references = referenceRepository.findByStepId(stepId); From 555db9110159c0c42c7db928ed839ee4158dfabf Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 12:14:31 +0900 Subject: [PATCH 40/66] =?UTF-8?q?refactor=20:=20step=20api=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/step/StepController.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/example/tily/step/StepController.java b/src/main/java/com/example/tily/step/StepController.java index 71000274..f1ddc986 100644 --- a/src/main/java/com/example/tily/step/StepController.java +++ b/src/main/java/com/example/tily/step/StepController.java @@ -3,6 +3,7 @@ import com.example.tily._core.security.CustomUserDetails; import com.example.tily._core.utils.ApiUtils; import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.validation.Errors; @@ -16,19 +17,21 @@ public class StepController { private final StepService stepService; - // 개인 로드맵(카테고리)의 step 생성하기 - @PostMapping("/roadmaps/individual/{id}/steps") - public ResponseEntity createIndividualStep(@RequestBody @Valid StepRequest.CreateIndividualStepDTO requestDTO, Errors errors, - @PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails) { - StepResponse.CreateIndividualStepDTO responseDTO = stepService.createIndividualStep(id, requestDTO, userDetails.getUser()); - return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); + // step 생성하기 + @PostMapping("/steps") + public ResponseEntity createStep(@RequestBody @Valid StepRequest.CreateStepDTO requestDTO, Errors errors, + @AuthenticationPrincipal CustomUserDetails userDetails) { + StepResponse.CreateStepDTO responseDTO = stepService.createStep(requestDTO, userDetails.getUser()); + return ResponseEntity.ok().body(ApiUtils.success(HttpStatus.CREATED, responseDTO)); } - // 특정 step의 참고자료 목록 조회 - @GetMapping("/roadmaps/{roadmapsId}/steps/{stepsId}/references") - public ResponseEntity findReference(@PathVariable Long stepsId, @AuthenticationPrincipal CustomUserDetails userDetails){ - StepResponse.FindReferenceDTO responseDTO = stepService.findReference(stepsId); - return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); + // step 수정하기 + @PatchMapping("/steps/{id}") + public ResponseEntity updateStep(@PathVariable Long id, + @RequestBody @Valid StepRequest.UpdateStepDTO requestDTO, Errors errors, + @AuthenticationPrincipal CustomUserDetails userDetails) { + stepService.updateStep(id, requestDTO, userDetails.getUser()); + return ResponseEntity.ok().body(ApiUtils.success(null)); } // 특정 로드맵의 step 목록 전체 조회 From 29fd5db5c02d33d7cd5233303aa3583693503014 Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 12:15:00 +0900 Subject: [PATCH 41/66] =?UTF-8?q?refactor=20:=20StepService=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/step/StepService.java | 86 ++++++++++++------- 1 file changed, 55 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index 458291a0..c6a10ebd 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -2,6 +2,7 @@ import com.example.tily._core.errors.exception.ExceptionCode; import com.example.tily._core.errors.exception.CustomException; +import com.example.tily.roadmap.Category; import com.example.tily.roadmap.Roadmap; import com.example.tily.roadmap.RoadmapRepository; import com.example.tily.roadmap.relation.GroupRole; @@ -32,50 +33,62 @@ public class StepService { private final UserRoadmapRepository userRoadmapRepository; private final UserStepRepository userStepRepository; - // 개인 로드맵(카테고리)의 step 생성하기 + // step 생성하기 @Transactional - public StepResponse.CreateIndividualStepDTO createIndividualStep(Long id, StepRequest.CreateIndividualStepDTO requestDTO, User user){ + public StepResponse.CreateStepDTO createStep(StepRequest.CreateStepDTO requestDTO, User user) { - Roadmap roadmap = getRoadmapById(id); + Long roadmapId = requestDTO.roadmapId(); + Roadmap roadmap = getRoadmapById(roadmapId); + + checkMasterAndManagerPermission(roadmapId, user); // 사용자가 해당 로드맵에 속했는지 확인 - userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(id, user.getId()) + userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, user.getId()) .orElseThrow(() -> new CustomException(ExceptionCode.STEP_ROADMAP_FORBIDDEN)); - Step step = Step.builder().roadmap(roadmap).title(requestDTO.title()).build(); // 개인 로드맵이므로 description, dueDate 는 null + Step step = Step.builder() + .roadmap(roadmap) + .title(requestDTO.title()) + .build(); // 개인 로드맵이므로 description, dueDate 는 null stepRepository.save(step); - UserStep userStep = UserStep.builder().roadmap(roadmap).step(step).user(user).isSubmit(true).build(); - userStepRepository.save(userStep); + List users = userRoadmapRepository.findByRoadmapIdAndIsAcceptTrue(roadmapId).stream().map(UserRoadmap::getUser).toList(); + for (User u : users) { + UserStep userStep = UserStep.builder() + .roadmap(roadmap) + .step(step) + .user(u) + .isSubmit(roadmap.getCategory().equals(Category.CATEGORY_INDIVIDUAL)) + .build(); + userStepRepository.save(userStep); + } - return new StepResponse.CreateIndividualStepDTO(step); + return new StepResponse.CreateStepDTO(step); } - // step의 참고자료 목록 조회 - public StepResponse.FindReferenceDTO findReference(Long stepId){ - Step step = getStepById(stepId); + // step 수정하기 + @Transactional + public void updateStep(Long stepId, StepRequest.UpdateStepDTO requestDTO, User user) { - List references = referenceRepository.findByStepId(stepId); + Step step = stepRepository.findById(stepId) + .orElseThrow(() -> new CustomException(ExceptionCode.STEP_NOT_FOUND)); - List youtubeDTOs = new ArrayList<>(); - List webDTOs = new ArrayList<>(); + Roadmap roadmap = step.getRoadmap(); - for(Reference reference : references){ - String category = reference.getCategory(); - Long id = reference.getId(); - String link = reference.getLink(); + checkMasterAndManagerPermission(roadmap.getId(), user); // 관리자 권한 확인 - if(category.equals("youtube")) - youtubeDTOs.add(new StepResponse.FindReferenceDTO.YoutubeDTO(id, link)); - else if(category.equals("web")) - webDTOs.add(new StepResponse.FindReferenceDTO.WebDTO(id, link)); + // 개인 로드맵이면 대응되는 til의 제목도 수정 + if (roadmap.getCategory().equals(Category.CATEGORY_INDIVIDUAL)) { + Til til = tilRepository.findByRoadmapIdAndStepId(roadmap.getId(), stepId); + if (til != null) til.updateTitle(requestDTO.title()); + step.updateTitle(requestDTO.title()); + } else { // 그룹 로드맵일 때 + step.update(requestDTO.title(), requestDTO.description(), requestDTO.dueDate()); } - - return new StepResponse.FindReferenceDTO(step, youtubeDTOs, webDTOs); } - // 로드맵의 step 목록 전체 조회 - public StepResponse.FindAllStepDTO findAllStep (Long roadmapId, User user) { + // 특정 로드맵의 step 목록 전체 조회 + public StepResponse.FindAllStepDTO findAllStep(Long roadmapId, User user) { List steps = stepRepository.findByRoadmapId(roadmapId); @@ -85,10 +98,10 @@ public StepResponse.FindAllStepDTO findAllStep (Long roadmapId, User user) { maps.put(step, til); } - // 해당 페이지로 들어온 사람의 역할 (master, manager, member, none) + // 해당 페이지로 들어온 사람의 role (master, manager, member, none) Optional userRoadmap = userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, user.getId()); - String myRole = userRoadmap.isPresent() ? userRoadmap.get().getRole() : "none"; - int progress = userRoadmap.isPresent() ? userRoadmap.get().getProgress() : 0; + String myRole = userRoadmap.map(UserRoadmap::getRole).orElse("none"); + int progress = userRoadmap.map(UserRoadmap::getProgress).orElse(0); List stepDTOs = steps.stream() .map(step -> new StepResponse.FindAllStepDTO.StepDTO(step, maps.get(step))).collect(Collectors.toList()); @@ -99,7 +112,18 @@ private Roadmap getRoadmapById(Long roadmapId) { return roadmapRepository.findById(roadmapId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); } - private Step getStepById(Long stepId) { - return stepRepository.findById(stepId).orElseThrow(() -> new CustomException(ExceptionCode.STEP_NOT_FOUND)); + private String checkMasterAndManagerPermission(Long roadmapId, User user) { + UserRoadmap userRoadmap = getUserBelongRoadmap(roadmapId, user.getId()); + + if (!userRoadmap.getRole().equals(GroupRole.ROLE_MASTER.getValue()) && !userRoadmap.getRole().equals(GroupRole.ROLE_MANAGER.getValue())) + throw new CustomException(ExceptionCode.ROADMAP_FORBIDDEN); + + return userRoadmap.getRole(); + } + + // 해당 로드맵에 속한 user + private UserRoadmap getUserBelongRoadmap(Long roadmapId, Long userId) { + return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, userId) + .orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_BELONG)); } } From eec9952413ee121d6a4e90676e6eba5c6521c46d Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 12:15:27 +0900 Subject: [PATCH 42/66] =?UTF-8?q?refactor=20:=20step=20=EC=9D=91=EB=8B=B5?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/step/StepRequest.java | 20 +++++++++++++++++-- .../com/example/tily/step/StepResponse.java | 6 ++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/tily/step/StepRequest.java b/src/main/java/com/example/tily/step/StepRequest.java index e8090da2..3f8a9016 100644 --- a/src/main/java/com/example/tily/step/StepRequest.java +++ b/src/main/java/com/example/tily/step/StepRequest.java @@ -1,9 +1,25 @@ package com.example.tily.step; import javax.validation.constraints.NotBlank; +import java.time.LocalDateTime; public class StepRequest { - public record CreateIndividualStepDTO(@NotBlank(message = "스텝 제목을 입력해주세요.") String title) { - } + public record CreateIndividualStepDTO( + @NotBlank(message = "스텝 제목을 입력해주세요.") String title + ) { } + + public record CreateStepDTO( + @NotBlank(message = "step의 제목을 입력해주세요.") + String title, + Long roadmapId, + String description, + LocalDateTime dueDate + ) { } + + public record UpdateStepDTO( + String title, + String description, + LocalDateTime dueDate + ) { } } \ No newline at end of file diff --git a/src/main/java/com/example/tily/step/StepResponse.java b/src/main/java/com/example/tily/step/StepResponse.java index 3d916336..8319ecc6 100644 --- a/src/main/java/com/example/tily/step/StepResponse.java +++ b/src/main/java/com/example/tily/step/StepResponse.java @@ -12,6 +12,12 @@ public CreateIndividualStepDTO(Step step) { } } + public record CreateStepDTO(Long id) { + public CreateStepDTO(Step step) { + this(step.getId()); + } + } + public record FindReferenceDTO(Long id, String description, List youtubes, List webs) { public FindReferenceDTO(Step step, List youtubeDTOs, List webDTOs) { this(step.getId(), step.getDescription(), youtubeDTOs, webDTOs); From d3f65e164282d69f37d2f77c57941c62e84c54c4 Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 12:16:05 +0900 Subject: [PATCH 43/66] =?UTF-8?q?fix=20:=20ExceptionCode=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/til/TilRepository.java | 2 ++ src/main/java/com/example/tily/til/TilService.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/tily/til/TilRepository.java b/src/main/java/com/example/tily/til/TilRepository.java index 25ba0591..3699c5a2 100644 --- a/src/main/java/com/example/tily/til/TilRepository.java +++ b/src/main/java/com/example/tily/til/TilRepository.java @@ -49,4 +49,6 @@ Slice findAllByDateByOrderByCreatedDateDesc(@Param("userId") Long userId, List findTilsByUserIdAndDateRange(@Param("userId") Long userId, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate); + + Til findByRoadmapIdAndStepId(Long roadmapId, Long stepId); } diff --git a/src/main/java/com/example/tily/til/TilService.java b/src/main/java/com/example/tily/til/TilService.java index f49b0989..19f3a215 100644 --- a/src/main/java/com/example/tily/til/TilService.java +++ b/src/main/java/com/example/tily/til/TilService.java @@ -58,7 +58,7 @@ public TilResponse.CreateTilDTO createTil(TilRequest.CreateTilDTO requestDTO, Us // step이 roadmap에 속했는지 확인 if (!step.getRoadmap().equals(roadmap)) - throw new CustomException(ExceptionCode.STEP_NOT_INCLUDE); + throw new CustomException(ExceptionCode.STEP_NOT_BELONG); getUserBelongRoadmap(roadmapId, user.getId()); From 90f410e29cfa63b21f37aa2301763445bdd41069 Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 12:16:45 +0900 Subject: [PATCH 44/66] =?UTF-8?q?feat=20:=20step=20title=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/step/Step.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/tily/step/Step.java b/src/main/java/com/example/tily/step/Step.java index 4dfec685..c25c498e 100644 --- a/src/main/java/com/example/tily/step/Step.java +++ b/src/main/java/com/example/tily/step/Step.java @@ -42,8 +42,13 @@ public Step(Long id, Roadmap roadmap, String title, String description, LocalDat this.dueDate = dueDate; } - public void update(String title, String description){ + public void update(String title, String description, LocalDateTime dueDate){ this.title = title; this.description = description; + this.dueDate = dueDate; + } + + public void updateTitle(String title) { + this.title = title; } } \ No newline at end of file From 977a314b83561bcd1a41bf4725c11c2c40a368b2 Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 12:17:06 +0900 Subject: [PATCH 45/66] =?UTF-8?q?feat=20:=20til=EC=9D=98=20title=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/til/Til.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/example/tily/til/Til.java b/src/main/java/com/example/tily/til/Til.java index f4b5975a..ddecac5f 100644 --- a/src/main/java/com/example/tily/til/Til.java +++ b/src/main/java/com/example/tily/til/Til.java @@ -68,6 +68,10 @@ public void updateContent (String content) { this.content = content; } + public void updateTitle (String title) { + this.title = title; + } + public void submitTil(String submitContent) { this.content = submitContent; this.submitContent = submitContent; From d8b37b2314a6992f5769ab1bf4e10ad55c709247 Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 12:17:56 +0900 Subject: [PATCH 46/66] =?UTF-8?q?fix=20:=20ExceptionCode=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20message=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/tily/_core/errors/exception/ExceptionCode.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java b/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java index a7d0e19e..0cedc3e6 100644 --- a/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java +++ b/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java @@ -24,7 +24,7 @@ public enum ExceptionCode { // til 관련 에러 TIL_ROADMAP_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 로드맵에 til을 생성할 권한이 없습니다."), - TIL_STEP_EXIST(HttpStatus.BAD_REQUEST, "이미 step에 대한 til이 존재합니다."), + TIL_STEP_EXIST(HttpStatus.BAD_REQUEST, "해당 step에 대한 til이 이미 존재합니다."), TIL_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 til을 찾을 수 없습니다"), TIL_UPDATE_FORBIDDEN(HttpStatus.FORBIDDEN, "til을 저장할 권한이 없습니다."), TIL_CONTENT_NULL(HttpStatus.BAD_REQUEST, "til의 내용을 입력해주세요."), @@ -38,7 +38,7 @@ public enum ExceptionCode { // roadmap 관련 에러 ROADMAP_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 roadmap을 찾을 수 없습니다."), ROADMAP_NOT_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 로드맵에 속하지 않았습니다."), - ROADMAP_NOT_BELONG(HttpStatus.NOT_FOUND, "해당 reoadmap에 속하지 않습니다."), + ROADMAP_NOT_BELONG(HttpStatus.FORBIDDEN, "해당 reoadmap에 속하지 않습니다."), ROADMAP_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 roadmap을 조회할 권한이 없습니다."), ROADMAP_SUBMIT_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 til을 제출할 권한이 없습니다."), ROADMAP_ALREADY_APPLY(HttpStatus.BAD_REQUEST, "해당 로드맵에 이미 신청했습니다."), @@ -51,7 +51,7 @@ public enum ExceptionCode { // step 관련 에러 STEP_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 step을 찾을 수 없습니다."), STEP_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 step을 조회할 권한이 없습니다."), - STEP_NOT_INCLUDE(HttpStatus.BAD_REQUEST, "해당 step은 roadmap에 속하지 않았습니다."), + STEP_NOT_BELONG(HttpStatus.BAD_REQUEST, "해당 step은 roadmap에 속하지 않았습니다."), STEP_ROADMAP_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 로드맵에 step을 생성할 권한이 없습니다."), // comment 관련 에러 From faa6de6de032adc810d19c83febeadcff7cbe05e Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 12:18:20 +0900 Subject: [PATCH 47/66] =?UTF-8?q?feat=20:=20S3=20proxy=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/_core/S3/S3Config.java | 39 ++++++++++++++++--- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/tily/_core/S3/S3Config.java b/src/main/java/com/example/tily/_core/S3/S3Config.java index 007fced9..e4c675f4 100644 --- a/src/main/java/com/example/tily/_core/S3/S3Config.java +++ b/src/main/java/com/example/tily/_core/S3/S3Config.java @@ -1,5 +1,7 @@ package com.example.tily._core.S3; +import com.amazonaws.ClientConfiguration; +import com.amazonaws.Protocol; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.services.s3.AmazonS3Client; @@ -7,6 +9,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; @Configuration public class S3Config { @@ -19,17 +22,41 @@ public class S3Config { @Value("${cloud.aws.region.static}") private String region; + @Value("krmp-proxy.9rum.cc") + private String proxyHost; + + @Value("3128") + private int proxyPort; + + @Bean + @Profile({"local", "prod"}) public AmazonS3Client amazonS3Client() { BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey, secretKey); - return (AmazonS3Client) AmazonS3ClientBuilder.standard() + return (AmazonS3Client) AmazonS3ClientBuilder + .standard() .withRegion(region) .withCredentials(new AWSStaticCredentialsProvider(awsCreds)) .build(); } -} -/* -S3 설정 레퍼런스 -https://velog.io/@msung99/AWS-SpringBoot-AWS-S3-에-다중-파일-업로드-API-구현-feat.-Spring-Cloud-AWS - */ + @Bean + @Profile("deploy") + public AmazonS3Client amazonS3ClientForDeploy() { + BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey, secretKey); + + ClientConfiguration clientConfiguration = new ClientConfiguration(); + clientConfiguration.setConnectionTimeout(60000); // 연결 타임아웃 시간 60000ms = 60s 설정 + clientConfiguration.setSocketTimeout(60000); // 소켓 타임아웃 시간 60000ms = 60s 설정 + clientConfiguration.setProxyHost(proxyHost); + clientConfiguration.setProxyPort(proxyPort); + clientConfiguration.setProxyProtocol(Protocol.HTTP); + + return (AmazonS3Client) AmazonS3ClientBuilder + .standard() + .withRegion(region) + .withClientConfiguration(clientConfiguration) + .withCredentials(new AWSStaticCredentialsProvider(awsCreds)) + .build(); + } +} From a1813b93b47796e784d7238f154c986a83b700e4 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Wed, 8 Nov 2023 12:44:04 +0900 Subject: [PATCH 48/66] =?UTF-8?q?fix:=20image=20API=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/tily/image/ImageController.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/tily/image/ImageController.java b/src/main/java/com/example/tily/image/ImageController.java index 9fd2bb62..f87c33c2 100644 --- a/src/main/java/com/example/tily/image/ImageController.java +++ b/src/main/java/com/example/tily/image/ImageController.java @@ -14,14 +14,14 @@ public class ImageController { final private ImageService imageService; // 폴더 별로 관리 하기 위해 나눔(user, roadmap, post) - @GetMapping("/image/user/{userId}") + @GetMapping("/images/users/{userId}") public ResponseEntity findUserImage(@PathVariable Long userId){ ImageResponse.UserImageDTO responseDTO = imageService.findUserImage(userId); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } - @PostMapping("/image/user/{userId}") + @PostMapping("/images/users/{userId}") public ResponseEntity uploadUserImage(@PathVariable Long userId, @RequestParam("image") MultipartFile file, @AuthenticationPrincipal CustomUserDetails userDetails) { @@ -30,14 +30,14 @@ public ResponseEntity uploadUserImage(@PathVariable Long userId, @RequestPara return ResponseEntity.ok().body(ApiUtils.success(null)); } - @GetMapping("/image/roadmap/{roadmapId}") + @GetMapping("/images/roadmaps/{roadmapId}") public ResponseEntity findRoadmapImage(@PathVariable Long roadmapId){ ImageResponse.RoadmapImageDTO responseDTO = imageService.findRoadmapImage(roadmapId); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } - @PostMapping("/image/roadmap/{roadmapId}") + @PostMapping("/images/roadmaps/{roadmapId}") public ResponseEntity uploadRoadmapImage(@PathVariable Long roadmapId, @RequestParam("image") MultipartFile file) { @@ -46,7 +46,7 @@ public ResponseEntity uploadRoadmapImage(@PathVariable Long roadmapId, return ResponseEntity.ok().body(ApiUtils.success(null)); } - @PostMapping("/image/write") + @PostMapping("/images/write") public ResponseEntity postImage(@RequestParam("image") MultipartFile file){ ImageResponse.PostImageDTO responseDTO = imageService.postImage(file); From 46b85810841048ca207e4bd67fb06b835dd263b5 Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 14:23:44 +0900 Subject: [PATCH 49/66] =?UTF-8?q?fix=20:=20=ED=8A=B9=EC=A0=95=20step?= =?UTF-8?q?=EC=9D=98=20til=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20api?= =?UTF-8?q?=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tily/roadmap/RoadmapController.java | 10 ----- .../example/tily/roadmap/RoadmapService.java | 33 --------------- .../com/example/tily/til/TilController.java | 11 +++++ .../java/com/example/tily/til/TilService.java | 41 +++++++++++++++++++ 4 files changed, 52 insertions(+), 43 deletions(-) diff --git a/src/main/java/com/example/tily/roadmap/RoadmapController.java b/src/main/java/com/example/tily/roadmap/RoadmapController.java index 1d261223..da04ef34 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapController.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapController.java @@ -139,14 +139,4 @@ public ResponseEntity rejectApplication(@PathVariable Long groupId, @PathVari roadmapService.rejectApplication(groupId, memberId, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(null)); } - - // 로드맵의 특정 step의 틸 목록 조회 - @GetMapping("/roadmaps/groups/{groupId}/steps/{stepId}/tils") - public ResponseEntity findTilOfStep(@PathVariable Long groupId, @PathVariable Long stepId, - @RequestParam(value="isSubmit", defaultValue = "true") Boolean isSubmit, - @RequestParam(value="isMember", defaultValue = "true") Boolean isMember, - @RequestParam(value="name", required = false) String name){ - RoadmapResponse.FindTilOfStepDTO responseDTO = roadmapService.findTilOfStep(groupId, stepId, isSubmit, isMember, name); - return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); - } } \ No newline at end of file diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index 73a3d9a8..9e9e44bd 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -532,39 +532,6 @@ public void rejectApplication(Long groupId, Long memberId, User user){ userRoadmap.updateRole(GroupRole.ROLE_NONE.getValue()); } - @Transactional - public RoadmapResponse.FindTilOfStepDTO findTilOfStep(Long groupsId, Long stepId, Boolean isSubmit, Boolean isMember, String name){ - - // 특정 로드맵에 속한 UserRoadmap list - List userRoadmaps = userRoadmapRepository.findByRoadmapIdAndIsAcceptTrue(groupsId); - List users = userStepRepository.findAllByStepIdAndIsSubmitAndName(stepId, isSubmit, name) - .stream().map(UserStep::getUser).toList(); // 특정 step에 대해 제출 여부, 사용자 이름으로 user 조회 - - List members = new ArrayList<>(); - - if (isMember) { // 로드맵에 속한 member만 대해 - for (User user : users) { - // 로드맵에서의 사용자의 role을 알기 위해 사용자의 userRoadmap 조회 - Optional userRoadmap = userRoadmaps.stream().filter(u -> u.getUser().equals(user)).findFirst(); - - if (userRoadmap.isPresent() & userRoadmap.get().getRole().equals(GroupRole.ROLE_MEMBER.getValue())) { - Til til = tilRepository.findByStepIdAndUserId(stepId, user.getId()); - if (til==null) members.add(new RoadmapResponse.FindTilOfStepDTO.MemberDTO(null, user)); - else members.add(new RoadmapResponse.FindTilOfStepDTO.MemberDTO(til, user)); - } - } - } else { // 로드맵에 속한 모든 사용자에 대해 - for (User user : users) { - Til til = tilRepository.findByStepIdAndUserId(stepId, user.getId()); - if (til==null) members.add(new RoadmapResponse.FindTilOfStepDTO.MemberDTO(null, user)); - else members.add(new RoadmapResponse.FindTilOfStepDTO.MemberDTO(til, user)); - } - } - - return new RoadmapResponse.FindTilOfStepDTO(members); - } - - private static String generateRandomCode() { String upperAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String lowerAlphabet = "abcdefghijklmnopqrstuvwxyz"; diff --git a/src/main/java/com/example/tily/til/TilController.java b/src/main/java/com/example/tily/til/TilController.java index f21c0ad9..6a864a51 100644 --- a/src/main/java/com/example/tily/til/TilController.java +++ b/src/main/java/com/example/tily/til/TilController.java @@ -2,6 +2,7 @@ import com.example.tily._core.security.CustomUserDetails; import com.example.tily._core.utils.ApiUtils; +import com.example.tily.roadmap.RoadmapResponse; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -77,4 +78,14 @@ public ResponseEntity findAllMyTil(@RequestParam(value = "roadmapId", require TilResponse.FindAllDTO responseDTO = tilService.findAllMyTil(roadmapId, date, title, page, size, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } + + // 로드맵의 특정 step의 til 목록 조회하기 + @GetMapping("/steps/{stepId}/tils") + public ResponseEntity findTilOfStep(@PathVariable Long stepId, + @RequestParam(value="isSubmit", defaultValue = "true") Boolean isSubmit, + @RequestParam(value="isMember", defaultValue = "true") Boolean isMember, + @RequestParam(value="name", required = false) String name){ + RoadmapResponse.FindTilOfStepDTO responseDTO = tilService.findTilOfStep(stepId, isSubmit, isMember, name); + return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); + } } diff --git a/src/main/java/com/example/tily/til/TilService.java b/src/main/java/com/example/tily/til/TilService.java index 19f3a215..105da3f5 100644 --- a/src/main/java/com/example/tily/til/TilService.java +++ b/src/main/java/com/example/tily/til/TilService.java @@ -8,6 +8,8 @@ import com.example.tily.roadmap.Category; import com.example.tily.roadmap.Roadmap; import com.example.tily.roadmap.RoadmapRepository; +import com.example.tily.roadmap.RoadmapResponse; +import com.example.tily.roadmap.relation.GroupRole; import com.example.tily.roadmap.relation.UserRoadmap; import com.example.tily.roadmap.relation.UserRoadmapRepository; import com.example.tily.step.Step; @@ -176,6 +178,45 @@ public TilResponse.FindAllDTO findAllMyTil(Long roadmapId, String date, String t return new TilResponse.FindAllDTO(tilDTOs, tils.hasNext()); } + // 로드맵의 특정 step의 til 목록 조회하기 + @Transactional + public RoadmapResponse.FindTilOfStepDTO findTilOfStep(Long stepId, Boolean isSubmit, Boolean isMember, String name){ + + Step step = stepRepository.findById(stepId) + .orElseThrow(() -> new CustomException(ExceptionCode.STEP_NOT_FOUND)); + + Roadmap roadmap = step.getRoadmap(); + + // 특정 로드맵에 속한 UserRoadmap list + List userRoadmaps = userRoadmapRepository.findByRoadmapIdAndIsAcceptTrue(roadmap.getId()); + // 특정 step에 대해 제출 여부, 사용자 이름으로 user 조회 + List users = userStepRepository.findAllByStepIdAndIsSubmitAndName(stepId, isSubmit, name) + .stream().map(UserStep::getUser).toList(); + + List members = new ArrayList<>(); + + if (isMember) { // 로드맵에 속한 member만 대해 + for (User user : users) { + // 로드맵에서의 사용자의 role을 알기 위해 사용자의 userRoadmap 조회 + Optional userRoadmap = userRoadmaps.stream().filter(u -> u.getUser().equals(user)).findFirst(); + + if (userRoadmap.isPresent() && userRoadmap.get().getRole().equals(GroupRole.ROLE_MEMBER.getValue())) { + Til til = tilRepository.findByStepIdAndUserId(stepId, user.getId()); + if (til==null) members.add(new RoadmapResponse.FindTilOfStepDTO.MemberDTO(null, user)); + else members.add(new RoadmapResponse.FindTilOfStepDTO.MemberDTO(til, user)); + } + } + } else { // 로드맵에 속한 모든 사용자에 대해 + for (User user : users) { + Til til = tilRepository.findByStepIdAndUserId(stepId, user.getId()); + if (til==null) members.add(new RoadmapResponse.FindTilOfStepDTO.MemberDTO(null, user)); + else members.add(new RoadmapResponse.FindTilOfStepDTO.MemberDTO(til, user)); + } + } + + return new RoadmapResponse.FindTilOfStepDTO(members); + } + private Til getTilById(Long tilId) { return tilRepository.findById(tilId).orElseThrow(() -> new CustomException(ExceptionCode.TIL_NOT_FOUND)); } From b30f45ce11a876833ee082bdf04b8abd96c099d4 Mon Sep 17 00:00:00 2001 From: suuding Date: Wed, 8 Nov 2023 15:23:36 +0900 Subject: [PATCH 50/66] =?UTF-8?q?refactor=20:=20=EC=B6=A9=EB=8F=8C=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0=20=EB=B0=8F=20=EB=B2=84=EA=B7=B8=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/TiLyApplication.java | 4 ++ .../com/example/tily/comment/Comment.java | 4 +- .../com/example/tily/roadmap/Roadmap.java | 6 +-- .../example/tily/roadmap/RoadmapService.java | 8 ---- .../tily/roadmap/relation/UserRoadmap.java | 2 +- src/main/java/com/example/tily/step/Step.java | 4 +- .../com/example/tily/step/StepController.java | 1 - .../com/example/tily/step/StepService.java | 24 ++++------ .../tily/step/reference/Reference.java | 5 +-- .../example/tily/step/relation/UserStep.java | 2 +- src/main/java/com/example/tily/til/Til.java | 6 +-- .../com/example/tily/til/TilRepository.java | 4 +- src/main/java/com/example/tily/user/User.java | 2 +- .../com/example/tily/user/UserService.java | 2 +- .../socialLogin/KakaoLoginService.java | 2 +- .../socialLogin/SocialLoginController.java | 4 +- .../socialLogin/SocialLoginResponse.java | 2 +- src/main/resources/data.sql | 44 +++++++++---------- 18 files changed, 56 insertions(+), 70 deletions(-) rename src/main/java/com/example/tily/{ => user}/socialLogin/KakaoLoginService.java (99%) rename src/main/java/com/example/tily/{ => user}/socialLogin/SocialLoginController.java (90%) rename src/main/java/com/example/tily/{ => user}/socialLogin/SocialLoginResponse.java (78%) diff --git a/src/main/java/com/example/tily/TiLyApplication.java b/src/main/java/com/example/tily/TiLyApplication.java index 804777cd..0bff9ecd 100644 --- a/src/main/java/com/example/tily/TiLyApplication.java +++ b/src/main/java/com/example/tily/TiLyApplication.java @@ -172,6 +172,8 @@ private Roadmap newIndividualRoadmap(User creator, Category category, String nam .category(category) .name(name) .stepNum(stepNum) + .isPublic(false) + .isRecruit(false) .build(); } @@ -184,6 +186,8 @@ public Roadmap newTilyRoadmap(User creator, Category category, String name, Stri .currentNum(currentNum) .stepNum(stepNum) .image(image) + .isPublic(false) + .isRecruit(false) .build(); } diff --git a/src/main/java/com/example/tily/comment/Comment.java b/src/main/java/com/example/tily/comment/Comment.java index 4156be6b..ebe09e51 100644 --- a/src/main/java/com/example/tily/comment/Comment.java +++ b/src/main/java/com/example/tily/comment/Comment.java @@ -19,7 +19,7 @@ @Entity @Table(name="comment_tb") @SQLDelete(sql = "UPDATE comment_tb SET isDeleted = true WHERE id = ?") -@Where(clause = "isDeleted = false") +@Where(clause = "is_deleted = false") public class Comment extends BaseTimeEntity { @Id @@ -34,7 +34,7 @@ public class Comment extends BaseTimeEntity { @JoinColumn(name="writer_id") private User writer; - @Column + @Column(columnDefinition="TEXT", length = 1000) private String content; @Column diff --git a/src/main/java/com/example/tily/roadmap/Roadmap.java b/src/main/java/com/example/tily/roadmap/Roadmap.java index 5bc75ab8..4ec89148 100644 --- a/src/main/java/com/example/tily/roadmap/Roadmap.java +++ b/src/main/java/com/example/tily/roadmap/Roadmap.java @@ -19,7 +19,7 @@ @Entity @Table(name="roadmap_tb") @SQLDelete(sql = "UPDATE roadmap_tb SET isDeleted = true WHERE id = ?") -@Where(clause = "isDeleted = false") +@Where(clause = "is_deleted = false") public class Roadmap extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -36,7 +36,7 @@ public class Roadmap extends BaseTimeEntity { @Column(nullable = false) private String name; - @Column + @Column(columnDefinition="TEXT", length = 1000) private String description; @Column @@ -61,7 +61,7 @@ public class Roadmap extends BaseTimeEntity { private boolean isDeleted = false; @Builder - public Roadmap(Long id, User creator, Category category, String name, String description, Boolean isPublic, Long currentNum, String code, Boolean isRecruit, int stepNum, String image) { + public Roadmap(Long id, User creator, Category category, String name, String description, boolean isPublic, Long currentNum, String code, boolean isRecruit, int stepNum, String image) { this.id = id; this.creator = creator; this.category = category; diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index 4b928f09..88769fbb 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -546,12 +546,4 @@ private List getTilsByRoadmapId(Long roadmapId){ private UserRoadmap getUserNotBelongRoadmap(Long roadmapId, Long userId) { return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptFalse(roadmapId, userId).orElseThrow(() -> new CustomException(ExceptionCode.USER_NOT_FOUND)); } - - private LocalDateTime parseDate(String date) { - try { - return LocalDateTime.parse(date, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); - } catch (DateTimeParseException e) { - throw new CustomException(ExceptionCode.DATE_WRONG); - } - } } diff --git a/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java b/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java index ab8cc98d..bc3f9ca7 100644 --- a/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java +++ b/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java @@ -17,7 +17,7 @@ @Entity @Table(name="user_roadmap_tb") @SQLDelete(sql = "UPDATE user_roadmap_tb SET isDeleted = true WHERE id = ?") -@Where(clause = "isDeleted = false") +@Where(clause = "is_deleted = false") public class UserRoadmap extends BaseTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/example/tily/step/Step.java b/src/main/java/com/example/tily/step/Step.java index e631a627..72e90817 100644 --- a/src/main/java/com/example/tily/step/Step.java +++ b/src/main/java/com/example/tily/step/Step.java @@ -19,7 +19,7 @@ @Entity @Table(name="step_tb") @SQLDelete(sql = "UPDATE step_tb SET isDeleted = true WHERE id = ?") -@Where(clause = "isDeleted = false") +@Where(clause = "is_deleted = false") public class Step { @Id @@ -33,7 +33,7 @@ public class Step { @Column(nullable = false) private String title; - @Column + @Column(columnDefinition="TEXT", length = 5000) private String description; @Column diff --git a/src/main/java/com/example/tily/step/StepController.java b/src/main/java/com/example/tily/step/StepController.java index fee36186..14d53046 100644 --- a/src/main/java/com/example/tily/step/StepController.java +++ b/src/main/java/com/example/tily/step/StepController.java @@ -45,7 +45,6 @@ public ResponseEntity findAllStep(@PathVariable("roadmapId") Long roadmapId, @DeleteMapping("/step/{stepId}") public ResponseEntity deleteStep(@PathVariable Long stepId, @AuthenticationPrincipal CustomUserDetails userDetails){ stepService.deleteStep(stepId, userDetails.getUser()); - return ResponseEntity.ok().body(ApiUtils.success(null)); } } \ No newline at end of file diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index 496ad113..757b64e6 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -87,10 +87,11 @@ public void updateStep(Long stepId, StepRequest.UpdateStepDTO requestDTO, User u } else { // 그룹 로드맵일 때 step.update(requestDTO.title(), requestDTO.description(), requestDTO.dueDate()); } + } // 특정 로드맵의 step 목록 전체 조회 - public StepResponse.FindAllStepDTO findAllStep(Long roadmapId, User user) { + public StepResponse.FindAllStepDTO findAllStep (Long roadmapId, User user) { List steps = stepRepository.findByRoadmapId(roadmapId); @@ -138,7 +139,8 @@ public void deleteStep(Long stepId, User user){ stepRepository.delete(step); } - private String checkMasterAndManagerPermission(Long roadmapId, User user) { // 매니저급만 접근 + // 로드맵의 관리자 권한 확인 (master, manager) + private String checkMasterAndManagerPermission(Long roadmapId, User user) { UserRoadmap userRoadmap = getUserBelongRoadmap(roadmapId, user.getId()); if(!userRoadmap.getRole().equals(GroupRole.ROLE_MASTER.getValue()) && !userRoadmap.getRole().equals(GroupRole.ROLE_MANAGER.getValue())){ @@ -147,17 +149,12 @@ private String checkMasterAndManagerPermission(Long roadmapId, User user) { // return userRoadmap.getRole(); } - private Roadmap getRoadmapById(Long roadmapId) { - return roadmapRepository.findById(roadmapId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); + private Step getStepById(Long stepId) { + return stepRepository.findById(stepId).orElseThrow(() -> new CustomException(ExceptionCode.STEP_NOT_FOUND)); } - private String checkMasterAndManagerPermission(Long roadmapId, User user) { - UserRoadmap userRoadmap = getUserBelongRoadmap(roadmapId, user.getId()); - - if (!userRoadmap.getRole().equals(GroupRole.ROLE_MASTER.getValue()) && !userRoadmap.getRole().equals(GroupRole.ROLE_MANAGER.getValue())) - throw new CustomException(ExceptionCode.ROADMAP_FORBIDDEN); - - return userRoadmap.getRole(); + private Roadmap getRoadmapById(Long roadmapId) { + return roadmapRepository.findById(roadmapId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); } // 해당 로드맵에 속한 user @@ -165,9 +162,4 @@ private UserRoadmap getUserBelongRoadmap(Long roadmapId, Long userId) { return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, userId) .orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_BELONG)); } - - // 해당 로드맵에 속한 user - private UserRoadmap getUserBelongRoadmap(Long roadmapId, Long userId) { - return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, userId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_BELONG)); - } } diff --git a/src/main/java/com/example/tily/step/reference/Reference.java b/src/main/java/com/example/tily/step/reference/Reference.java index a6a61990..27b73791 100644 --- a/src/main/java/com/example/tily/step/reference/Reference.java +++ b/src/main/java/com/example/tily/step/reference/Reference.java @@ -5,7 +5,6 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import org.checkerframework.checker.units.qual.C; import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.Where; @@ -16,7 +15,7 @@ @Entity @Table(name="reference_tb") @SQLDelete(sql = "UPDATE reference_tb SET isDeleted = true WHERE id = ?") -@Where(clause = "isDeleted = false") +@Where(clause = "is_deleted = false") public class Reference { @Id @@ -30,7 +29,7 @@ public class Reference { @Column(nullable = false) private String category; - @Column(nullable = false, columnDefinition="TEXT", length = 1000) + @Column(columnDefinition="TEXT", length = 1000) private String link; @Column diff --git a/src/main/java/com/example/tily/step/relation/UserStep.java b/src/main/java/com/example/tily/step/relation/UserStep.java index d8daa4fd..958e692d 100644 --- a/src/main/java/com/example/tily/step/relation/UserStep.java +++ b/src/main/java/com/example/tily/step/relation/UserStep.java @@ -17,7 +17,7 @@ @Entity @Table(name="user_step_tb") @SQLDelete(sql = "UPDATE user_step_tb SET isDeleted = true WHERE id = ?") -@Where(clause = "isDeleted = false") +@Where(clause = "is_deleted = false") public class UserStep { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/example/tily/til/Til.java b/src/main/java/com/example/tily/til/Til.java index 88089f7a..0341be2e 100644 --- a/src/main/java/com/example/tily/til/Til.java +++ b/src/main/java/com/example/tily/til/Til.java @@ -16,7 +16,7 @@ @Entity @Table(name="til_tb") @SQLDelete(sql = "UPDATE til_tb SET isDeleted = true WHERE id = ?") -@Where(clause = "isDeleted = false") +@Where(clause = "is_deleted = false") public class Til extends BaseTimeEntity { @Id @@ -38,10 +38,10 @@ public class Til extends BaseTimeEntity { @Column(nullable = false) private String title; - @Column(columnDefinition="TEXT", length = 5000) + @Column(columnDefinition="TEXT") private String content; - @Column(columnDefinition="TEXT", length = 5000) + @Column(columnDefinition="TEXT") private String submitContent; @Column diff --git a/src/main/java/com/example/tily/til/TilRepository.java b/src/main/java/com/example/tily/til/TilRepository.java index f0592343..55d15409 100644 --- a/src/main/java/com/example/tily/til/TilRepository.java +++ b/src/main/java/com/example/tily/til/TilRepository.java @@ -41,7 +41,7 @@ Slice findAllByDateByOrderByCreatedDateDesc(@Param("userId") Long userId, List findByStepId(Long stepId); - List findByUserId(Long userId); + List findByWriterId(Long writerId); @Query("select t from Til t where t.writer.id=:userId and t.step.id=:stepId") Til findByStepIdAndUserId(@Param("stepId") Long stepId, @Param("userId") Long userId); @@ -54,6 +54,8 @@ List findTilsByUserIdAndDateRange(@Param("userId") Long userId, @Param("endDate") LocalDateTime endDate); Til findByRoadmapIdAndStepId(Long roadmapId, Long stepId); + + List findByRoadmapId(Long roadmapId); @Modifying @Query("update Til t SET t.isDeleted = true WHERE t.isDeleted = false AND t.id IN :tilIds") diff --git a/src/main/java/com/example/tily/user/User.java b/src/main/java/com/example/tily/user/User.java index 0cecdb45..5cd231b1 100644 --- a/src/main/java/com/example/tily/user/User.java +++ b/src/main/java/com/example/tily/user/User.java @@ -19,7 +19,7 @@ @Entity @Table(name="user_tb") @SQLDelete(sql = "UPDATE user_tb SET isDeleted = true WHERE id = ?") -@Where(clause = "isDeleted = false") +@Where(clause = "is_deleted = false") public class User extends BaseTimeEntity { @Id diff --git a/src/main/java/com/example/tily/user/UserService.java b/src/main/java/com/example/tily/user/UserService.java index 1b0d4f69..477ced75 100644 --- a/src/main/java/com/example/tily/user/UserService.java +++ b/src/main/java/com/example/tily/user/UserService.java @@ -322,6 +322,6 @@ private List getUserStepByUserId(Long userId) { } private List getTilByUserId(Long userId){ - return tilRepository.findByUserId(userId); + return tilRepository.findByWriterId(userId); } } diff --git a/src/main/java/com/example/tily/socialLogin/KakaoLoginService.java b/src/main/java/com/example/tily/user/socialLogin/KakaoLoginService.java similarity index 99% rename from src/main/java/com/example/tily/socialLogin/KakaoLoginService.java rename to src/main/java/com/example/tily/user/socialLogin/KakaoLoginService.java index 8650994d..772d1b71 100644 --- a/src/main/java/com/example/tily/socialLogin/KakaoLoginService.java +++ b/src/main/java/com/example/tily/user/socialLogin/KakaoLoginService.java @@ -1,4 +1,4 @@ -package com.example.tily.socialLogin; +package com.example.tily.user.socialLogin; import com.example.tily._core.security.CustomUserDetails; import com.example.tily._core.security.JWTProvider; diff --git a/src/main/java/com/example/tily/socialLogin/SocialLoginController.java b/src/main/java/com/example/tily/user/socialLogin/SocialLoginController.java similarity index 90% rename from src/main/java/com/example/tily/socialLogin/SocialLoginController.java rename to src/main/java/com/example/tily/user/socialLogin/SocialLoginController.java index 94a7a490..f8cfd4ed 100644 --- a/src/main/java/com/example/tily/socialLogin/SocialLoginController.java +++ b/src/main/java/com/example/tily/user/socialLogin/SocialLoginController.java @@ -1,4 +1,4 @@ -package com.example.tily.socialLogin; +package com.example.tily.user.socialLogin; import com.example.tily._core.utils.ApiUtils; import com.fasterxml.jackson.core.JsonProcessingException; @@ -9,8 +9,6 @@ import lombok.RequiredArgsConstructor; -import javax.servlet.http.HttpServletResponse; - @RestController @RequiredArgsConstructor diff --git a/src/main/java/com/example/tily/socialLogin/SocialLoginResponse.java b/src/main/java/com/example/tily/user/socialLogin/SocialLoginResponse.java similarity index 78% rename from src/main/java/com/example/tily/socialLogin/SocialLoginResponse.java rename to src/main/java/com/example/tily/user/socialLogin/SocialLoginResponse.java index f9c9dd53..b5f3d685 100644 --- a/src/main/java/com/example/tily/socialLogin/SocialLoginResponse.java +++ b/src/main/java/com/example/tily/user/socialLogin/SocialLoginResponse.java @@ -1,4 +1,4 @@ -package com.example.tily.socialLogin; +package com.example.tily.user.socialLogin; public class SocialLoginResponse{ public record UserInfoDto(String nickname, String email){}; diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index b3857c41..7f251d8d 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -7,7 +7,7 @@ INSERT INTO til_tb (id, title, content) VALUES ('1','이것은 제목','이것 --drop table if exists reference_tb CASCADE --drop table if exists roadmap_tb CASCADE --drop table if exists step_tb CASCADE -drop table if exists til_tb CASCADE; +--drop table if exists til_tb CASCADE; --drop table if exists user_roadmap_tb CASCADE --drop table if exists user_step_tb CASCADE --drop table if exists user_tb CASCADE @@ -43,21 +43,21 @@ drop table if exists til_tb CASCADE; -- primary key (id) --); -- -create table til_tb ( - id bigint not null auto_increment, - created_date timestamp, - updated_date timestamp, - comment_num integer, - content varchar(255), - is_personal boolean, - submit_content varchar(255), - submit_date timestamp, - title varchar(255) not null, - roadmap_id bigint, - step_id bigint, - writer_id bigint, - primary key (id) -); +--create table til_tb ( +-- id bigint not null auto_increment, +-- created_date timestamp, +-- updated_date timestamp, +-- comment_num integer, +-- content varchar(255), +-- is_personal boolean, +-- submit_content varchar(255), +-- submit_date timestamp, +-- title varchar(255) not null, +-- roadmap_id bigint, +-- step_id bigint, +-- writer_id bigint, +-- primary key (id) +--); -- --create table step_tb ( -- id bigint not null auto_increment, @@ -92,9 +92,9 @@ create table til_tb ( -- step_id bigint, -- primary key (id) --); - -insert into til_tb (id, created_date, updated_date, comment_num, content, is_personal, roadmap_id, step_id, submit_content, submit_date, title, writer_id) values (default, '2023-09-10', '2023-09-10', 0, '이것은 내용입니다.', true, '1', '5', null, null, '이것은 제목입니다!!', '1'); -insert into til_tb (id, created_date, updated_date, comment_num, content, is_personal, roadmap_id, step_id, submit_content, submit_date, title, writer_id) values (default, '2023-10-10', '2023-10-10', 0, '이것은 내용입니다.', true, '1', '6', null, null, '이것은 제목입니다!!!', '1'); -insert into til_tb (id, created_date, updated_date, comment_num, content, is_personal, roadmap_id, step_id, submit_content, submit_date, title, writer_id) values (default, '2022-12-10', '2022-12-10', 0, '이것은 내용입니다.', true, '1', '7', null, null, '이것은 제목입니다!!!!', '1'); -insert into til_tb (id, created_date, updated_date, comment_num, content, is_personal, roadmap_id, step_id, submit_content, submit_date, title, writer_id) values (default, '2023-01-10', '2023-01-10', 0, '이것은 내용입니다.', true, '1', '8', null, null, '이것은 제목입니다 홍홍', '1'); -insert into til_tb (id, created_date, updated_date, comment_num, content, is_personal, roadmap_id, step_id, submit_content, submit_date, title, writer_id) values (default, '2023-02-10', '2023-02-10', 0, '이것은 내용입니다.', true, '1', '9', null, null, '이것은 제목입니다.', '1'); \ No newline at end of file +-- +--insert into til_tb (id, created_date, updated_date, comment_num, content, is_personal, roadmap_id, step_id, submit_content, submit_date, title, writer_id) values (default, '2023-09-10', '2023-09-10', 0, '이것은 내용입니다.', true, '1', '5', null, null, '이것은 제목입니다!!', '1'); +--insert into til_tb (id, created_date, updated_date, comment_num, content, is_personal, roadmap_id, step_id, submit_content, submit_date, title, writer_id) values (default, '2023-10-10', '2023-10-10', 0, '이것은 내용입니다.', true, '1', '6', null, null, '이것은 제목입니다!!!', '1'); +--insert into til_tb (id, created_date, updated_date, comment_num, content, is_personal, roadmap_id, step_id, submit_content, submit_date, title, writer_id) values (default, '2022-12-10', '2022-12-10', 0, '이것은 내용입니다.', true, '1', '7', null, null, '이것은 제목입니다!!!!', '1'); +--insert into til_tb (id, created_date, updated_date, comment_num, content, is_personal, roadmap_id, step_id, submit_content, submit_date, title, writer_id) values (default, '2023-01-10', '2023-01-10', 0, '이것은 내용입니다.', true, '1', '8', null, null, '이것은 제목입니다 홍홍', '1'); +--insert into til_tb (id, created_date, updated_date, comment_num, content, is_personal, roadmap_id, step_id, submit_content, submit_date, title, writer_id) values (default, '2023-02-10', '2023-02-10', 0, '이것은 내용입니다.', true, '1', '9', null, null, '이것은 제목입니다.', '1'); \ No newline at end of file From 379d8deb0869a66c05dcd8fa9fc35a9ea554a952 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Wed, 8 Nov 2023 15:52:34 +0900 Subject: [PATCH 51/66] =?UTF-8?q?fix:=20alarm=20isRead=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20Boolean=20->=20boolean=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/alarm/Alarm.java | 4 ++-- src/main/java/com/example/tily/alarm/AlarmResponse.java | 2 +- src/main/java/com/example/tily/roadmap/RoadmapRequest.java | 6 +++--- src/main/java/com/example/tily/roadmap/RoadmapResponse.java | 6 +++--- src/main/java/com/example/tily/step/StepResponse.java | 6 ------ src/main/java/com/example/tily/step/StepService.java | 1 - 6 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/example/tily/alarm/Alarm.java b/src/main/java/com/example/tily/alarm/Alarm.java index 3a33dd71..843f6f54 100644 --- a/src/main/java/com/example/tily/alarm/Alarm.java +++ b/src/main/java/com/example/tily/alarm/Alarm.java @@ -34,10 +34,10 @@ public class Alarm extends BaseTimeEntity { private Comment comment; @Column - private Boolean isRead; + private boolean isRead; @Builder - public Alarm(Til til, User receiver, Comment comment, Boolean isRead) { + public Alarm(Til til, User receiver, Comment comment, boolean isRead) { this.til = til; this.receiver = receiver; this.comment = comment; diff --git a/src/main/java/com/example/tily/alarm/AlarmResponse.java b/src/main/java/com/example/tily/alarm/AlarmResponse.java index cbcbb028..76f3b197 100644 --- a/src/main/java/com/example/tily/alarm/AlarmResponse.java +++ b/src/main/java/com/example/tily/alarm/AlarmResponse.java @@ -37,7 +37,7 @@ public record AlarmDTO(Long id, public AlarmDTO(Alarm alarm){ this(alarm.getId(), alarm.getTil().getId(), - alarm.getIsRead(), + alarm.isRead(), alarm.getCreatedDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), new RoadmapDTO(alarm.getTil().getRoadmap()), new StepDTO(alarm.getTil().getStep()), diff --git a/src/main/java/com/example/tily/roadmap/RoadmapRequest.java b/src/main/java/com/example/tily/roadmap/RoadmapRequest.java index fadb0373..c99ee4d6 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapRequest.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapRequest.java @@ -15,16 +15,16 @@ public record CreateIndividualRoadmapDTO(@NotBlank(message = "이름을 입력 @Size(min=2, max=20, message = "이름은 2자에서 20자 이내여야 합니다.") String name) { } - public record CreateGroupRoadmapDTO(String name, String description, Boolean isPublic) { + public record CreateGroupRoadmapDTO(String name, String description, boolean isPublic) { } public record CreateTilyRoadmapDTO(RoadmapDTO roadmap, List steps) { } - public record UpdateGroupRoadmapDTO(String name, String description, Boolean isPublic, Boolean isRecruit) { + public record UpdateGroupRoadmapDTO(String name, String description, boolean isPublic, boolean isRecruit) { } - public record RoadmapDTO(@NotBlank(message = "이름을 입력해주세요.") String name, String description, String code, Boolean isPublic, Boolean isRecruit){ + public record RoadmapDTO(@NotBlank(message = "이름을 입력해주세요.") String name, String description, String code, boolean isPublic, boolean isRecruit){ } public record StepDTO( diff --git a/src/main/java/com/example/tily/roadmap/RoadmapResponse.java b/src/main/java/com/example/tily/roadmap/RoadmapResponse.java index 5301fd1b..4d6ca6c8 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapResponse.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapResponse.java @@ -22,7 +22,7 @@ public CreateRoadmapDTO(Roadmap roadmap) { } } - public record FindGroupRoadmapDTO(Creator creator, String name, String description, String myRole, Long recentTilId, Long recentStepId, Boolean isPublic, Boolean isRecruit, String code, String category, List steps) { + public record FindGroupRoadmapDTO(Creator creator, String name, String description, String myRole, Long recentTilId, Long recentStepId, boolean isPublic, boolean isRecruit, String code, String category, List steps) { public FindGroupRoadmapDTO(Roadmap roadmap, List steps, User user, Long recentTilId, Long recentStepId, String myRole) { this(new Creator(user.getName(), user.getImage()), roadmap.getName(), roadmap.getDescription(), myRole, recentTilId, recentStepId, roadmap.isPublic(), roadmap.isRecruit(), roadmap.getCode(), roadmap.getCategory().getValue(), steps); } @@ -62,7 +62,7 @@ public TilyDTO(Roadmap roadmap) { } public record GroupDTO (Long id, String name, int stepNum, Creator creator, boolean isManager, String description) { - public GroupDTO(Roadmap roadmap, Boolean isManager) { + public GroupDTO(Roadmap roadmap, boolean isManager) { this(roadmap.getId(), roadmap.getName(), roadmap.getStepNum(), new Creator(roadmap.getCreator()), isManager, roadmap.getDescription()); } @@ -73,7 +73,7 @@ public Creator(User user) { } } - public record FindRoadmapByQueryDTO (String category, List roadmaps, Boolean hasNext) { + public record FindRoadmapByQueryDTO (String category, List roadmaps, boolean hasNext) { public FindRoadmapByQueryDTO(Category category, List roadmaps, boolean hasNext) { this(category.getValue(), roadmaps, hasNext); } diff --git a/src/main/java/com/example/tily/step/StepResponse.java b/src/main/java/com/example/tily/step/StepResponse.java index 8319ecc6..2492bdaf 100644 --- a/src/main/java/com/example/tily/step/StepResponse.java +++ b/src/main/java/com/example/tily/step/StepResponse.java @@ -6,12 +6,6 @@ public class StepResponse { - public record CreateIndividualStepDTO(Long id) { - public CreateIndividualStepDTO(Step step) { - this(step.getId()); - } - } - public record CreateStepDTO(Long id) { public CreateStepDTO(Step step) { this(step.getId()); diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index 757b64e6..9809de66 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -89,7 +89,6 @@ public void updateStep(Long stepId, StepRequest.UpdateStepDTO requestDTO, User u } } - // 특정 로드맵의 step 목록 전체 조회 public StepResponse.FindAllStepDTO findAllStep (Long roadmapId, User user) { From 4f3adfb294ba31585314f7b4e1f971818dc87b6d Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Wed, 8 Nov 2023 16:25:40 +0900 Subject: [PATCH 52/66] =?UTF-8?q?fix:=20UserRoadamp=20isAccept=20=ED=95=84?= =?UTF-8?q?=EB=93=9C=20Boolean=20->=20boolean=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/tily/alarm/AlarmResponse.java | 2 +- .../com/example/tily/roadmap/RoadmapService.java | 4 ++-- .../example/tily/roadmap/relation/UserRoadmap.java | 6 +++--- .../java/com/example/tily/step/StepResponse.java | 2 +- .../java/com/example/tily/til/TilController.java | 4 ++-- src/main/java/com/example/tily/til/TilResponse.java | 12 ++++++------ src/main/java/com/example/tily/til/TilService.java | 2 +- src/main/java/com/example/tily/user/User.java | 2 ++ 8 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/example/tily/alarm/AlarmResponse.java b/src/main/java/com/example/tily/alarm/AlarmResponse.java index 76f3b197..620fe6b2 100644 --- a/src/main/java/com/example/tily/alarm/AlarmResponse.java +++ b/src/main/java/com/example/tily/alarm/AlarmResponse.java @@ -28,7 +28,7 @@ public SenderDTO(User user){ public record AlarmDTO(Long id, Long tilId, - Boolean isRead, + boolean isRead, String createDate, RoadmapDTO roadmap, StepDTO step, diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index 88769fbb..7be9c26d 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -273,7 +273,7 @@ public void applyGroupRoadmap(RoadmapRequest.ApplyRoadmapDTO requestDTO, Long id if (ur.isPresent()) { if (ur.get().getRole().equals(GroupRole.ROLE_NONE.getValue())) throw new CustomException(ExceptionCode.ROADMAP_REJECT); - else if (ur.get().getIsAccept().equals(true)) + else if (ur.get().isAccept()) throw new CustomException(ExceptionCode.ROADMAP_ALREADY_MEMBER); else throw new CustomException(ExceptionCode.ROADMAP_ALREADY_APPLY); @@ -301,7 +301,7 @@ public void applyTilyRoadmap(Long id, User user) { // 이미 로드맵에 속한 경우 Optional ur = userRoadmapRepository.findByRoadmapIdAndUserId(id, user.getId()); - if (ur.isPresent() && ur.get().getIsAccept().equals(true)) + if (ur.isPresent() && ur.get().isAccept()) throw new CustomException(ExceptionCode.ROADMAP_ALREADY_MEMBER); UserRoadmap userRoadmap = UserRoadmap.builder() diff --git a/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java b/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java index bc3f9ca7..e4ba4b51 100644 --- a/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java +++ b/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java @@ -35,7 +35,7 @@ public class UserRoadmap extends BaseTimeEntity { private String content; @Column - private Boolean isAccept; + private boolean isAccept; @Column(nullable = false) private String role; @@ -47,7 +47,7 @@ public class UserRoadmap extends BaseTimeEntity { private boolean isDeleted = false; @Builder - public UserRoadmap(Roadmap roadmap, User user, String content, Boolean isAccept, GroupRole role, int progress) { + public UserRoadmap(Roadmap roadmap, User user, String content, boolean isAccept, GroupRole role, int progress) { this.roadmap = roadmap; this.user = user; this.content = content; @@ -58,7 +58,7 @@ public UserRoadmap(Roadmap roadmap, User user, String content, Boolean isAccept, public void updateRole(String role) { this.role = role; } - public void updateIsAccept(Boolean isAccept) { this.isAccept = isAccept; } + public void updateIsAccept(boolean isAccept) { this.isAccept = isAccept; } public void updateProgress(int progress) { this.progress = progress; diff --git a/src/main/java/com/example/tily/step/StepResponse.java b/src/main/java/com/example/tily/step/StepResponse.java index 2492bdaf..051fbef0 100644 --- a/src/main/java/com/example/tily/step/StepResponse.java +++ b/src/main/java/com/example/tily/step/StepResponse.java @@ -24,7 +24,7 @@ public record WebDTO(Long id, String link) {} public record FindAllStepDTO(List steps, int progress, String myRole) { - public record StepDTO(Long id, String title, Boolean isSubmit, Long tilId) { + public record StepDTO(Long id, String title, boolean isSubmit, Long tilId) { public StepDTO(Step step, Til til) { this(step.getId(), step.getTitle(), til==null ? false : (til.getSubmitContent()!=null), til==null ? null : til.getId()); } diff --git a/src/main/java/com/example/tily/til/TilController.java b/src/main/java/com/example/tily/til/TilController.java index 6a864a51..a74ab7b9 100644 --- a/src/main/java/com/example/tily/til/TilController.java +++ b/src/main/java/com/example/tily/til/TilController.java @@ -82,8 +82,8 @@ public ResponseEntity findAllMyTil(@RequestParam(value = "roadmapId", require // 로드맵의 특정 step의 til 목록 조회하기 @GetMapping("/steps/{stepId}/tils") public ResponseEntity findTilOfStep(@PathVariable Long stepId, - @RequestParam(value="isSubmit", defaultValue = "true") Boolean isSubmit, - @RequestParam(value="isMember", defaultValue = "true") Boolean isMember, + @RequestParam(value="isSubmit", defaultValue = "true") boolean isSubmit, + @RequestParam(value="isMember", defaultValue = "true") boolean isMember, @RequestParam(value="name", required = false) String name){ RoadmapResponse.FindTilOfStepDTO responseDTO = tilService.findTilOfStep(stepId, isSubmit, isMember, name); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); diff --git a/src/main/java/com/example/tily/til/TilResponse.java b/src/main/java/com/example/tily/til/TilResponse.java index 96279d3d..79e41187 100644 --- a/src/main/java/com/example/tily/til/TilResponse.java +++ b/src/main/java/com/example/tily/til/TilResponse.java @@ -21,9 +21,9 @@ public CreateTilDTO(Til til) { this(til.getId()); } } - - public record ViewDTO(String content, String submitContent, Boolean isPersonal, Boolean isSubmit, String roadmapName, StepDTO step, List comments) { - public ViewDTO(Step step, Til til, Boolean isSubmit, List comments) { + + public record ViewDTO(String content, String submitContent, boolean isPersonal, boolean isSubmit, String roadmapName, StepDTO step, List comments) { + public ViewDTO(Step step, Til til, boolean isSubmit, List comments) { this(til.getContent(), til.getSubmitContent(), til.isPersonal(), isSubmit, step.getRoadmap().getName(), new StepDTO(step), comments); } @@ -33,15 +33,15 @@ public StepDTO(Step step) { } } - public record CommentDTO(Long id, String content, String name, String image, Boolean isOwner, String createDate) { - public CommentDTO(Comment comment, Boolean isOwner) { + public record CommentDTO(Long id, String content, String name, String image, boolean isOwner, String createDate) { + public CommentDTO(Comment comment, boolean isOwner) { this(comment.getId(), comment.getContent(), comment.getWriter().getName(), comment.getWriter().getImage(), isOwner, comment.getCreatedDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); } } } - public record FindAllDTO(List tils, Boolean hasNext) {} + public record FindAllDTO(List tils, boolean hasNext) {} public record TilDTO(Long id, String createDate, StepDTO step, RoadmapDTO roadmap) { public TilDTO(Til til, Step step, Roadmap roadmap) { diff --git a/src/main/java/com/example/tily/til/TilService.java b/src/main/java/com/example/tily/til/TilService.java index 5383a1f0..29f51985 100644 --- a/src/main/java/com/example/tily/til/TilService.java +++ b/src/main/java/com/example/tily/til/TilService.java @@ -184,7 +184,7 @@ public TilResponse.FindAllDTO findAllMyTil(Long roadmapId, String date, String t // 로드맵의 특정 step의 til 목록 조회하기 @Transactional - public RoadmapResponse.FindTilOfStepDTO findTilOfStep(Long stepId, Boolean isSubmit, Boolean isMember, String name){ + public RoadmapResponse.FindTilOfStepDTO findTilOfStep(Long stepId, boolean isSubmit, boolean isMember, String name){ Step step = stepRepository.findById(stepId) .orElseThrow(() -> new CustomException(ExceptionCode.STEP_NOT_FOUND)); diff --git a/src/main/java/com/example/tily/user/User.java b/src/main/java/com/example/tily/user/User.java index 5cd231b1..6a3f14bb 100644 --- a/src/main/java/com/example/tily/user/User.java +++ b/src/main/java/com/example/tily/user/User.java @@ -35,8 +35,10 @@ public class User extends BaseTimeEntity { @Column(length = 100, nullable = false) private String password; + @Column private String image; + @Column @Enumerated(EnumType.STRING) private Role role; From f7ad97a85c62ffbf4cb4807802d7f6f421bf88f3 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 01:07:19 +0900 Subject: [PATCH 53/66] =?UTF-8?q?fix:=20comment=20softDelete=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 6148 -> 6148 bytes src/.DS_Store | Bin 6148 -> 6148 bytes src/main/.DS_Store | Bin 6148 -> 6148 bytes src/main/java/.DS_Store | Bin 6148 -> 6148 bytes src/main/java/com/.DS_Store | Bin 6148 -> 6148 bytes src/main/java/com/example/.DS_Store | Bin 6148 -> 6148 bytes src/main/java/com/example/tily/.DS_Store | Bin 10244 -> 10244 bytes .../com/example/tily/comment/Comment.java | 2 +- .../example/tily/comment/CommentService.java | 4 ++-- .../example/tily/roadmap/RoadmapResponse.java | 3 --- src/test/.DS_Store | Bin 6148 -> 6148 bytes src/test/java/.DS_Store | Bin 6148 -> 6148 bytes src/test/java/com/.DS_Store | Bin 6148 -> 6148 bytes src/test/java/com/example/.DS_Store | Bin 8196 -> 8196 bytes src/test/java/com/example/tily/.DS_Store | Bin 8196 -> 8196 bytes 15 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.DS_Store b/.DS_Store index 0daae8bc754969401e0c18e2bc9b1ce5ef36cd16..74e8564aa05b97c4b3bed919ceef83f47a661168 100644 GIT binary patch delta 69 zcmZoMXffEZl9h4CJrt}M&_nE3dR;jwK@vbmPQ6T3MR&8wY8iaqRRT#LGjr+ Zxq10rlO5UQ8M`+pvMpuY%+B$b9{}GZ6w?3z delta 94 zcmZoMXffEZl9h4$q!noW!=2aWfmoKYjpS*%Q(L diff --git a/src/.DS_Store b/src/.DS_Store index ca0ab83b2769a3afa161512d3765ad886486a59b..7fe294d165922de1e42f6e6f926697a1b5053ee9 100644 GIT binary patch delta 47 zcmZoMXffE}%`!QPwUooi+*C)w*urS?bymm89IVGVj0{Y46pYNxHeYAeXWGop@s}R} DNQ4cH delta 107 zcmZoMXffE}&BC~SvJXq4n|O7#rMZrRk)c_wjzYDik%5kaiLqI2EhmSlvc7dte0EN5 rUVbM77%(zIXa-&=4Wqgyv#_4wFf=pPQ7|^K+ diff --git a/src/main/java/com/.DS_Store b/src/main/java/com/.DS_Store index f8fd70aca46d8415ff0293766a18b9232a0249ee..3402cd823015303b78a0cf5d4845607946d3952c 100644 GIT binary patch delta 69 zcmZoMXffCj&cwK5as*SMxf`w77jzYDik%5kaiLqI2EhmSlvc7dte0EN5 eUVbM77%(zIXa-&=4Wqg?voJHWZf4{7#}5D#JQ4{2 diff --git a/src/main/java/com/example/tily/.DS_Store b/src/main/java/com/example/tily/.DS_Store index 144f801ea3f65ae7a3034cce122263e133dba65d..c07dcb3950cfccc84e3219a2c899dcd1063aa117 100644 GIT binary patch delta 61 zcmV-D0K)%-P=rvBPXQgVP`eKS9g_?YLz5;Mb_X{#EFd#DGLtSF8#(c*o`dBbQCNsCZ7?Io?IZLQjbGzPP$=ma(-?B0|MYsnVaw8l9ZF51XRf3n;mp) ra@A2sARDLZ6cp7S_>~uA5bKQ1O;VScH?u4JVwt=`Tz<2n=o2OY!Ky}J diff --git a/src/main/java/com/example/tily/comment/Comment.java b/src/main/java/com/example/tily/comment/Comment.java index ebe09e51..030384f2 100644 --- a/src/main/java/com/example/tily/comment/Comment.java +++ b/src/main/java/com/example/tily/comment/Comment.java @@ -18,7 +18,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="comment_tb") -@SQLDelete(sql = "UPDATE comment_tb SET isDeleted = true WHERE id = ?") +@SQLDelete(sql = "UPDATE comment_tb SET is_deleted = true WHERE id = ?") @Where(clause = "is_deleted = false") public class Comment extends BaseTimeEntity { diff --git a/src/main/java/com/example/tily/comment/CommentService.java b/src/main/java/com/example/tily/comment/CommentService.java index 2689df74..6036aee5 100644 --- a/src/main/java/com/example/tily/comment/CommentService.java +++ b/src/main/java/com/example/tily/comment/CommentService.java @@ -71,8 +71,8 @@ public void deleteComment(Long id, User user) { Comment comment = commentRepository.findById(id) .orElseThrow(() -> new CustomException(ExceptionCode.COMMENT_NOT_FOUND)); - // 댓글 주인 또는 글의 주인만 댓글 삭제 가능 - if(!comment.getWriter().getId().equals(user.getId()) || !comment.getTil().getWriter().getId().equals(user.getId())) + // 댓글 주인이 아니고 글의 주인도 아니라면 삭제 불가 + if(!comment.getWriter().getId().equals(user.getId()) && !comment.getTil().getWriter().getId().equals(user.getId())) throw new CustomException(ExceptionCode.COMMENT_DELETE_FORBIDDEN); alarmRepository.deleteByCommentId(id); diff --git a/src/main/java/com/example/tily/roadmap/RoadmapResponse.java b/src/main/java/com/example/tily/roadmap/RoadmapResponse.java index 4d6ca6c8..a144a88a 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapResponse.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapResponse.java @@ -1,13 +1,10 @@ package com.example.tily.roadmap; -import com.example.tily.roadmap.relation.GroupRole; import com.example.tily.roadmap.relation.UserRoadmap; import com.example.tily.step.Step; import com.example.tily.step.reference.Reference; import com.example.tily.til.Til; -import com.example.tily.user.Role; import com.example.tily.user.User; -import org.joda.time.DateTime; import java.time.LocalDate; import java.time.LocalDateTime; diff --git a/src/test/.DS_Store b/src/test/.DS_Store index 07c41797784d28ee4bf53b45d77b0033095e3285..dad2471ca2b959469cf5f6984d3d546addd355be 100644 GIT binary patch delta 21 ccmZoMXffDufQiG%z(hyE$lPr62__p+07-ZTG5`Po delta 21 ccmZoMXffDufQiG{z(hyE$lPS}2__p+07-cUF#rGn diff --git a/src/test/java/.DS_Store b/src/test/java/.DS_Store index ca9ad98b5a63209e5810d060252e1c14e99a8dd6..28c8dec897acb24c42adc55d4bc3df0c81cedfab 100644 GIT binary patch delta 21 ccmZoMXffEZhl#_;z(hyE$lPr65he#w07)J^%m! delta 21 ccmZoMXffDuhKa-2z(hyE$lPS}6($2w07_8?Jpcdz diff --git a/src/test/java/com/example/.DS_Store b/src/test/java/com/example/.DS_Store index bd4a5204eebac50086384e38ba872327de44d348..f8c4467ed3e437879da69c966d29129aff9b4ca7 100644 GIT binary patch delta 21 ccmZp1XmQwZK!C%@z(hyE$lPr62>}~^08GvXXaE2J delta 21 ccmZp1XmQwZK!C&8z(hyE$lPS}2>}~^08GyYX8-^I diff --git a/src/test/java/com/example/tily/.DS_Store b/src/test/java/com/example/tily/.DS_Store index c901d31f3683a85a4ab0a86cdb674e9fea629216..ed168e18d3a085df0f0c5894c2051274fddb52b9 100644 GIT binary patch delta 24 fcmZp1XmQwZMu6SOz(hyE$b538ki%wS!H;|ZV)_T0 delta 25 gcmZp1XmQwZMu5ZEz(hyE$lPRdm5}{rVZo1l0BMc~(EtDd From 6cbb5949bbc82336c7f6b1dc1249199bfdd5aef5 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 01:16:06 +0900 Subject: [PATCH 54/66] =?UTF-8?q?fix:=20roadmap=20softDelete=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/tily/_core/errors/exception/ExceptionCode.java | 2 +- src/main/java/com/example/tily/roadmap/Roadmap.java | 2 +- src/main/java/com/example/tily/roadmap/RoadmapController.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java b/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java index 0c7207c2..0ec658ac 100644 --- a/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java +++ b/src/main/java/com/example/tily/_core/errors/exception/ExceptionCode.java @@ -39,7 +39,7 @@ public enum ExceptionCode { ROADMAP_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 roadmap을 찾을 수 없습니다."), ROADMAP_NOT_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 로드맵에 속하지 않았습니다."), ROADMAP_NOT_BELONG(HttpStatus.FORBIDDEN, "해당 reoadmap에 속하지 않습니다."), - ROADMAP_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 roadmap을 조회할 권한이 없습니다."), + ROADMAP_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 roadmap에 접근할 권한이 없습니다."), ROADMAP_SUBMIT_FORBIDDEN(HttpStatus.FORBIDDEN, "해당 til을 제출할 권한이 없습니다."), ROADMAP_ALREADY_APPLY(HttpStatus.BAD_REQUEST, "해당 로드맵에 이미 신청했습니다."), ROADMAP_REJECT(HttpStatus.BAD_REQUEST, "로드맵 신청이 거절되었습니다."), diff --git a/src/main/java/com/example/tily/roadmap/Roadmap.java b/src/main/java/com/example/tily/roadmap/Roadmap.java index 4ec89148..c402d197 100644 --- a/src/main/java/com/example/tily/roadmap/Roadmap.java +++ b/src/main/java/com/example/tily/roadmap/Roadmap.java @@ -18,7 +18,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="roadmap_tb") -@SQLDelete(sql = "UPDATE roadmap_tb SET isDeleted = true WHERE id = ?") +@SQLDelete(sql = "UPDATE roadmap_tb SET is_deleted = true WHERE id = ?") @Where(clause = "is_deleted = false") public class Roadmap extends BaseTimeEntity { @Id diff --git a/src/main/java/com/example/tily/roadmap/RoadmapController.java b/src/main/java/com/example/tily/roadmap/RoadmapController.java index f5512bc6..86f467b7 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapController.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapController.java @@ -144,6 +144,6 @@ public ResponseEntity rejectApplication(@PathVariable Long groupId, @PathVari @DeleteMapping("/roadmaps/{id}") public ResponseEntity deleteRoadmap(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ roadmapService.deleteRoadmap(id, userDetails.getUser()); - return ResponseEntity.ok().body(null); + return ResponseEntity.ok().body(ApiUtils.success(null)); } } \ No newline at end of file From 47b062e8f0d2a1f09fc0cdc0b08f0ce07f2c4365 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 01:31:06 +0900 Subject: [PATCH 55/66] =?UTF-8?q?fix:=20step=20softDelete=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/step/Step.java | 2 +- src/main/java/com/example/tily/step/StepController.java | 2 +- src/main/java/com/example/tily/step/StepService.java | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/tily/step/Step.java b/src/main/java/com/example/tily/step/Step.java index 72e90817..eba61b10 100644 --- a/src/main/java/com/example/tily/step/Step.java +++ b/src/main/java/com/example/tily/step/Step.java @@ -18,7 +18,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="step_tb") -@SQLDelete(sql = "UPDATE step_tb SET isDeleted = true WHERE id = ?") +@SQLDelete(sql = "UPDATE step_tb SET is_deleted = true WHERE id = ?") @Where(clause = "is_deleted = false") public class Step { diff --git a/src/main/java/com/example/tily/step/StepController.java b/src/main/java/com/example/tily/step/StepController.java index 14d53046..2c48ce9c 100644 --- a/src/main/java/com/example/tily/step/StepController.java +++ b/src/main/java/com/example/tily/step/StepController.java @@ -42,7 +42,7 @@ public ResponseEntity findAllStep(@PathVariable("roadmapId") Long roadmapId, } // step 삭제 - @DeleteMapping("/step/{stepId}") + @DeleteMapping("/steps/{stepId}") public ResponseEntity deleteStep(@PathVariable Long stepId, @AuthenticationPrincipal CustomUserDetails userDetails){ stepService.deleteStep(stepId, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(null)); diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index 9809de66..cb9a3c8e 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -117,7 +117,7 @@ public void deleteStep(Long stepId, User user){ checkMasterAndManagerPermission(step.getRoadmap().getId(), user); // 매니저급만 삭제 가능 - List tils = tilRepository.findByStepId(stepId); + List tils = getTisByStepId(stepId); List tilIds = tils.stream() .map(Til::getId) .collect(Collectors.toList()); @@ -156,6 +156,10 @@ private Roadmap getRoadmapById(Long roadmapId) { return roadmapRepository.findById(roadmapId).orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); } + private List getTisByStepId(Long stepId){ + return tilRepository.findByStepId(stepId); + } + // 해당 로드맵에 속한 user private UserRoadmap getUserBelongRoadmap(Long roadmapId, Long userId) { return userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(roadmapId, userId) From 1a7a17768712c25c854c3432becbbced41ecb44b Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 01:46:33 +0900 Subject: [PATCH 56/66] =?UTF-8?q?fix:=20reference=20softDelete=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/step/reference/Reference.java | 2 +- .../com/example/tily/step/reference/ReferenceController.java | 3 ++- .../com/example/tily/step/reference/ReferenceRepository.java | 4 ++++ .../com/example/tily/step/reference/ReferenceService.java | 2 +- src/main/java/com/example/tily/step/relation/UserStep.java | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/tily/step/reference/Reference.java b/src/main/java/com/example/tily/step/reference/Reference.java index 27b73791..42a4804e 100644 --- a/src/main/java/com/example/tily/step/reference/Reference.java +++ b/src/main/java/com/example/tily/step/reference/Reference.java @@ -14,7 +14,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="reference_tb") -@SQLDelete(sql = "UPDATE reference_tb SET isDeleted = true WHERE id = ?") +@SQLDelete(sql = "UPDATE reference_tb SET is_deleted = true WHERE id = ?") @Where(clause = "is_deleted = false") public class Reference { diff --git a/src/main/java/com/example/tily/step/reference/ReferenceController.java b/src/main/java/com/example/tily/step/reference/ReferenceController.java index 210a31ab..aebf0291 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceController.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceController.java @@ -13,6 +13,7 @@ @RestController @RequiredArgsConstructor +@RequestMapping("/api") public class ReferenceController { private final ReferenceService referenceService; @@ -34,7 +35,7 @@ public ResponseEntity findReference(@RequestBody @Valid ReferenceRequest.Find } // 참고자료 삭제 - @DeleteMapping("/reference/{id}") + @DeleteMapping("/references/{id}") public ResponseEntity deleteReference(@PathVariable("id") Long id, @AuthenticationPrincipal CustomUserDetails userDetails) { referenceService.deleteReference(id, userDetails.getUser()); diff --git a/src/main/java/com/example/tily/step/reference/ReferenceRepository.java b/src/main/java/com/example/tily/step/reference/ReferenceRepository.java index e0b005ca..36e0bf4e 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceRepository.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceRepository.java @@ -9,6 +9,10 @@ public interface ReferenceRepository extends JpaRepository { List findByStepId(Long stepId); + @Modifying + @Query("update Reference r SET r.isDeleted = true WHERE r.isDeleted = false AND r.id = :referenceId") + void softDeleteReferenceById(Long referenceId); + @Modifying @Query("update Reference r SET r.isDeleted = true WHERE r.isDeleted = false AND r.step.id IN :stepIds") void softDeleteReferenceByStepIds(List stepIds); // 여러 step에 대한 reference 삭제 diff --git a/src/main/java/com/example/tily/step/reference/ReferenceService.java b/src/main/java/com/example/tily/step/reference/ReferenceService.java index 0e688fae..ae1158ef 100644 --- a/src/main/java/com/example/tily/step/reference/ReferenceService.java +++ b/src/main/java/com/example/tily/step/reference/ReferenceService.java @@ -72,7 +72,7 @@ public void deleteReference(Long referenceId, User user){ checkMasterAndManagerPermission(reference.getStep().getRoadmap().getId(), user); // 매니저급만 삭제 가능 - referenceRepository.delete(reference); + referenceRepository.softDeleteReferenceById(referenceId); } private String checkMasterAndManagerPermission(Long roadmapId, User user) { // 매니저급만 접근 diff --git a/src/main/java/com/example/tily/step/relation/UserStep.java b/src/main/java/com/example/tily/step/relation/UserStep.java index 958e692d..ceaed43f 100644 --- a/src/main/java/com/example/tily/step/relation/UserStep.java +++ b/src/main/java/com/example/tily/step/relation/UserStep.java @@ -16,7 +16,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="user_step_tb") -@SQLDelete(sql = "UPDATE user_step_tb SET isDeleted = true WHERE id = ?") +@SQLDelete(sql = "UPDATE user_step_tb SET is_deleted = true WHERE id = ?") @Where(clause = "is_deleted = false") public class UserStep { @Id From 80482730c5bba54e36d6659b3e51a98b9ae59d81 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 01:53:59 +0900 Subject: [PATCH 57/66] =?UTF-8?q?fix:=20til=20softDelete=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/step/StepRepository.java | 4 ++++ src/main/java/com/example/tily/step/StepService.java | 2 +- src/main/java/com/example/tily/til/Til.java | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/tily/step/StepRepository.java b/src/main/java/com/example/tily/step/StepRepository.java index 8ef75b54..dd9fce5d 100644 --- a/src/main/java/com/example/tily/step/StepRepository.java +++ b/src/main/java/com/example/tily/step/StepRepository.java @@ -20,6 +20,10 @@ public interface StepRepository extends JpaRepository { @Query("select s from Step s join fetch s.roadmap where s.roadmap.id=:roadmapId") List findByRoadmapId(@Param("roadmapId") Long roadmapId); + @Modifying + @Query("update Step s SET s.isDeleted = true WHERE s.isDeleted = false AND s.id = :stepId") + void softDeleteStepById(Long stepId); + @Modifying @Query("update Step s SET s.isDeleted = true WHERE s.isDeleted = false AND s.id IN :stepIds") void softDeleteStepByStepIds(List stepIds); diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index cb9a3c8e..54d6faaf 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -135,7 +135,7 @@ public void deleteStep(Long stepId, User user){ userStepRepository.softDeleteUserStepByStepId(stepId); // 5. Step을 삭제한다 - stepRepository.delete(step); + stepRepository.softDeleteStepById(stepId); } // 로드맵의 관리자 권한 확인 (master, manager) diff --git a/src/main/java/com/example/tily/til/Til.java b/src/main/java/com/example/tily/til/Til.java index 0341be2e..634e742f 100644 --- a/src/main/java/com/example/tily/til/Til.java +++ b/src/main/java/com/example/tily/til/Til.java @@ -15,7 +15,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="til_tb") -@SQLDelete(sql = "UPDATE til_tb SET isDeleted = true WHERE id = ?") +@SQLDelete(sql = "UPDATE til_tb SET is_deleted = true WHERE id = ?") @Where(clause = "is_deleted = false") public class Til extends BaseTimeEntity { From 02435fe072ef004cb5e188ab550476d6a475d724 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 01:57:39 +0900 Subject: [PATCH 58/66] =?UTF-8?q?fix=20user=20softDelete=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/user/User.java | 2 +- src/main/java/com/example/tily/user/UserRepository.java | 5 +++++ src/main/java/com/example/tily/user/UserService.java | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/tily/user/User.java b/src/main/java/com/example/tily/user/User.java index 6a3f14bb..e9c37c8c 100644 --- a/src/main/java/com/example/tily/user/User.java +++ b/src/main/java/com/example/tily/user/User.java @@ -18,7 +18,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="user_tb") -@SQLDelete(sql = "UPDATE user_tb SET isDeleted = true WHERE id = ?") +@SQLDelete(sql = "UPDATE user_tb SET is_deleted = true WHERE id = ?") @Where(clause = "is_deleted = false") public class User extends BaseTimeEntity { diff --git a/src/main/java/com/example/tily/user/UserRepository.java b/src/main/java/com/example/tily/user/UserRepository.java index 0426b10b..29419719 100644 --- a/src/main/java/com/example/tily/user/UserRepository.java +++ b/src/main/java/com/example/tily/user/UserRepository.java @@ -1,10 +1,15 @@ package com.example.tily.user; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import java.util.Optional; public interface UserRepository extends JpaRepository { + @Modifying + @Query("update User u SET u.isDeleted = true WHERE u.isDeleted = false AND u.id = :userId") + void softDeleteUserById(Long userId); Optional findByEmail(String email); } diff --git a/src/main/java/com/example/tily/user/UserService.java b/src/main/java/com/example/tily/user/UserService.java index 477ced75..3db16bae 100644 --- a/src/main/java/com/example/tily/user/UserService.java +++ b/src/main/java/com/example/tily/user/UserService.java @@ -236,7 +236,7 @@ public void withdrawMembership(User user){ roadmapRepository.softDeleteRoadmapByRoadmapIds(roadmapIds); // 8. 유저 삭제 - userRepository.delete(user); + userRepository.softDeleteUserById(user.getId()); } ////////////// From d82e45d034f6b6d0f45efe4b3260483850e836ae Mon Sep 17 00:00:00 2001 From: suuding Date: Thu, 9 Nov 2023 04:45:45 +0900 Subject: [PATCH 59/66] =?UTF-8?q?feat=20:=20=EB=A1=9C=EB=93=9C=EB=A7=B5=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20api=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/tily/roadmap/RoadmapController.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/example/tily/roadmap/RoadmapController.java b/src/main/java/com/example/tily/roadmap/RoadmapController.java index 86f467b7..8cada663 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapController.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapController.java @@ -16,23 +16,15 @@ public class RoadmapController { private final RoadmapService roadmapService; - // 개인 로드맵(카테고리) 생성하기 - @PostMapping("/roadmaps/individual") - public ResponseEntity createIndividualRoadmap(@RequestBody @Valid RoadmapRequest.CreateIndividualRoadmapDTO requestDTO, Errors errors, - @AuthenticationPrincipal CustomUserDetails userDetails) { - RoadmapResponse.CreateRoadmapDTO responseDTO = roadmapService.createIndividualRoadmap(requestDTO, userDetails.getUser()); - return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); - } - - // 그룹 로드맵 생성하기 + // 로드맵 생성하기 @PostMapping("/roadmaps") - public ResponseEntity createGroupRoadmap(@RequestBody @Valid RoadmapRequest.CreateGroupRoadmapDTO requestDTO, Errors errors, + public ResponseEntity createRoadmap(@RequestBody @Valid RoadmapRequest.CreateRoadmapDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails){ - RoadmapResponse.CreateRoadmapDTO responseDTO = roadmapService.createGroupRoadmap(requestDTO, userDetails.getUser()); + RoadmapResponse.CreateRoadmapDTO responseDTO = roadmapService.createRoadmap(requestDTO, userDetails.getUser()); return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } - // 틸리 로드맵 생성하기 + // 틸리 로드맵 생성하기 - 임시 api @PostMapping("/roadmaps/tily") public ResponseEntity createTilyRoadmap(@RequestBody @Valid RoadmapRequest.CreateTilyRoadmapDTO requestDTO, Errors errors, @AuthenticationPrincipal CustomUserDetails userDetails){ From acf8823deac9995166168008aa24326786b8f72d Mon Sep 17 00:00:00 2001 From: suuding Date: Thu, 9 Nov 2023 04:46:39 +0900 Subject: [PATCH 60/66] =?UTF-8?q?faet=20:=20=EB=A1=9C=EB=93=9C=EB=A7=B5=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=ED=95=98=EA=B8=B0=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(=EA=B0=9C=EC=9D=B8,=20=EA=B7=B8=EB=A3=B9?= =?UTF-8?q?=20=EC=83=9D=EC=84=B1=20=ED=95=9C=EB=B2=88=EC=97=90=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/tily/roadmap/RoadmapRequest.java | 77 +++++++++++++------ .../example/tily/roadmap/RoadmapService.java | 36 +++------ 2 files changed, 64 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/example/tily/roadmap/RoadmapRequest.java b/src/main/java/com/example/tily/roadmap/RoadmapRequest.java index c99ee4d6..68f3e02c 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapRequest.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapRequest.java @@ -11,21 +11,45 @@ public class RoadmapRequest { - public record CreateIndividualRoadmapDTO(@NotBlank(message = "이름을 입력해주세요.") - @Size(min=2, max=20, message = "이름은 2자에서 20자 이내여야 합니다.") String name) { - } - - public record CreateGroupRoadmapDTO(String name, String description, boolean isPublic) { - } + public record CreateIndividualRoadmapDTO( + @NotBlank(message = "이름을 입력해주세요.") + @Size(min=2, max=20, message = "이름은 2자에서 20자 이내여야 합니다.") + String name + ) { } + public record CreateGroupRoadmapDTO( + String name, + String description, + boolean isPublic + ) { } + + public record CreateRoadmapDTO ( + String category, + @NotBlank(message = "이름을 입력해주세요.") + @Size(min=2, max=20, message = "이름은 2자에서 20자 이내여야 합니다.") + String name, + String description, + boolean isPublic + ) { } - public record CreateTilyRoadmapDTO(RoadmapDTO roadmap, List steps) { - } + public record CreateTilyRoadmapDTO( + RoadmapDTO roadmap, + List steps + ) { } - public record UpdateGroupRoadmapDTO(String name, String description, boolean isPublic, boolean isRecruit) { - } + public record UpdateGroupRoadmapDTO( + String name, + String description, + boolean isPublic, + boolean isRecruit + ) { } - public record RoadmapDTO(@NotBlank(message = "이름을 입력해주세요.") String name, String description, String code, boolean isPublic, boolean isRecruit){ - } + public record RoadmapDTO( + @NotBlank(message = "이름을 입력해주세요.") String name, + String description, + String code, + boolean isPublic, + boolean isRecruit + ){ } public record StepDTO( Long id, @@ -35,21 +59,28 @@ public record StepDTO( ReferenceDTOs references, LocalDateTime dueDate) {} - public record ReferenceDTOs(List youtube, List web) { - } + public record ReferenceDTOs( + List youtube, + List web + ) { } - public record ReferenceDTO(Long id, @NotBlank(message = "링크 주소를 입력해주세요.") String link) { - } + public record ReferenceDTO( + Long id, + @NotBlank(message = "링크 주소를 입력해주세요.") String link + ) { } - public record ApplyRoadmapDTO(@NotBlank(message="소개를 입력해주세요.")String content){ - } + public record ApplyRoadmapDTO( + @NotBlank(message="소개를 입력해주세요.") String content + ) { } - public record ParticipateRoadmapDTO(@NotBlank(message="이름을 입력해주세요.") - @Size(min=8, max=8, message = "코드는 8자여야 합니다.") String code){ - } + public record ParticipateRoadmapDTO( + @NotBlank(message="이름을 입력해주세요.") + @Size(min=8, max=8, message = "코드는 8자여야 합니다.") String code + ){ } - public record ChangeMemberRoleDTO(@NotNull(message="역할을 선택해주세요.") String role){ - } + public record ChangeMemberRoleDTO( + @NotNull(message="역할을 선택해주세요.") String role + ){ } } diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index 7be9c26d..2a2da716 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -38,40 +38,19 @@ public class RoadmapService { private final UserStepRepository userStepRepository; private final CommentRepository commentRepository; + // 로드맵 생성하기 @Transactional - public RoadmapResponse.CreateRoadmapDTO createIndividualRoadmap(RoadmapRequest.CreateIndividualRoadmapDTO requestDTO, User user){ + public RoadmapResponse.CreateRoadmapDTO createRoadmap(RoadmapRequest.CreateRoadmapDTO requestDTO, User user){ Roadmap roadmap = Roadmap.builder() .creator(user) - .category(Category.CATEGORY_INDIVIDUAL) - .name(requestDTO.name()) - .stepNum(0) - .build(); - roadmapRepository.save(roadmap); - - UserRoadmap userRoadmap = UserRoadmap.builder() - .roadmap(roadmap) - .user(user) - .role(GroupRole.ROLE_MASTER) - .isAccept(true) - .build(); - userRoadmapRepository.save(userRoadmap); - - return new RoadmapResponse.CreateRoadmapDTO(roadmap); - } - - @Transactional - public RoadmapResponse.CreateRoadmapDTO createGroupRoadmap(RoadmapRequest.CreateGroupRoadmapDTO requestDTO, User user){ - - Roadmap roadmap = Roadmap.builder() - .creator(user) - .category(Category.CATEGORY_GROUP) + .category(Category.getCategory(requestDTO.category())) .name(requestDTO.name()) .description(requestDTO.description()) .isPublic(requestDTO.isPublic()) // 공개여부 .currentNum(1L) - .code(generateRandomCode()) - .isRecruit(true) // 모집여부 + .code(requestDTO.category().equals(Category.CATEGORY_TILY.getValue()) ? generateRandomCode() : null) + .isRecruit(requestDTO.category().equals(Category.CATEGORY_TILY.getValue())) // 모집여부 .stepNum(0) .build(); roadmapRepository.save(roadmap); @@ -88,6 +67,7 @@ public RoadmapResponse.CreateRoadmapDTO createGroupRoadmap(RoadmapRequest.Create return new RoadmapResponse.CreateRoadmapDTO(roadmap); } + // 틸리 로드맵 생성하기 - 임시 api @Transactional public RoadmapResponse.CreateRoadmapDTO createTilyRoadmap(RoadmapRequest.CreateTilyRoadmapDTO requestDTO, User user){ @@ -157,6 +137,7 @@ public RoadmapResponse.CreateRoadmapDTO createTilyRoadmap(RoadmapRequest.CreateT return new RoadmapResponse.CreateRoadmapDTO(roadmap); } + // 로드맵 정보 조회하기 public RoadmapResponse.FindGroupRoadmapDTO findGroupRoadmap(Long id, User user){ Roadmap roadmap = roadmapRepository.findById(id) .orElseThrow(() -> new CustomException(ExceptionCode.ROADMAP_NOT_FOUND)); @@ -224,6 +205,7 @@ public void updateGroupRoadmap(Long id, RoadmapRequest.UpdateGroupRoadmapDTO req roadmap.update(requestDTO); } + // 내가 속한 로드맵 전체 목록 조회하기 public RoadmapResponse.FindAllMyRoadmapDTO findAllMyRoadmaps(User user) { List roadmaps = userRoadmapRepository.findByUserIdAndIsAccept(user.getId(), true); // 내가 속한 로드맵 조회 @@ -247,6 +229,7 @@ public RoadmapResponse.FindAllMyRoadmapDTO findAllMyRoadmaps(User user) { return new RoadmapResponse.FindAllMyRoadmapDTO(categories, new RoadmapResponse.FindAllMyRoadmapDTO.RoadmapDTO(tilys, groups)); } + // 로드맵 조회하기 public RoadmapResponse.FindRoadmapByQueryDTO findAll(String category, String name, int page, int size) { // 생성일자를 기준으로 내림차순 @@ -260,6 +243,7 @@ public RoadmapResponse.FindRoadmapByQueryDTO findAll(String category, String nam return new RoadmapResponse.FindRoadmapByQueryDTO(Category.getCategory(category), roadmapDTOS, hasNext); } + // 그룹 로드맵에 참여 신청하기 @Transactional public void applyGroupRoadmap(RoadmapRequest.ApplyRoadmapDTO requestDTO, Long id, User user){ Roadmap roadmap = getRoadmapById(id); From fa5423c3a3f079406fed7280dd7997635f0128a1 Mon Sep 17 00:00:00 2001 From: suuding Date: Thu, 9 Nov 2023 04:46:59 +0900 Subject: [PATCH 61/66] =?UTF-8?q?fix=20:=20step=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=8B=9C=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/step/StepService.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/example/tily/step/StepService.java b/src/main/java/com/example/tily/step/StepService.java index 54d6faaf..9b4a9294 100644 --- a/src/main/java/com/example/tily/step/StepService.java +++ b/src/main/java/com/example/tily/step/StepService.java @@ -51,6 +51,8 @@ public StepResponse.CreateStepDTO createStep(StepRequest.CreateStepDTO requestDT Step step = Step.builder() .roadmap(roadmap) .title(requestDTO.title()) + .description(requestDTO.description()) + .dueDate(requestDTO.dueDate()) .build(); // 개인 로드맵이므로 description, dueDate 는 null stepRepository.save(step); From 15c4f1833b19be1a7db3b5b44190f6a0adc34986 Mon Sep 17 00:00:00 2001 From: suuding Date: Thu, 9 Nov 2023 04:47:18 +0900 Subject: [PATCH 62/66] =?UTF-8?q?feat=20:=20=EC=86=8C=EC=85=9C=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=EC=97=90=EC=84=9C=20/api=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/tily/user/socialLogin/SocialLoginController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/example/tily/user/socialLogin/SocialLoginController.java b/src/main/java/com/example/tily/user/socialLogin/SocialLoginController.java index f8cfd4ed..53b6c1ec 100644 --- a/src/main/java/com/example/tily/user/socialLogin/SocialLoginController.java +++ b/src/main/java/com/example/tily/user/socialLogin/SocialLoginController.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @@ -12,6 +13,7 @@ @RestController @RequiredArgsConstructor +@RequestMapping("/api") public class SocialLoginController { private final KakaoLoginService kakaoLoginService; From 7a6dd84c180fd48e140614e572f9233049771066 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 08:18:25 +0900 Subject: [PATCH 63/66] =?UTF-8?q?fix:=20softDelete=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EB=AA=A8=EB=91=90=20JPQL=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/comment/CommentRepository.java | 4 ++++ src/main/java/com/example/tily/comment/CommentService.java | 2 +- src/main/java/com/example/tily/roadmap/RoadmapController.java | 2 +- src/main/java/com/example/tily/roadmap/RoadmapRepository.java | 4 ++++ src/main/java/com/example/tily/roadmap/RoadmapService.java | 2 +- .../java/com/example/tily/roadmap/relation/UserRoadmap.java | 2 +- src/main/java/com/example/tily/til/TilRepository.java | 4 ++++ src/main/java/com/example/tily/til/TilService.java | 2 +- 8 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/tily/comment/CommentRepository.java b/src/main/java/com/example/tily/comment/CommentRepository.java index cfc6e0aa..44a96fc5 100644 --- a/src/main/java/com/example/tily/comment/CommentRepository.java +++ b/src/main/java/com/example/tily/comment/CommentRepository.java @@ -12,6 +12,10 @@ public interface CommentRepository extends JpaRepository { @Query("select c from Comment c join fetch c.writer where c.til.id=:tilId") List findByTilId(@Param("tilId") Long tilId); + @Modifying + @Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.id = :commentId") + void softDeleteCommentById(Long commentId); + @Modifying @Query("update Comment c SET c.isDeleted = true WHERE c.isDeleted = false AND c.til.id = :tilId") void softDeleteCommentsByTilId(Long tilId); diff --git a/src/main/java/com/example/tily/comment/CommentService.java b/src/main/java/com/example/tily/comment/CommentService.java index 6036aee5..5763c3b1 100644 --- a/src/main/java/com/example/tily/comment/CommentService.java +++ b/src/main/java/com/example/tily/comment/CommentService.java @@ -76,6 +76,6 @@ public void deleteComment(Long id, User user) { throw new CustomException(ExceptionCode.COMMENT_DELETE_FORBIDDEN); alarmRepository.deleteByCommentId(id); - commentRepository.deleteById(id); // soft delete 적용됨 + commentRepository.softDeleteCommentById(id); } } diff --git a/src/main/java/com/example/tily/roadmap/RoadmapController.java b/src/main/java/com/example/tily/roadmap/RoadmapController.java index 86f467b7..381417fd 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapController.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapController.java @@ -48,7 +48,7 @@ public ResponseEntity findGroupRoadmap(@PathVariable Long id, @Authentication } // 그룹 로드맵 정보 수정하기 - @PostMapping("/roadmaps/{id}") + @PatchMapping("/roadmaps/{id}") public ResponseEntity updateGroupRoadmap(@RequestBody @Valid RoadmapRequest.UpdateGroupRoadmapDTO requestDTO, Errors errors, @PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ roadmapService.updateGroupRoadmap(id, requestDTO, userDetails.getUser()); diff --git a/src/main/java/com/example/tily/roadmap/RoadmapRepository.java b/src/main/java/com/example/tily/roadmap/RoadmapRepository.java index 297a0f52..c99e9d95 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapRepository.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapRepository.java @@ -25,6 +25,10 @@ public interface RoadmapRepository extends JpaRepository { Optional findByCode(String code); + @Modifying + @Query("update Roadmap r SET r.isDeleted = true WHERE r.isDeleted = false AND r.id = :roadmapId") + void softDeleteRoadmapById(Long roadmapId); + @Modifying @Query("update Roadmap r SET r.isDeleted = true WHERE r.isDeleted = false AND r.id IN :roadmapIds") void softDeleteRoadmapByRoadmapIds(List roadmapIds); diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index 7be9c26d..0f5ec537 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -477,7 +477,7 @@ public void deleteRoadmap(Long roadmapId, User user){ userRoadmapRepository.softDeleteUserRoadmapByRoadmapId(roadmapId); // 7. Roadmap을 삭제한다 - roadmapRepository.delete(roadmap); + roadmapRepository.softDeleteRoadmapById(roadmapId); } private static String generateRandomCode() { diff --git a/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java b/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java index e4ba4b51..baf1dc9b 100644 --- a/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java +++ b/src/main/java/com/example/tily/roadmap/relation/UserRoadmap.java @@ -16,7 +16,7 @@ @NoArgsConstructor(access = AccessLevel.PROTECTED) @Entity @Table(name="user_roadmap_tb") -@SQLDelete(sql = "UPDATE user_roadmap_tb SET isDeleted = true WHERE id = ?") +@SQLDelete(sql = "UPDATE user_roadmap_tb SET is_deleted = true WHERE id = ?") @Where(clause = "is_deleted = false") public class UserRoadmap extends BaseTimeEntity { @Id diff --git a/src/main/java/com/example/tily/til/TilRepository.java b/src/main/java/com/example/tily/til/TilRepository.java index 55d15409..96468f42 100644 --- a/src/main/java/com/example/tily/til/TilRepository.java +++ b/src/main/java/com/example/tily/til/TilRepository.java @@ -56,6 +56,10 @@ List findTilsByUserIdAndDateRange(@Param("userId") Long userId, Til findByRoadmapIdAndStepId(Long roadmapId, Long stepId); List findByRoadmapId(Long roadmapId); + + @Modifying + @Query("update Til t SET t.isDeleted = true WHERE t.isDeleted = false AND t.id = :tilId") + void softDeleteTilById(Long tilId); @Modifying @Query("update Til t SET t.isDeleted = true WHERE t.isDeleted = false AND t.id IN :tilIds") diff --git a/src/main/java/com/example/tily/til/TilService.java b/src/main/java/com/example/tily/til/TilService.java index 29f51985..620bfd87 100644 --- a/src/main/java/com/example/tily/til/TilService.java +++ b/src/main/java/com/example/tily/til/TilService.java @@ -158,7 +158,7 @@ public void deleteTil(Long tilId, User user) { commentRepository.softDeleteCommentsByTilId(tilId); // 2. Til을 삭제한다. - tilRepository.deleteById(tilId); + tilRepository.softDeleteTilById(tilId); } // 나의 til 목록 전체 조회하기 From 20996c186d9353b26cd163b53c76731a0b697e39 Mon Sep 17 00:00:00 2001 From: suuding Date: Thu, 9 Nov 2023 12:47:52 +0900 Subject: [PATCH 64/66] =?UTF-8?q?fix=20:=20gmail=20smtp=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=82=AC=EC=9A=A9=EC=95=88=ED=95=A8=20(=ED=81=AC?= =?UTF-8?q?=EB=9E=A8=ED=8F=B4=EB=A6=B0=EC=97=90=EC=84=9C=20=EC=95=88?= =?UTF-8?q?=EB=90=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/user/UserService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/tily/user/UserService.java b/src/main/java/com/example/tily/user/UserService.java index 3db16bae..25b1b44b 100644 --- a/src/main/java/com/example/tily/user/UserService.java +++ b/src/main/java/com/example/tily/user/UserService.java @@ -54,14 +54,14 @@ public class UserService { @Transactional public void checkEmail(UserRequest.CheckEmailDTO requestDTO) { checkEmail(requestDTO.email()); - sendCode(requestDTO.email()); + //sendCode(requestDTO.email()); } // 인증코드 전송 @Transactional public void sendEmailCode(UserRequest.SendEmailCodeDTO requestDTO) { findByEmail(requestDTO.email()); - sendCode(requestDTO.email()); + //sendCode(requestDTO.email()); } // 인증코드 확인 From 57c5a1b86695f4d89ea96f82e043243d02887bb5 Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 13:52:29 +0900 Subject: [PATCH 65/66] =?UTF-8?q?fix:=20findGroupRoadmap=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tily/roadmap/RoadmapController.java | 6 ++++- .../example/tily/roadmap/RoadmapService.java | 27 +++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/example/tily/roadmap/RoadmapController.java b/src/main/java/com/example/tily/roadmap/RoadmapController.java index 033df548..39ce9c9c 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapController.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapController.java @@ -2,6 +2,7 @@ import com.example.tily._core.security.CustomUserDetails; import com.example.tily._core.utils.ApiUtils; +import com.example.tily.user.User; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; @@ -9,6 +10,7 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; +import java.util.Optional; @RestController @RequiredArgsConstructor @@ -35,7 +37,9 @@ public ResponseEntity createTilyRoadmap(@RequestBody @Valid RoadmapRequest.Cr // 틸리, 그룹 로드맵 정보 조회하기 @GetMapping("/roadmaps/{id}") public ResponseEntity findGroupRoadmap(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ - RoadmapResponse.FindGroupRoadmapDTO responseDTO = roadmapService.findGroupRoadmap(id, userDetails.getUser()); + User user = Optional.ofNullable(userDetails).map(CustomUserDetails::getUser).orElse(null); + RoadmapResponse.FindGroupRoadmapDTO responseDTO = roadmapService.findGroupRoadmap(id, user); + return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); } diff --git a/src/main/java/com/example/tily/roadmap/RoadmapService.java b/src/main/java/com/example/tily/roadmap/RoadmapService.java index 921b572f..f3b02231 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapService.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapService.java @@ -174,20 +174,19 @@ else if(reference.getCategory().equals("web")){ .map(RoadmapResponse.ReferenceDTOs.ReferenceDTO::new).collect(Collectors.toList()))) .collect(Collectors.toList()); - Optional userRoadmap = userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(id, user.getId()); - String myRole; - Long recentTilId; - Long recentStepId; - - if (userRoadmap.isPresent()) { - myRole = userRoadmap.get().getRole(); - List tils = tilRepository.findByUserIdByOrderByUpdatedDateDesc(id, user.getId()); - recentTilId = !tils.isEmpty() ? tils.get(0).getId() : null; - recentStepId = !tils.isEmpty() ? tils.get(0).getStep().getId() : null; - } else { - myRole = "none"; - recentTilId = null; - recentStepId = null; + String myRole = "none"; + Long recentTilId = null; + Long recentStepId = null; + + if(user != null){ + Optional userRoadmap = userRoadmapRepository.findByRoadmapIdAndUserIdAndIsAcceptTrue(id, user.getId()); + + if (userRoadmap.isPresent()) { + myRole = userRoadmap.get().getRole(); + List tils = tilRepository.findByUserIdByOrderByUpdatedDateDesc(id, user.getId()); + recentTilId = !tils.isEmpty() ? tils.get(0).getId() : null; + recentStepId = !tils.isEmpty() ? tils.get(0).getStep().getId() : null; + } } return new RoadmapResponse.FindGroupRoadmapDTO(roadmap, steps, roadmap.getCreator(), recentTilId, recentStepId, myRole); From 4bf58f844c996825d126d810fe467dfd2ca5e48d Mon Sep 17 00:00:00 2001 From: hoyaii <131665728+hoyaii@users.noreply.github.com> Date: Thu, 9 Nov 2023 13:53:14 +0900 Subject: [PATCH 66/66] =?UTF-8?q?fix:=20findGroupRoadmap=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A3=B0=EB=9F=AC=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/tily/roadmap/RoadmapController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/tily/roadmap/RoadmapController.java b/src/main/java/com/example/tily/roadmap/RoadmapController.java index 39ce9c9c..37b60627 100644 --- a/src/main/java/com/example/tily/roadmap/RoadmapController.java +++ b/src/main/java/com/example/tily/roadmap/RoadmapController.java @@ -39,7 +39,7 @@ public ResponseEntity createTilyRoadmap(@RequestBody @Valid RoadmapRequest.Cr public ResponseEntity findGroupRoadmap(@PathVariable Long id, @AuthenticationPrincipal CustomUserDetails userDetails){ User user = Optional.ofNullable(userDetails).map(CustomUserDetails::getUser).orElse(null); RoadmapResponse.FindGroupRoadmapDTO responseDTO = roadmapService.findGroupRoadmap(id, user); - + return ResponseEntity.ok().body(ApiUtils.success(responseDTO)); }