From 3a5f5f52ed617065cacd2a7fc61ce059469280c9 Mon Sep 17 00:00:00 2001 From: gabang2 Date: Sun, 24 Sep 2023 21:07:56 +0900 Subject: [PATCH 1/9] =?UTF-8?q?fix=20:=20generated=EC=97=90=EB=9F=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dopamine | Bin 2733 -> 0 bytes .../dopamine/backend/BackendApplication.java | 9 +++- .../controller/LevelBackofficeController.java | 45 +++++++++++++++++- .../domain/common/entity/BaseEntity.java | 2 +- .../feed/controller/FeedController.java | 4 -- .../repository/FeedCustomRepositoryImpl.java | 12 +++-- .../feed/repository/FeedRepository.java | 5 +- .../domain/feed/service/FeedService.java | 5 +- .../domain/level/service/LevelService.java | 25 +++++++++- .../member/controller/MemberController.java | 2 +- .../backend/global/config/CorsFilter.java | 4 +- src/main/resources/application.yml | 16 +++---- src/main/resources/keystore.p12 | 0 src/main/resources/keystorelocal.p12 | 0 .../templates/level/levelUpdate.html | 36 ++++++++++++++ 15 files changed, 134 insertions(+), 31 deletions(-) delete mode 100644 dopamine create mode 100644 src/main/resources/keystore.p12 create mode 100644 src/main/resources/keystorelocal.p12 create mode 100644 src/main/resources/templates/level/levelUpdate.html diff --git a/dopamine b/dopamine deleted file mode 100644 index e4fa4247a287474388e9812d75ff4a8b9b6d3cc5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2733 zcma)+c{J1u8^>p7Xlm@Lv1Kd54}%c~k;alG+Yq`$c8QC!H`c+}4MK*okI0_vYxZd& zw;~~uY*{1s_IA$uo_o*x*ZcnQoaa2B@Av!s`2|R9l@Kr#Ah9_ikW#UP*aH-p1xzEc znZrnICcm&DK!Vr*mjtK7Nbtg6IPceFBiR3wI>82p&`5BtUr-&m{dWS60&D=>Kj#TR z8piz=w@r+Q6`w!qxqfjN=$qd;i!XsdB+(GCFmM9F`tOerBpd_?AdtVs62LA{7+4C1 zu4F2_9p;?VG*Mi!pk4o}$RlsIoWBU!ujGCHqDsd?@= zD%wa4?v}*KuEG=aiu}!)G-8Y`y+BT^LF=x5?UoVTO-*`bNw3=5%mj2&ABn$#6;wYQ zJ+uCLtf7gLpj#fbDjFn0JpJJb`W;#PmFwvwy1(1d_h{h3XTlRENrNoY^ z%}~V+UjLtronX(ng$#XcAUjVK`2C9ix_6{}DB@udbBKj_yvinfWH= zV|UHM?itrl_ni_$s;>cGsz3wAA;8dY5Br?Q|1RrN=tw8Sh1N{XXp5jO=%4 zi`)K0e>AKqX^omV_qdf}f@+%H=U<2;+w=8p2$;R%PfYglDd}8};|$>N>`@M?zA0f- z3yhadZ5i=<|Ix9fxH;uh4)wOrdC!>hB$kH8hdAa;cld>~``O+KGHDR9K%N$auVOG4 zkRB$=o?EjmF-{Umn#%c^-_Q17w6t$;VY3ZZ#JBpw9%*s5Y61*Wxf6~)KP1rKvJ$0B zknc=qS>SHpJe**=LiH#jlnULSqgRIC*TMV%9YziMN#aDF^5(p>Hh*taW-IVNGYL)p&rrPiJE(uo66DzD4QTxee_be{6fy(s?+b%Cc#*++tA zd_AH{AhC_x51+FKkIQP=_v^bNtIpeXy{4j><$7SKi*~3yO=L`14Ek;^H^eUVRo9b&lho~EH7p3 z`>WK&`}k1PT>piE7fTAV*JJda{Py~&v*Bxo&)wO}NKJ;ohxA(tfi2xhZq^ZmJ0-?p z_HJPFh8G5T{(f$>YV$z|qyJX&Dg4Y<a6AZO4WkT1v)a$B?Wn` zih>djPzFe_w7*R(2pS1S`h~(FV9>7>^p67mUsbJs%gl02NU~nnxYJ#tmqjM}85`>V zscI*53W3AaEIj#)BLA)+>V6~%28xad0ykwjuqDO?JYURSLlsDE-jkn>=8>)-v3(My zJ}GDq+1hLTUaEV|w-Y2nQ>APy1`AnSX04`Wycab3BZzZVVX z&PI|+5?O#e@S0lIQi(q=@WM+cS0hzAK7IVI^+h5tblw~jW0wB=lql|9Yu3ae!Z${L zbfYemd0LFEUbQ~|jTRT3i$&Ih;N1Q&3bXQ3NgPYmGOQ9le%MaQy`r7|)~#z;>iy7f z0YaVTV=8Sr0%uql&_{K``76n9dxiP~NR2u3SIls{289ySZ9(bylcw=&68e*h(~Ra( zD={^`0piFg|K1J0Wx6L|j@KP45M@74BDP7a-_k|@KGiAxBCr(aZt$ie&( z9>vk({2v<9N_6Mx^Enz)~a9qC_xd!goGo%J~KJU1vOvx{79`}OnmpS_W)_Nyw+^RZVFp0DhtwsPTZ z&i4ddwTbbT418!XS_mC5S^I+{G2IJqyqXr>wH7*Nx4iwsxxso%p@Z+Oi<(V!MTFAF z7}sld=d!A_`s6+%hTB_7i^($q2Tk8(vIlVO&PCRV?5B=0vh=Z~6s84;n0P?QJs0BK zy9sn-c!ixO9HcK^a-fbk+0QA_W2I1Kx^hozk?VCSKk)RE%*|lC`W#^;^>J}!@4+}n zq_|I`Gl;(lHZaFV6m ztnnQ|wiffN`=bqz{2D4>mx@t*h{7bppkc3eui|GkrT&J^SCzIBW getFeedListOrderByDate(int page) { return jpaQueryFactory.selectFrom(feed) - .where(feed.fulfillYn.eq(true)) + .where(feed.fulfillYn.eq(true), + feed.delYn.ne(true)) .orderBy(feed.createdDate.desc()) .limit(9) .offset((long) (page - 1) * PAGEOFFSET) @@ -47,7 +48,8 @@ public List getFeedListOrderByLikeCount(int page) { return jpaQueryFactory.selectFrom(feed) .where(feed.createdDate.after(dayOffset), - feed.fulfillYn.eq(true)) + feed.fulfillYn.eq(true), + feed.delYn.ne(true)) .orderBy(feed.likeCount.desc()) .limit(9) .offset((long) (page - 1) * PAGEOFFSET) @@ -66,7 +68,8 @@ public List getFeedListByChallengeOrderByLikeCount(Challenge challenge) { return jpaQueryFactory.selectFrom(feed) .where(feed.createdDate.after(dayOffset), feed.challenge.eq(challenge), - feed.fulfillYn.eq(true)) + feed.fulfillYn.eq(true), + feed.delYn.ne(true)) .orderBy(feed.likeCount.desc()) .limit(6) .fetch(); @@ -81,7 +84,8 @@ public List getFeedListByChallengeOrderByLikeCount(Challenge challenge) { public List getFeedListByMemberOrderByDate(int page, Member member) { return jpaQueryFactory.selectFrom(feed) .where(feed.member.eq(member), - feed.fulfillYn.eq(true)) + feed.fulfillYn.eq(true), + feed.delYn.ne(true)) .orderBy(feed.createdDate.desc()) .limit(9) .offset((long) (page - 1) * PAGEOFFSET) diff --git a/src/main/java/dopamine/backend/domain/feed/repository/FeedRepository.java b/src/main/java/dopamine/backend/domain/feed/repository/FeedRepository.java index 73292ed..75e4678 100644 --- a/src/main/java/dopamine/backend/domain/feed/repository/FeedRepository.java +++ b/src/main/java/dopamine/backend/domain/feed/repository/FeedRepository.java @@ -9,8 +9,7 @@ import java.util.Optional; public interface FeedRepository extends JpaRepository { - Optional findFeedByContent(String content); - List findFeedByMember(Member member); + List findFeedByMemberAndDelYn(Member member, Boolean delYn); - public List findFeedByMemberAndCreatedDateBetweenOrderByCreatedDate(Member member, LocalDateTime startDate, LocalDateTime finishDate); + public List findFeedByMemberAndDelYnAndCreatedDateBetweenOrderByCreatedDate(Member member, Boolean delYn, LocalDateTime startDate, LocalDateTime finishDate); } diff --git a/src/main/java/dopamine/backend/domain/feed/service/FeedService.java b/src/main/java/dopamine/backend/domain/feed/service/FeedService.java index dd6b179..173e45f 100644 --- a/src/main/java/dopamine/backend/domain/feed/service/FeedService.java +++ b/src/main/java/dopamine/backend/domain/feed/service/FeedService.java @@ -72,6 +72,7 @@ public FeedResponseDTO getFeed(Member member, Long feedId) { Feed feed = verifiedFeed(feedId); if (!feed.getFulfillYn()) throw new BusinessLogicException(ExceptionCode.FEED_FULFILL_NOT_VALID); + if (feed.getDelYn()) throw new BusinessLogicException(ExceptionCode.DELETE_FEED_NOT_FOUND); Challenge challenge = feed.getChallenge(); MemberResponseDto memberResponseDto = memberMapper.memberToMemberResponseDto(feed.getMember()); @@ -228,7 +229,7 @@ public List feedListByMemberAndMonth(Member member, String mont LocalDateTime startDate = date.withDayOfMonth(1).atStartOfDay(); LocalDateTime finishDate = date.withDayOfMonth(date.lengthOfMonth()).atTime(LocalTime.MAX); - List findListByMemberAndDate = feedRepository.findFeedByMemberAndCreatedDateBetweenOrderByCreatedDate(member, startDate, finishDate); + List findListByMemberAndDate = feedRepository.findFeedByMemberAndDelYnAndCreatedDateBetweenOrderByCreatedDate(member, false, startDate, finishDate); return getFeedResponseDTOS(member, findListByMemberAndDate); } @@ -255,7 +256,7 @@ public List feedListByMemberAndYear(Member member, List members = memberRepository.findAllByLevel(level); + for(Member member : members) { + member.changeMember(null, null, null, 0, findLevelByLevelNum(1)); + } levelRepository.delete(level); orderLevelNum(); + allMemberLevelChange(); } /** @@ -87,6 +98,9 @@ public LevelResponseDto editLevel(Long levelId, LevelEditDto levelEditDto) { if(levelEditDto.getExp() != 0) verifiedExp(level.getLevelNum(), levelEditDto.getExp()); level.changeLevel(level.getLevelNum(), levelEditDto.getName(), levelEditDto.getBadge(), levelEditDto.getExp()); + // 모든 멤버에 레벨 반영 + allMemberLevelChange(); + // level -> responseDto LevelResponseDto levelResponseDto = levelMapper.levelToLevelResponseDto(level); return levelResponseDto; @@ -102,7 +116,7 @@ public Level verifiedLevel(Long levelId) { return level.orElseThrow(() -> new BusinessLogicException(ExceptionCode.LEVEL_NOT_FOUND)); } - public Level findMemberByLevelNum(int levelNum) { + public Level findLevelByLevelNum(int levelNum) { Optional level = levelRepository.findLevelByLevelNum(levelNum); return level.orElseThrow(() -> new BusinessLogicException(ExceptionCode.LEVEL_NOT_FOUND)); } @@ -141,7 +155,6 @@ public void verifiedExp(int levelNum, int exp) { public void orderLevelNum() { List levels = levelRepository.findAllByOrderByLevelNumAsc(); for (int i=0; i < levels.size() ; i++) { - System.out.println(levels.get(i).getLevelId()); levels.get(i).changeLevel(i+1, null, null, 0); } } @@ -161,5 +174,13 @@ public LevelDetailResponseDto memberDetailLevel(Member member) { .expPercent(expPercent).build(); } + // Level 변경시 모든 멤버의 레벨에 반영 + private void allMemberLevelChange(){ + List members = memberRepository.findAll(); + for (Member member : members) { + Level level = memberService.getMemberLevel(member.getExp()); + member.changeMember(null, null, null, 0, level); + } + } } diff --git a/src/main/java/dopamine/backend/domain/member/controller/MemberController.java b/src/main/java/dopamine/backend/domain/member/controller/MemberController.java index c8e6123..515c19e 100644 --- a/src/main/java/dopamine/backend/domain/member/controller/MemberController.java +++ b/src/main/java/dopamine/backend/domain/member/controller/MemberController.java @@ -60,7 +60,7 @@ public ResponseEntity getMember(@RequestHeader("Authorization") String accessTok LevelDetailResponseDto levelDetailResponseDto = levelService.memberDetailLevel(member); - int successCnt = feedRepository.findFeedByMember(member).size(); // todo : fullfillyn default값 추가되면 수정해야함 + int successCnt = feedRepository.findFeedByMemberAndDelYn(member, false).size(); // todo : fullfillyn default값 추가되면 수정해야함 MemberDetailResponseDto response = MemberDetailResponseDto.builder() .memberId(member.getMemberId()) diff --git a/src/main/java/dopamine/backend/global/config/CorsFilter.java b/src/main/java/dopamine/backend/global/config/CorsFilter.java index daad584..9189ae7 100644 --- a/src/main/java/dopamine/backend/global/config/CorsFilter.java +++ b/src/main/java/dopamine/backend/global/config/CorsFilter.java @@ -1,7 +1,5 @@ package dopamine.backend.global.config; -import lombok.AllArgsConstructor; -import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.stereotype.Component; @@ -31,6 +29,8 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization"); + response.setHeader("Content-Type", "application/json"); + response.setHeader("Accept", "application/json"); if("OPTIONS".equalsIgnoreCase(request.getMethod())) { response.setStatus(HttpServletResponse.SC_OK); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index e0e015d..e649caf 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,16 +1,17 @@ server: - port: 9000 + port: 443 error: include-exception: true # 응답에 exception의 내용을 포함할지 여부 path: '/error' # 응답을 처리할 Handler의 경로 whitelabel: enabled: true # 서버 오류 발생시 브라우저에 보여줄 기본 페이지 생성 여부 # include-message: always -# ssl: -# key-store: dopamine -# key-store-type: PKCS12 -# key-password: dopamine -# key-alias: dopamine + ssl: + key-store: ${DOPAMINE_KEYSTORE} + key-store-type: PKCS12 + key-alias: ${DOPAMINE_KEY_ALIAS} + key-store-password: admin1234 + enabled: true spring: @@ -33,7 +34,7 @@ spring: database: mysql show-sql: false hibernate: - ddl-auto: update + ddl-auto: none properties: hibernate: format_sql: false @@ -53,7 +54,6 @@ jwt: secret: ${DOPAMINE_JWT_SECRET} kakao: client_id: ${DOPAMINE_KAKAO_CLIENT_ID} - redirect_url: ${DOPAMINE_KAKAO_REDIRECT_URL} cloud: aws: diff --git a/src/main/resources/keystore.p12 b/src/main/resources/keystore.p12 new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/keystorelocal.p12 b/src/main/resources/keystorelocal.p12 new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/templates/level/levelUpdate.html b/src/main/resources/templates/level/levelUpdate.html new file mode 100644 index 0000000..e9f3d9a --- /dev/null +++ b/src/main/resources/templates/level/levelUpdate.html @@ -0,0 +1,36 @@ + + + + + + + + + + + + +
+
+

레벨 생성

+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+ \ No newline at end of file From 20ec16ff996129553434414a3b12f58db642a0ff Mon Sep 17 00:00:00 2001 From: gabang2 Date: Wed, 4 Oct 2023 18:33:34 +0900 Subject: [PATCH 2/9] =?UTF-8?q?refactor=20:=20=EC=95=88=EC=93=B0=EB=8A=94?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dopamine/backend/backoffice/form/LevelForm.java | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 src/main/java/dopamine/backend/backoffice/form/LevelForm.java diff --git a/src/main/java/dopamine/backend/backoffice/form/LevelForm.java b/src/main/java/dopamine/backend/backoffice/form/LevelForm.java deleted file mode 100644 index ab7fe0e..0000000 --- a/src/main/java/dopamine/backend/backoffice/form/LevelForm.java +++ /dev/null @@ -1,9 +0,0 @@ -package dopamine.backend.backoffice.form; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class LevelForm { -} From 995943ad09ea843a055eae8401054ba878eec1ba Mon Sep 17 00:00:00 2001 From: gabang2 Date: Wed, 4 Oct 2023 20:01:54 +0900 Subject: [PATCH 3/9] =?UTF-8?q?refactor=20#65=20:=20LevelService=20?= =?UTF-8?q?=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 --- .../backend/domain/level/entity/Level.java | 4 + .../domain/level/service/LevelService.java | 95 ++++++++++++------- .../member/controller/MemberController.java | 2 +- .../backend/domain/member/entity/Member.java | 2 +- .../global/exception/ExceptionCode.java | 2 +- 5 files changed, 70 insertions(+), 35 deletions(-) diff --git a/src/main/java/dopamine/backend/domain/level/entity/Level.java b/src/main/java/dopamine/backend/domain/level/entity/Level.java index c2e5ab6..3e25a05 100644 --- a/src/main/java/dopamine/backend/domain/level/entity/Level.java +++ b/src/main/java/dopamine/backend/domain/level/entity/Level.java @@ -49,4 +49,8 @@ public void changeLevel(int levelNum, String name, String badge, int exp) { this.exp = (exp != 0) ? exp : this.exp; } + public void changeLevelNum(int levelNum) { + this.levelNum = (levelNum != 0) ? levelNum : this.levelNum; + } + } diff --git a/src/main/java/dopamine/backend/domain/level/service/LevelService.java b/src/main/java/dopamine/backend/domain/level/service/LevelService.java index 435c487..8217259 100644 --- a/src/main/java/dopamine/backend/domain/level/service/LevelService.java +++ b/src/main/java/dopamine/backend/domain/level/service/LevelService.java @@ -23,13 +23,11 @@ @Service @RequiredArgsConstructor @Transactional -@Slf4j public class LevelService { private final LevelRepository levelRepository; private final LevelMapper levelMapper; private final MemberRepository memberRepository; - private final MemberService memberService; public static int INF = 1000000000; @@ -40,7 +38,10 @@ public class LevelService { */ public Level createLevel(LevelRequestDto levelRequestDto) { + // levelNum : 하나씩 증가하도록 int levelNum = createLevelNum(); + + // 이전 레벨보다 작거나, 다음 레벨보다 큰지 검증 verifiedExp(levelNum, levelRequestDto.getExp()); // create @@ -62,13 +63,20 @@ public Level createLevel(LevelRequestDto levelRequestDto) { * @param levelId */ public void deleteLevel(Long levelId) { + + // 레벨 찾기 Level level = verifiedLevel(levelId); - List members = memberRepository.findAllByLevel(level); - for(Member member : members) { - member.changeMember(null, null, null, 0, findLevelByLevelNum(1)); - } + Level levelOne = findLevelByLevelNum(1); + + // 1레벨 삭제 불가(모든 회원의 default) + if (level == levelOne) throw new BusinessLogicException(ExceptionCode.LEVEL_1_CANNOT_DELETE); + + // 레벨에 포함된 회원을 1레벨로 변경 후 삭제 + level.getMembers().forEach(member -> member.setLevel(levelOne)); levelRepository.delete(level); - orderLevelNum(); + + // levelNum 정렬 & 관련 멤버의 레벨 변경 + sortLevelNum(); allMemberLevelChange(); } @@ -85,6 +93,27 @@ public LevelResponseDto getLevel(Long levelId) { return levelResponseDto; } + /** + * GET : 레벨 디테일하게 조회 + * @param member + * @return + */ + @Transactional(readOnly = true) + public LevelDetailResponseDto getMemberDetailLevel(Member member) { + int expRange = levelRepository.findLevelByLevelNum(member.getLevel().getLevelNum() + 1).map(Level::getExp).orElse(INF) - member.getLevel().getExp(); + int expMember = levelRepository.findLevelByLevelNum(member.getLevel().getLevelNum() + 1).map(Level::getExp).orElse(INF) - member.getExp() - 1; + int expPercent = (int)Math.round((double) expMember/expRange * 100); + + return LevelDetailResponseDto.builder() + .levelId(member.getLevel().getLevelId()) + .levelNum(member.getLevel().getLevelNum()) + .name(member.getLevel().getName()) + .badge(member.getLevel().getBadge()) + .expRange(expRange) + .expMember(expMember) + .expPercent(expPercent).build(); + } + /** * UPDATE : 수정 (name, exp, badge설정 가능) * @@ -107,15 +136,22 @@ public LevelResponseDto editLevel(Long levelId, LevelEditDto levelEditDto) { } /** - * 검증 -> levelId 입력하면 관련 ChallengeMember Entity가 있는지 확인 + * 검증 -> levelId 입력하면 관련 Level Entity가 있는지 확인 * @param levelId * @return level */ + @Transactional(readOnly = true) public Level verifiedLevel(Long levelId) { Optional level = levelRepository.findById(levelId); return level.orElseThrow(() -> new BusinessLogicException(ExceptionCode.LEVEL_NOT_FOUND)); } + /** + * levelNum을 기준으로 Level Entity 찾기 + * @param levelNum + * @return Level + */ + @Transactional(readOnly = true) public Level findLevelByLevelNum(int levelNum) { Optional level = levelRepository.findLevelByLevelNum(levelNum); return level.orElseThrow(() -> new BusinessLogicException(ExceptionCode.LEVEL_NOT_FOUND)); @@ -124,6 +160,7 @@ public Level findLevelByLevelNum(int levelNum) { /** * DB에서 가장 큰 levelNum 조회 + 1 (순차적으로) */ + @Transactional(readOnly = true) public int createLevelNum(){ return levelRepository.findTopByOrderByLevelNumDesc() .map(level -> level.getLevelNum() + 1) @@ -135,6 +172,7 @@ public int createLevelNum(){ * @param levelNum * @param exp */ + @Transactional(readOnly = true) public void verifiedExp(int levelNum, int exp) { // 이전 기준 경험치보다 큰지 검증 int preExp = levelRepository.findLevelByLevelNum(levelNum - 1).map(Level::getExp).orElse(-1); @@ -152,35 +190,28 @@ public void verifiedExp(int levelNum, int exp) { /** * levelNum연속으로 이어지도록 설정(삭제시 levelNum한칸씩 앞으로) */ - public void orderLevelNum() { - List levels = levelRepository.findAllByOrderByLevelNumAsc(); - for (int i=0; i < levels.size() ; i++) { - levels.get(i).changeLevel(i+1, null, null, 0); + private void sortLevelNum() { + int levelNum = 0; + for (Level level : levelRepository.findAllByOrderByLevelNumAsc()) { + level.changeLevelNum(++levelNum); } } - public LevelDetailResponseDto memberDetailLevel(Member member) { - int expRange = levelRepository.findLevelByLevelNum(member.getLevel().getLevelNum() + 1).map(Level::getExp).orElse(INF) - member.getLevel().getExp(); - int expMember = levelRepository.findLevelByLevelNum(member.getLevel().getLevelNum() + 1).map(Level::getExp).orElse(INF) - member.getExp() - 1; - int expPercent = (int)Math.round((double) expMember/expRange * 100); - - return LevelDetailResponseDto.builder() - .levelId(member.getLevel().getLevelId()) - .levelNum(member.getLevel().getLevelNum()) - .name(member.getLevel().getName()) - .badge(member.getLevel().getBadge()) - .expRange(expRange) - .expMember(expMember) - .expPercent(expPercent).build(); + /** + * Level 변경시 모든 멤버의 레벨에 반영 + */ + private void allMemberLevelChange(){ + memberRepository.findAll().forEach(member -> member.setLevel(getMemberLevel(member.getExp()))); } - // Level 변경시 모든 멤버의 레벨에 반영 - private void allMemberLevelChange(){ - List members = memberRepository.findAll(); - for (Member member : members) { - Level level = memberService.getMemberLevel(member.getExp()); - member.changeMember(null, null, null, 0, level); - } + /** + * 경험치에 속하는 Level 반환 + * @param exp + * @return Level + */ + @Transactional(readOnly = true) + public Level getMemberLevel(int exp) { + return levelRepository.findTopByExpLessThanEqualOrderByExpDesc(exp); } } diff --git a/src/main/java/dopamine/backend/domain/member/controller/MemberController.java b/src/main/java/dopamine/backend/domain/member/controller/MemberController.java index 515c19e..caf8119 100644 --- a/src/main/java/dopamine/backend/domain/member/controller/MemberController.java +++ b/src/main/java/dopamine/backend/domain/member/controller/MemberController.java @@ -58,7 +58,7 @@ public ResponseEntity getMember(@RequestHeader("Authorization") String accessTok Member member = jwtService.getMemberFromAccessToken(accessToken); // member 찾기 - LevelDetailResponseDto levelDetailResponseDto = levelService.memberDetailLevel(member); + LevelDetailResponseDto levelDetailResponseDto = levelService.getMemberDetailLevel(member); int successCnt = feedRepository.findFeedByMemberAndDelYn(member, false).size(); // todo : fullfillyn default값 추가되면 수정해야함 diff --git a/src/main/java/dopamine/backend/domain/member/entity/Member.java b/src/main/java/dopamine/backend/domain/member/entity/Member.java index d21b448..49670a9 100644 --- a/src/main/java/dopamine/backend/domain/member/entity/Member.java +++ b/src/main/java/dopamine/backend/domain/member/entity/Member.java @@ -85,7 +85,7 @@ public void changeMember(String kakaoId, String nickname, String refreshToken, i } // == 연관관계 편의 메소드 == // - private void setLevel(Level level) { + public void setLevel(Level level) { if (this.level != null) { if (this.level.getMembers().contains(this)) { this.level.getMembers().remove(this); diff --git a/src/main/java/dopamine/backend/global/exception/ExceptionCode.java b/src/main/java/dopamine/backend/global/exception/ExceptionCode.java index 6702939..fa3895f 100644 --- a/src/main/java/dopamine/backend/global/exception/ExceptionCode.java +++ b/src/main/java/dopamine/backend/global/exception/ExceptionCode.java @@ -16,7 +16,7 @@ public enum ExceptionCode { MISSING_YEAR_REQUEST_PARAM(400, "필수 파라미터(year)를 작성해야 합니다."), MISSING_REDIRECT_REQUEST_PARAM(400, "필수 파라미터(redirect_url)를 작성해야 합니다."), CHALLENGE_ALREADY_CERTIFIED(400, "이미 완료한 챌린지입니다."), - + LEVEL_1_CANNOT_DELETE(400, "1레벨은 삭제할 수 없습니다."), EXP_MIN_NOT_VALID(400, "레벨 경험치는 이전 레벨보다 높은 기준으로 설정해주세요."), EXP_MAX_NOT_VALID(400, "레벨 경험치는 이후 레벨보다 낮은 기준으로 설정해주세요."), LOGOUT_MEMBER(400, "이미 로그아웃한 유저입니다."), From 42c6a4cb3dfcd0e396308bfd4e389e5c4666ceb9 Mon Sep 17 00:00:00 2001 From: gabang2 Date: Wed, 4 Oct 2023 21:05:15 +0900 Subject: [PATCH 4/9] =?UTF-8?q?refactor=20#65=20:=20ImageService=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20-=20=EA=B4=80=EB=A0=A8?= =?UTF-8?q?=20=EC=BD=94=EB=93=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ChallengeBackofficeController.java | 9 +++------ .../backoffice/controller/LevelBackofficeController.java | 9 +++------ .../domain/challenge/controller/ChallengeController.java | 9 +++------ .../backend/domain/level/controller/LevelController.java | 8 ++------ .../dopamine/backend/global/s3/service/ImageService.java | 2 ++ 5 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/main/java/dopamine/backend/backoffice/controller/ChallengeBackofficeController.java b/src/main/java/dopamine/backend/backoffice/controller/ChallengeBackofficeController.java index 1913aab..12f0f69 100644 --- a/src/main/java/dopamine/backend/backoffice/controller/ChallengeBackofficeController.java +++ b/src/main/java/dopamine/backend/backoffice/controller/ChallengeBackofficeController.java @@ -59,9 +59,7 @@ public String createForm(Model model){ public String createChallenge(ChallengeRequestDTO challengeRequestDTO, @RequestPart(value = "file", required = false) MultipartFile file){ - if(!file.isEmpty()){ - challengeRequestDTO.setImage(imageService.updateImage(file, "challenge", "image")); - } + challengeRequestDTO.setImage(imageService.updateImage(file, "challenge", "image")); challengeService.createChallenge(challengeRequestDTO); return "redirect:/backoffice/challenge"; @@ -104,9 +102,8 @@ public String editLevel(@PathVariable("challengeId") Long challengeId, ChallengeEditDTO challengeEditDTO, @RequestPart("file") MultipartFile file) { // 이미지 업로드 - if (!file.isEmpty()) { - challengeEditDTO.setImage(imageService.updateImage(file, "level", "badge")); - } + challengeEditDTO.setImage(imageService.updateImage(file, "level", "badge")); + // 레벨 수정 challengeService.editChallenge(challengeId, challengeEditDTO); return "redirect:/backoffice/challenge"; diff --git a/src/main/java/dopamine/backend/backoffice/controller/LevelBackofficeController.java b/src/main/java/dopamine/backend/backoffice/controller/LevelBackofficeController.java index 4fd4860..c49e390 100644 --- a/src/main/java/dopamine/backend/backoffice/controller/LevelBackofficeController.java +++ b/src/main/java/dopamine/backend/backoffice/controller/LevelBackofficeController.java @@ -78,9 +78,8 @@ public String editLevel(@PathVariable("levelId") Long levelId, LevelEditDto levelEditDto, @RequestPart("file") MultipartFile file) { // 이미지 업로드 - if (!file.isEmpty()) { - levelEditDto.setBadge(imageService.updateImage(file, "level", "badge")); - } + levelEditDto.setBadge(imageService.updateImage(file, "level", "badge")); + // 레벨 수정 levelService.editLevel(levelId, levelEditDto); return "redirect:/backoffice/level"; @@ -110,9 +109,7 @@ public String levelCreate(Model model) { public String levelCreate(LevelRequestDto levelRequestDto, @RequestPart("file") MultipartFile file) { // 이미지 업로드 - if (!file.isEmpty()) { - levelRequestDto.setBadge(imageService.updateImage(file, "level", "badge")); - } + levelRequestDto.setBadge(imageService.updateImage(file, "level", "badge")); // 레벨 생성 Level level = levelService.createLevel(levelRequestDto); diff --git a/src/main/java/dopamine/backend/domain/challenge/controller/ChallengeController.java b/src/main/java/dopamine/backend/domain/challenge/controller/ChallengeController.java index e1812fa..6bbb029 100644 --- a/src/main/java/dopamine/backend/domain/challenge/controller/ChallengeController.java +++ b/src/main/java/dopamine/backend/domain/challenge/controller/ChallengeController.java @@ -31,9 +31,7 @@ public class ChallengeController { @PostMapping(value = "/challenges", consumes={MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) public void createChallenge(@Valid @RequestPart(value = "request") ChallengeRequestDTO challengeRequestDTO, @RequestPart(value = "image", required = false) MultipartFile file){ - if(file != null){ - challengeRequestDTO.setImage(imageService.updateImage(file, "challenge", "image")); - } + challengeRequestDTO.setImage(imageService.updateImage(file, "challenge", "image")); challengeService.createChallenge(challengeRequestDTO); } @@ -74,9 +72,8 @@ public ChallengeResponseDTO getChallenge(@PathVariable("challengeId") Long chall @PutMapping(value = "/challenges/{challengeId}", consumes={MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE}) public void editChallenge(@PathVariable Long challengeId, @RequestPart(value = "request") ChallengeEditDTO challengeEditDTO, @RequestPart(value = "image", required = false) MultipartFile file){ - if(file != null){ - challengeEditDTO.setImage(imageService.updateImage(file, "challenge", "image")); - } + + challengeEditDTO.setImage(imageService.updateImage(file, "challenge", "image")); challengeService.editChallenge(challengeId, challengeEditDTO); } diff --git a/src/main/java/dopamine/backend/domain/level/controller/LevelController.java b/src/main/java/dopamine/backend/domain/level/controller/LevelController.java index 46466f0..5d8576d 100644 --- a/src/main/java/dopamine/backend/domain/level/controller/LevelController.java +++ b/src/main/java/dopamine/backend/domain/level/controller/LevelController.java @@ -31,9 +31,7 @@ public LevelResponseDto createLevel( @RequestPart(value = "badge", required = false) MultipartFile file) { // 이미지 업로드 - if (file != null) { - levelRequestDto.setBadge(imageService.updateImage(file, "level", "badge")); - } + levelRequestDto.setBadge(imageService.updateImage(file, "level", "badge")); // 레벨 생성 Level level = levelService.createLevel(levelRequestDto); @@ -64,9 +62,7 @@ public LevelResponseDto editLevel( @RequestPart(value = "badge", required = false) MultipartFile file) { // 이미지 업로드 - if (file != null) { - levelEditDto.setBadge(imageService.updateImage(file, "level", "badge")); - } + levelEditDto.setBadge(imageService.updateImage(file, "level", "badge")); return levelService.editLevel(levelId, levelEditDto); } diff --git a/src/main/java/dopamine/backend/global/s3/service/ImageService.java b/src/main/java/dopamine/backend/global/s3/service/ImageService.java index d9bf047..75e1acf 100644 --- a/src/main/java/dopamine/backend/global/s3/service/ImageService.java +++ b/src/main/java/dopamine/backend/global/s3/service/ImageService.java @@ -29,6 +29,8 @@ public class ImageService { public String updateImage(MultipartFile file, String entityName, String columnName) { + if (file.isEmpty()) return null; + // File Path 설정 String uploadFilePath = entityName + "/" + columnName; // 엔티티명.컬럼명 폴더가 만들어짐 From 5cae473f1c9fe1fa81f0a859d4015f7265296c44 Mon Sep 17 00:00:00 2001 From: gabang2 Date: Wed, 4 Oct 2023 22:17:32 +0900 Subject: [PATCH 5/9] =?UTF-8?q?refactor=20#65=20:=20MemberService=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20-=20exp&Level=20?= =?UTF-8?q?=EC=97=B0=EB=8F=99=20=EB=B6=80=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../level/service/LevelInitService.java | 3 +- .../member/controller/MemberController.java | 5 - .../backend/domain/member/entity/Member.java | 20 ++- .../member/request/MemberRequestDto.java | 9 -- .../domain/member/service/MemberService.java | 116 ++++++------------ 5 files changed, 46 insertions(+), 107 deletions(-) diff --git a/src/main/java/dopamine/backend/domain/level/service/LevelInitService.java b/src/main/java/dopamine/backend/domain/level/service/LevelInitService.java index cc7d6f4..c3a0a78 100644 --- a/src/main/java/dopamine/backend/domain/level/service/LevelInitService.java +++ b/src/main/java/dopamine/backend/domain/level/service/LevelInitService.java @@ -22,8 +22,7 @@ public void run(String... args) throws Exception { return levelService.createLevel( LevelRequestDto .builder() - .name("새싹지키미") - .badge("/url/testurl") + .name("새싹지킴이") .exp(0) .build() ); diff --git a/src/main/java/dopamine/backend/domain/member/controller/MemberController.java b/src/main/java/dopamine/backend/domain/member/controller/MemberController.java index caf8119..ffab94e 100644 --- a/src/main/java/dopamine/backend/domain/member/controller/MemberController.java +++ b/src/main/java/dopamine/backend/domain/member/controller/MemberController.java @@ -25,7 +25,6 @@ @RequestMapping("/api/members") @Api(tags = "멤버 API") @RequiredArgsConstructor -@Slf4j public class MemberController { private final MemberService memberService; private final MemberMapper memberMapper; @@ -33,15 +32,11 @@ public class MemberController { private final LevelService levelService; private final FeedRepository feedRepository; - - // CREATE : 생성 @PostMapping public ResponseEntity createMember(@Valid @RequestBody MemberRequestDto memberRequestDto) { Member member = memberService.createMember(memberRequestDto); MemberResponseDto memberResponseDto = memberMapper.memberToMemberResponseDto(member); - log.info("임시 accessToken"); - log.info(jwtService.getAccessToken(member)); return new ResponseEntity<>(memberResponseDto, HttpStatus.CREATED); } diff --git a/src/main/java/dopamine/backend/domain/member/entity/Member.java b/src/main/java/dopamine/backend/domain/member/entity/Member.java index 49670a9..036ad4c 100644 --- a/src/main/java/dopamine/backend/domain/member/entity/Member.java +++ b/src/main/java/dopamine/backend/domain/member/entity/Member.java @@ -5,10 +5,7 @@ import dopamine.backend.domain.feed.entity.Feed; import dopamine.backend.domain.feedLike.entity.FeedLike; import dopamine.backend.domain.level.entity.Level; -import lombok.AccessLevel; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; +import lombok.*; import javax.persistence.*; import java.time.LocalDateTime; @@ -60,12 +57,8 @@ public class Member extends BaseEntity { */ @Builder - public Member(String kakaoId, String nickname, String refreshToken, int exp, Level level) { + public Member(String kakaoId) { this.kakaoId = kakaoId; - this.nickname = nickname; - this.refreshToken = refreshToken; - this.exp = exp; - setLevel(level); } /** @@ -76,12 +69,10 @@ public Member(String kakaoId, String nickname, String refreshToken, int exp, Lev * @param exp * @param level */ - public void changeMember(String kakaoId, String nickname, String refreshToken, int exp, Level level) { + public void changeMember(String kakaoId, String nickname, String refreshToken) { this.kakaoId = Optional.ofNullable(kakaoId).orElse(this.kakaoId); this.nickname = Optional.ofNullable(nickname).orElse(this.nickname); this.refreshToken = Optional.ofNullable(refreshToken).orElse(this.refreshToken); - this.exp = (exp != 0) ? exp : this.exp; - setLevel(level); } // == 연관관계 편의 메소드 == // @@ -98,4 +89,9 @@ public void setLevel(Level level) { public void setChallengeRefreshDate(LocalDateTime localDateTime){ challengeRefreshDate = localDateTime; } + + public void setExpAndLevel(int exp, Level level) { + this.exp = exp; + setLevel(level); + } } \ No newline at end of file diff --git a/src/main/java/dopamine/backend/domain/member/request/MemberRequestDto.java b/src/main/java/dopamine/backend/domain/member/request/MemberRequestDto.java index 6e2f2ee..5901631 100644 --- a/src/main/java/dopamine/backend/domain/member/request/MemberRequestDto.java +++ b/src/main/java/dopamine/backend/domain/member/request/MemberRequestDto.java @@ -10,14 +10,5 @@ @NoArgsConstructor @AllArgsConstructor public class MemberRequestDto { - private String kakaoId; - - @Pattern(regexp = "^[ㄱ-ㅎ가-힣a-zA-Z0-9-_ ]{2,10}$", message = "닉네임은 특수문자를 제외한 2~10자리여야 합니다.") - private String nickname; - - private String refreshToken; - - private int exp; - } diff --git a/src/main/java/dopamine/backend/domain/member/service/MemberService.java b/src/main/java/dopamine/backend/domain/member/service/MemberService.java index 16df097..9f8c5aa 100644 --- a/src/main/java/dopamine/backend/domain/member/service/MemberService.java +++ b/src/main/java/dopamine/backend/domain/member/service/MemberService.java @@ -23,54 +23,31 @@ @Slf4j public class MemberService { private final MemberRepository memberRepository; - private final MemberMapper memberMapper; private final LevelRepository levelRepository; /** - * CREATE : 생성 + * kakaoId를 가진 Member가 없으면 새로운 Member생성, 아니면 기존 Member반환 * - * @param memberRequestDto + * @param kakaoId + * @return */ - public Member createMember(MemberRequestDto memberRequestDto) { - // 닉네임 중복 검사 - checkNicknameDuplication(null, memberRequestDto.getNickname()); - - // exp에 해당하는 레벨 생성 - Level level = getMemberLevel(memberRequestDto.getExp()); - - // member 생성 - Member member = Member.builder() - .kakaoId(memberRequestDto.getKakaoId()) // kakaoId - .nickname(memberRequestDto.getNickname()) // nickname - .refreshToken(memberRequestDto.getRefreshToken()) // refreshToken - .level(level) // level - .exp(memberRequestDto.getExp()).build(); // exp - - memberRepository.save(member); - - return member; + public Member findMemberByKakaoId(String kakaoId) { + return memberRepository.findMemberByKakaoId(kakaoId).orElseGet(() -> createMember(MemberRequestDto.builder() + .kakaoId(kakaoId) + .build())); } /** - * DELETE : 삭제 + * CREATE : 생성 * - * @param member + * @param memberRequestDto */ - public void deleteMember(Member member) { - memberRepository.delete(member); - } + public Member createMember(MemberRequestDto memberRequestDto) { - /** - * GET : 조회 - * - * @param memberId - * @return memberResponseDto - */ - @Transactional(readOnly = true) - public MemberResponseDto getMember(Long memberId) { - Member member = verifiedMember(memberId); - MemberResponseDto memberResponseDto = memberMapper.memberToMemberResponseDto(member); - return memberResponseDto; + Member member = Member.builder().kakaoId(memberRequestDto.getKakaoId()).build(); // member 생성 + setMemberExpAndLevel(member, 0); // 경험치 설정 + + return memberRepository.save(member); } /** @@ -85,24 +62,22 @@ public Member editMember(Member member, MemberEditDto memberEditDto) { // 닉네임 중복 검사 checkNicknameDuplication(member, memberEditDto.getNickname()); - // exp에 해당하는 레벨 생성 - Level level = member.getLevel(); - if (memberEditDto.getExp() != 0) { - level = getMemberLevel(memberEditDto.getExp()); - } - // member 수정 - member.changeMember( - memberEditDto.getKakaoId(), // kakaoId - memberEditDto.getNickname(), // nickname - memberEditDto.getRefreshToken(), // refreshToken - memberEditDto.getExp(), // exp - level // level - ); + member.changeMember(memberEditDto.getKakaoId(), memberEditDto.getNickname(), memberEditDto.getRefreshToken()); + setMemberExpAndLevel(member, memberEditDto.getExp()); return member; } + /** + * DELETE : 삭제 + * + * @param member + */ + public void deleteMember(Member member) { + memberRepository.delete(member); + } + /** * 검증 -> memberId 입력하면 관련 Member Entity가 있는지 확인 * @@ -115,35 +90,21 @@ public Member verifiedMember(Long memberId) { return member.orElseThrow(() -> new BusinessLogicException(ExceptionCode.MEMBER_NOT_FOUND)); } - //== jwt 인증 부분==// - - /** - * kakaoId를 가진 Member가 없으면 새로운 Member생성, 아니면 기존 Member반환 - * - * @param kakaoId - * @return - */ - public Member findMemberByKakaoId(String kakaoId) { - return memberRepository.findMemberByKakaoId(kakaoId).orElseGet(() -> createMember(MemberRequestDto.builder() - .kakaoId(kakaoId) - .build())); - } /** - * 닉네임 중복 검사

- * 1. 기존 사용자 정보이면, 중복 검사 진행 X

- * 2. nickname 값이 입력되어 있으면, 중복 검사 진행 + * 닉네임 중복 검사 * * @param member * @param nickname */ public void checkNicknameDuplication(Member member, String nickname) { + // 기존 사용자 정보이면 중복 검사 진행x if (member != null && member.getNickname() != null) { if (member.getNickname().equals(nickname)) { return; } } - + // nickname 값이 입력되어 있으면, 중복 검사 진행 if (nickname != null) { memberRepository.findMemberByNickname(nickname).ifPresent(a -> { throw new BusinessLogicException(ExceptionCode.NICKNAME_DUPLICATE); @@ -152,16 +113,17 @@ public void checkNicknameDuplication(Member member, String nickname) { } /** - * exp에 해당하는 Level 반환 + * exp에 따라 level 변함 * + * @param member * @param exp - * @return Level */ - public Level getMemberLevel(int exp) { - return levelRepository.findTopByExpLessThanEqualOrderByExpDesc(exp); + public void setMemberExpAndLevel(Member member, int exp) { + if (exp <= 0 && member.getLevel() != null) return; + Level level = levelRepository.findTopByExpLessThanEqualOrderByExpDesc(exp); + member.setExpAndLevel(exp, level); } - /** * Member의 exp 증가 * @@ -170,8 +132,7 @@ public Level getMemberLevel(int exp) { */ public void plusMemberExp(Member member, int exp) { exp = member.getExp() + exp; - Level level = getMemberLevel(exp); - member.changeMember(null, null, null, exp, level); + setMemberExpAndLevel(member, exp); } /** @@ -181,10 +142,7 @@ public void plusMemberExp(Member member, int exp) { * @param exp */ public void minusMemberExp(Member member, int exp) { - if (member.getExp() >= exp) { - exp = member.getExp() - exp; - Level level = getMemberLevel(exp); - member.changeMember(null, null, null, exp, level); - } + exp = member.getExp() - exp; + setMemberExpAndLevel(member, exp); } } \ No newline at end of file From dcf81f97e238086485b48d5e893d9b677b4a85ac Mon Sep 17 00:00:00 2001 From: gabang2 Date: Wed, 4 Oct 2023 22:24:48 +0900 Subject: [PATCH 6/9] =?UTF-8?q?refactor=20#65=20:=20MemberService=20?= =?UTF-8?q?=EC=95=88=EC=93=B0=EB=8A=94=20=EC=BD=94=EB=93=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC=20&=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=88=9C?= =?UTF-8?q?=EC=84=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/member/service/MemberService.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/dopamine/backend/domain/member/service/MemberService.java b/src/main/java/dopamine/backend/domain/member/service/MemberService.java index 9f8c5aa..7c38af6 100644 --- a/src/main/java/dopamine/backend/domain/member/service/MemberService.java +++ b/src/main/java/dopamine/backend/domain/member/service/MemberService.java @@ -20,7 +20,6 @@ @Service @AllArgsConstructor @Transactional -@Slf4j public class MemberService { private final MemberRepository memberRepository; private final LevelRepository levelRepository; @@ -78,18 +77,6 @@ public void deleteMember(Member member) { memberRepository.delete(member); } - /** - * 검증 -> memberId 입력하면 관련 Member Entity가 있는지 확인 - * - * @param memberId - * @return member - */ - - public Member verifiedMember(Long memberId) { - Optional member = memberRepository.findById(memberId); - return member.orElseThrow(() -> new BusinessLogicException(ExceptionCode.MEMBER_NOT_FOUND)); - } - /** * 닉네임 중복 검사 @@ -97,6 +84,7 @@ public Member verifiedMember(Long memberId) { * @param member * @param nickname */ + @Transactional(readOnly = true) public void checkNicknameDuplication(Member member, String nickname) { // 기존 사용자 정보이면 중복 검사 진행x if (member != null && member.getNickname() != null) { @@ -145,4 +133,16 @@ public void minusMemberExp(Member member, int exp) { exp = member.getExp() - exp; setMemberExpAndLevel(member, exp); } + + /** + * 검증 -> memberId 입력하면 관련 Member Entity가 있는지 확인 + * + * @param memberId + * @return member + */ + @Transactional(readOnly = true) + public Member verifiedMember(Long memberId) { + Optional member = memberRepository.findById(memberId); + return member.orElseThrow(() -> new BusinessLogicException(ExceptionCode.MEMBER_NOT_FOUND)); + } } \ No newline at end of file From f0e1fd63157d29adbe6fbe539eb36f14c0c5f2e7 Mon Sep 17 00:00:00 2001 From: gabang2 Date: Wed, 4 Oct 2023 22:35:45 +0900 Subject: [PATCH 7/9] =?UTF-8?q?refactor=20#65=20:=20MemberController=20?= =?UTF-8?q?=EA=B0=80=EC=8B=9C=EC=84=B1=20=EC=A2=8B=EA=B2=8C=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 --- .../feed/repository/FeedRepository.java | 2 +- .../member/controller/MemberController.java | 19 ++++--------- .../backend/domain/member/entity/Member.java | 28 +++++++++++++------ 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/main/java/dopamine/backend/domain/feed/repository/FeedRepository.java b/src/main/java/dopamine/backend/domain/feed/repository/FeedRepository.java index 75e4678..9216128 100644 --- a/src/main/java/dopamine/backend/domain/feed/repository/FeedRepository.java +++ b/src/main/java/dopamine/backend/domain/feed/repository/FeedRepository.java @@ -9,7 +9,7 @@ import java.util.Optional; public interface FeedRepository extends JpaRepository { - List findFeedByMemberAndDelYn(Member member, Boolean delYn); + List findFeedByMemberAndDelYnAndFulfillYn(Member member, Boolean delYn, Boolean fulfillYn); public List findFeedByMemberAndDelYnAndCreatedDateBetweenOrderByCreatedDate(Member member, Boolean delYn, LocalDateTime startDate, LocalDateTime finishDate); } diff --git a/src/main/java/dopamine/backend/domain/member/controller/MemberController.java b/src/main/java/dopamine/backend/domain/member/controller/MemberController.java index ffab94e..c3bbc98 100644 --- a/src/main/java/dopamine/backend/domain/member/controller/MemberController.java +++ b/src/main/java/dopamine/backend/domain/member/controller/MemberController.java @@ -51,19 +51,17 @@ public void deleteMember(@RequestHeader("Authorization") String accessToken) { @GetMapping public ResponseEntity getMember(@RequestHeader("Authorization") String accessToken) { - Member member = jwtService.getMemberFromAccessToken(accessToken); // member 찾기 - - LevelDetailResponseDto levelDetailResponseDto = levelService.getMemberDetailLevel(member); - - int successCnt = feedRepository.findFeedByMemberAndDelYn(member, false).size(); // todo : fullfillyn default값 추가되면 수정해야함 + // member 찾기 + Member member = jwtService.getMemberFromAccessToken(accessToken); + // Response MemberDetailResponseDto response = MemberDetailResponseDto.builder() .memberId(member.getMemberId()) .kakaoId(member.getKakaoId()) .nickname(member.getNickname()) - .successCnt(successCnt) + .successCnt(feedRepository.findFeedByMemberAndDelYnAndFulfillYn(member, false, true).size()) .exp(member.getExp()) - .level(levelDetailResponseDto) + .level(levelService.getMemberDetailLevel(member)) .build(); return new ResponseEntity<>(response, HttpStatus.OK); @@ -80,11 +78,4 @@ public ResponseEntity editMember(@RequestHeader("Authorization") String accessTo return new ResponseEntity<>(response, HttpStatus.OK); } - - @GetMapping("/mypage") - public ResponseEntity returnMemberDetail(@RequestHeader("Authorization") String accessToken) { - Member member = jwtService.getMemberFromAccessToken(accessToken); - MemberResponseDto response = memberMapper.memberToMemberResponseDto(member); - return new ResponseEntity<>(response, HttpStatus.OK); - } } diff --git a/src/main/java/dopamine/backend/domain/member/entity/Member.java b/src/main/java/dopamine/backend/domain/member/entity/Member.java index 036ad4c..196f694 100644 --- a/src/main/java/dopamine/backend/domain/member/entity/Member.java +++ b/src/main/java/dopamine/backend/domain/member/entity/Member.java @@ -75,6 +75,25 @@ public void changeMember(String kakaoId, String nickname, String refreshToken) { this.refreshToken = Optional.ofNullable(refreshToken).orElse(this.refreshToken); } + // == 비즈니스 로직 == // + /** + * exp와 level 변경 + * @param exp + * @param level + */ + public void setExpAndLevel(int exp, Level level) { + this.exp = exp; + setLevel(level); + } + + /** + * RefreshDate 변경 + * @param localDateTime + */ + public void setChallengeRefreshDate(LocalDateTime localDateTime){ + challengeRefreshDate = localDateTime; + } + // == 연관관계 편의 메소드 == // public void setLevel(Level level) { if (this.level != null) { @@ -85,13 +104,4 @@ public void setLevel(Level level) { this.level = Optional.ofNullable(level).orElse(this.level); this.level.getMembers().add(this); } - - public void setChallengeRefreshDate(LocalDateTime localDateTime){ - challengeRefreshDate = localDateTime; - } - - public void setExpAndLevel(int exp, Level level) { - this.exp = exp; - setLevel(level); - } } \ No newline at end of file From cb5fa6d7466a872a79076434c7c6e6e7562e95eb Mon Sep 17 00:00:00 2001 From: gabang2 Date: Wed, 4 Oct 2023 23:11:49 +0900 Subject: [PATCH 8/9] =?UTF-8?q?refactor=20#65=20:=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=EC=9E=90=EC=9D=98=20Feed=EB=A5=BC=20=EA=B8=B0=EC=A4=80?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20exp=EC=99=80=20Level=20=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FeedBackofficeController.java | 7 +-- .../domain/challenge/entity/Challenge.java | 2 +- .../domain/feed/service/FeedService.java | 3 +- .../domain/member/service/MemberService.java | 43 ++++++------------- 4 files changed, 18 insertions(+), 37 deletions(-) diff --git a/src/main/java/dopamine/backend/backoffice/controller/FeedBackofficeController.java b/src/main/java/dopamine/backend/backoffice/controller/FeedBackofficeController.java index b316f35..dab1f65 100644 --- a/src/main/java/dopamine/backend/backoffice/controller/FeedBackofficeController.java +++ b/src/main/java/dopamine/backend/backoffice/controller/FeedBackofficeController.java @@ -35,9 +35,7 @@ public String feed(Model model) { public String feedDelete(@PathVariable("feedId") Long feedId) { Feed feed = feedService.verifiedFeed(feedId); feedService.deleteFeedHard(feedId); - if (feed.getFulfillYn()) { - memberService.minusMemberExp(feed.getMember(), feed.getChallenge().getChallengeLevel().getExp()); - } + memberService.setMemberExpAndLevel(feed.getMember()); return "redirect:/backoffice/feed"; } @@ -47,11 +45,10 @@ public String feedFullfill(@PathVariable("feedId") Long feedId) { if (feedService.verifiedFeed(feedId).getFulfillYn()) { feedService.patchFeedFulfill(feedId, false); - memberService.minusMemberExp(feed.getMember(), feed.getChallenge().getChallengeLevel().getExp()); } else { feedService.patchFeedFulfill(feedId, true); - memberService.plusMemberExp(feed.getMember(), feed.getChallenge().getChallengeLevel().getExp()); } + memberService.setMemberExpAndLevel(feed.getMember()); return "redirect:/backoffice/feed"; } diff --git a/src/main/java/dopamine/backend/domain/challenge/entity/Challenge.java b/src/main/java/dopamine/backend/domain/challenge/entity/Challenge.java index 9bc8d5a..8572aae 100644 --- a/src/main/java/dopamine/backend/domain/challenge/entity/Challenge.java +++ b/src/main/java/dopamine/backend/domain/challenge/entity/Challenge.java @@ -49,7 +49,7 @@ public Challenge(String title, String subtitle, String image, String challengeGu this.challengeLevel = challengeLevel; } - public void changeChallenge(ChallengeEditDTO challengeEditDTO){ + public void changeChallenge(ChallengeEditDTO challengeEditDTO) { this.title = challengeEditDTO.getTitle(); this.subtitle = challengeEditDTO.getSubtitle(); this.image = challengeEditDTO.getImage(); diff --git a/src/main/java/dopamine/backend/domain/feed/service/FeedService.java b/src/main/java/dopamine/backend/domain/feed/service/FeedService.java index 173e45f..b4ea996 100644 --- a/src/main/java/dopamine/backend/domain/feed/service/FeedService.java +++ b/src/main/java/dopamine/backend/domain/feed/service/FeedService.java @@ -97,8 +97,7 @@ public void postFeed(Member member, FeedRequestDTO feedRequestDTO) { feed.setChallenge(challenge); feed.setMember(member); setCertification(member, challenge); - int exp = feed.getChallenge().getChallengeLevel().getExp(); - memberService.plusMemberExp(member, exp); + memberService.setMemberExpAndLevel(member); feedRepository.save(feed); } diff --git a/src/main/java/dopamine/backend/domain/member/service/MemberService.java b/src/main/java/dopamine/backend/domain/member/service/MemberService.java index 7c38af6..9e619d2 100644 --- a/src/main/java/dopamine/backend/domain/member/service/MemberService.java +++ b/src/main/java/dopamine/backend/domain/member/service/MemberService.java @@ -1,5 +1,6 @@ package dopamine.backend.domain.member.service; +import dopamine.backend.domain.feed.entity.Feed; import dopamine.backend.global.exception.BusinessLogicException; import dopamine.backend.global.exception.ExceptionCode; import dopamine.backend.domain.level.repository.LevelRepository; @@ -44,7 +45,7 @@ public Member findMemberByKakaoId(String kakaoId) { public Member createMember(MemberRequestDto memberRequestDto) { Member member = Member.builder().kakaoId(memberRequestDto.getKakaoId()).build(); // member 생성 - setMemberExpAndLevel(member, 0); // 경험치 설정 + setMemberExpAndLevel(member); // 경험치 설정 return memberRepository.save(member); } @@ -63,7 +64,7 @@ public Member editMember(Member member, MemberEditDto memberEditDto) { // member 수정 member.changeMember(memberEditDto.getKakaoId(), memberEditDto.getNickname(), memberEditDto.getRefreshToken()); - setMemberExpAndLevel(member, memberEditDto.getExp()); + setMemberExpAndLevel(member); return member; } @@ -101,39 +102,23 @@ public void checkNicknameDuplication(Member member, String nickname) { } /** - * exp에 따라 level 변함 - * + * member의 Feed에 따라 exp와 Level변경 * @param member - * @param exp */ - public void setMemberExpAndLevel(Member member, int exp) { - if (exp <= 0 && member.getLevel() != null) return; - Level level = levelRepository.findTopByExpLessThanEqualOrderByExpDesc(exp); - member.setExpAndLevel(exp, level); - } + public void setMemberExpAndLevel(Member member) { + int exp = 0; - /** - * Member의 exp 증가 - * - * @param member - * @param exp - */ - public void plusMemberExp(Member member, int exp) { - exp = member.getExp() + exp; - setMemberExpAndLevel(member, exp); - } + // 사용자의 Feed를 기준으로 exp 계산 + for (Feed f : member.getFeeds()) { + if (!f.getFulfillYn()) continue; + exp += f.getChallenge().getChallengeLevel().getExp(); + } - /** - * Member의 exp 감소 - * - * @param member - * @param exp - */ - public void minusMemberExp(Member member, int exp) { - exp = member.getExp() - exp; - setMemberExpAndLevel(member, exp); + // exp와 level 변경 + member.setExpAndLevel(exp, levelRepository.findTopByExpLessThanEqualOrderByExpDesc(exp)); } + /** * 검증 -> memberId 입력하면 관련 Member Entity가 있는지 확인 * From 607868ce39dfafd9e903febc76b7e8c16b10a916 Mon Sep 17 00:00:00 2001 From: gabang2 Date: Wed, 4 Oct 2023 23:41:40 +0900 Subject: [PATCH 9/9] =?UTF-8?q?refactor=20#65=20:=20Feed=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20&=20=EC=83=9D=EC=84=B1=20&=20fullfill=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EB=94=B0=EB=9D=BC=EC=84=9C=20exp=EA=B3=84=EC=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FeedBackofficeController.java | 2 +- .../backend/domain/feed/controller/FeedController.java | 7 ++++++- .../backend/domain/feed/service/FeedService.java | 10 +++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/dopamine/backend/backoffice/controller/FeedBackofficeController.java b/src/main/java/dopamine/backend/backoffice/controller/FeedBackofficeController.java index dab1f65..7abb351 100644 --- a/src/main/java/dopamine/backend/backoffice/controller/FeedBackofficeController.java +++ b/src/main/java/dopamine/backend/backoffice/controller/FeedBackofficeController.java @@ -34,7 +34,7 @@ public String feed(Model model) { @GetMapping("/{feedId}/delete") public String feedDelete(@PathVariable("feedId") Long feedId) { Feed feed = feedService.verifiedFeed(feedId); - feedService.deleteFeedHard(feedId); + feedService.deleteFeedHard(feed); memberService.setMemberExpAndLevel(feed.getMember()); return "redirect:/backoffice/feed"; } diff --git a/src/main/java/dopamine/backend/domain/feed/controller/FeedController.java b/src/main/java/dopamine/backend/domain/feed/controller/FeedController.java index 4aba832..01d7f1f 100644 --- a/src/main/java/dopamine/backend/domain/feed/controller/FeedController.java +++ b/src/main/java/dopamine/backend/domain/feed/controller/FeedController.java @@ -1,11 +1,13 @@ package dopamine.backend.domain.feed.controller; +import dopamine.backend.domain.feed.entity.Feed; import dopamine.backend.domain.feed.request.FeedEditDTO; import dopamine.backend.domain.feed.request.FeedRequestDTO; import dopamine.backend.domain.feed.response.FeedResponseDTO; import dopamine.backend.domain.feed.response.FeedYearResponseDto; import dopamine.backend.domain.feed.service.FeedService; import dopamine.backend.domain.member.entity.Member; +import dopamine.backend.domain.member.service.MemberService; import dopamine.backend.global.exception.BusinessLogicException; import dopamine.backend.global.exception.ExceptionCode; import dopamine.backend.global.jwt.service.JwtService; @@ -30,6 +32,7 @@ public class FeedController { private final FeedService feedService; private final ImageService imageService; private final JwtService jwtService; + private final MemberService memberService; /** * 피드 조회 @@ -217,6 +220,8 @@ public void deleteFeed(@PathVariable Long feedId) { */ @DeleteMapping("/feeds/{feedId}/hard") public void deleteFeedHard(@PathVariable Long feedId) { - feedService.deleteFeedHard(feedId); + Feed feed = feedService.verifiedFeed(feedId); + feedService.deleteFeedHard(feed); + memberService.setMemberExpAndLevel(feed.getMember()); } } \ No newline at end of file diff --git a/src/main/java/dopamine/backend/domain/feed/service/FeedService.java b/src/main/java/dopamine/backend/domain/feed/service/FeedService.java index b4ea996..169fc94 100644 --- a/src/main/java/dopamine/backend/domain/feed/service/FeedService.java +++ b/src/main/java/dopamine/backend/domain/feed/service/FeedService.java @@ -140,14 +140,10 @@ public void deleteFeed(Long feedId) { /** * 피드 완전 삭제 (DB) - * - * @param feedId + * @param feed */ - public void deleteFeedHard(Long feedId) { - Feed feed = verifiedFeed(feedId); - + public void deleteFeedHard(Feed feed) { feed.deleteFromChallenge(); - feedRepository.delete(feed); } @@ -271,7 +267,7 @@ public List feedListByMemberAndYear(Member member, List