Skip to content

Commit

Permalink
Merge pull request #292 from Team-Smeme/develop
Browse files Browse the repository at this point in the history
[CHORE] 실서버 배포
  • Loading branch information
thguss authored May 19, 2024
2 parents c338b52 + ffe7627 commit 3259475
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 28 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

- ✍️ **서비스 소개**: [서비스 소개 바로가기](https://linktr.ee/smeem)
- 📱 **iOS 다운로드**: [App Stroe 바로가기](https://apps.apple.com/kr/app/smeem-%EC%8A%A4%EB%B0%88-%EC%98%81%EC%9E%91-%EC%98%81%EC%96%B4%EC%9D%BC%EA%B8%B0-%EC%98%81%EC%96%B4%EB%85%B8%ED%8A%B8/id6450711685)
- 📱 **Android 다운로드**: 준비 중
- 📱 **Android 다운로드**: [Play Store 바로가기](https://play.google.com/store/apps/details?id=com.sopt.smeem&hl=ko&gl=US)

<br/>

Expand Down Expand Up @@ -40,7 +40,7 @@
## 🗂️ 프로젝트 구조 (Project Architecture) : 멀티모듈 구조 (Multi-Module)
Smeem 프로젝트는 단일 모듈 구조에서 시작하여, 코드 간의 의존도와 결합도를 줄여보고자 멀티모듈 구조의 프로젝트로 리팩토링을 진행했습니다.

<img width="600" alt="image" src="https://github.com/Team-Smeme/Smeme-server-renewal/assets/81692211/3dc1d246-bf8f-47f9-bfc6-b22158f6c26f" />
<img width="600" alt="image" src="https://github.com/Team-Smeme/Smeme-server-renewal/assets/55437339/367330ae-bb98-4f09-9caa-6a63353e4a64" />

### smeem-api
- 클라이언트와 가장 직접적으로 소통하는 계층으로, API와 비즈니스 로직을 모아둔 모듈입니다.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.smeem.domain.badge.adapter.BadgeFinder;
import com.smeem.domain.badge.model.Badge;
import com.smeem.domain.badge.model.BadgeType;
import com.smeem.domain.member.adapter.memberbadge.MemberBadgeCounter;
import com.smeem.domain.member.adapter.member.MemberFinder;
import com.smeem.domain.member.adapter.memberbadge.MemberBadgeFinder;
import com.smeem.domain.member.adapter.memberbadge.MemberBadgeSaver;
import com.smeem.domain.member.model.Member;
Expand All @@ -26,7 +26,7 @@ public class BadgeService {
private final BadgeFinder badgeFinder;
private final MemberBadgeSaver memberBadgeSaver;
private final MemberBadgeFinder memberBadgeFinder;
private final MemberBadgeCounter memberBadgeCounter;
private final MemberFinder memberFinder;

public BadgeListServiceResponseV3 getBadgesV3(BadgeListServiceRequestV3 request) {
val response = badgeFinder.findAllOrderById()
Expand Down Expand Up @@ -71,20 +71,21 @@ private void putBadgeMap(Map<BadgeType, List<Badge>> badgeMap, Badge badge) {
badgeMap.computeIfAbsent(badge.getType(), k -> new ArrayList<>()).add(badge);
}

private Integer calculateRemainingNumber(Long badgeId, Long count) {
private Integer calculateRemainingNumber(Long badgeId, int count) {
return switch (badgeId.intValue()) {
case 2 -> 1 - count.intValue() > 0 ? 1 - count.intValue() : null;
case 3 -> 10 - count.intValue() > 0 ? 10 - count.intValue() : null;
case 4 -> 30 - count.intValue() > 0 ? 30 - count.intValue() : null;
case 5 -> 50 - count.intValue() > 0 ? 50 - count.intValue() : null;
case 2 -> 1 - count;
case 3 -> 10 - count;
case 4 -> 30 - count;
case 5 -> 50 - count;
default -> null;
};
}

private BadgeGetServiceResponseV3 convertToBadgeGetServiceResponseV3(Badge badge, final long memberId) {
val count = memberBadgeCounter.countByBadgeIdAndMemberId(badge.getId(), memberId);
val hasBadge = count > 0;
val remainingNumber = calculateRemainingNumber(badge.getId(), count);
val member = memberFinder.findById(memberId);
val hasBadge = memberBadgeFinder.isExistByMemberAndBadge(member, badge);
val memberDiaryCount = member.getDiaries().size();
val remainingNumber = calculateRemainingNumber(badge.getId(), memberDiaryCount);
return BadgeGetServiceResponseV3.of(badge, hasBadge, remainingNumber);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import com.smeem.common.config.ValueConfig;
import com.smeem.domain.badge.adapter.BadgeFinder;
import com.smeem.domain.badge.model.Badge;
import com.smeem.domain.member.adapter.member.MemberCounter;
import com.smeem.domain.member.adapter.member.MemberFinder;
import com.smeem.domain.member.adapter.member.MemberUpdater;
import com.smeem.domain.member.exception.MemberException;
import com.smeem.domain.member.model.Member;
import com.smeem.domain.plan.adapter.PlanFinder;
import com.smeem.domain.training.model.DayType;
import com.smeem.domain.training.model.TrainingTime;
import com.smeem.external.discord.DiscordAlarmSender;
import com.smeem.external.discord.AlarmService;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -47,8 +48,9 @@ public class MemberService {
private final TrainingTimeService trainingTimeService;
private final GoalService goalService;
private final MemberBadgeService memberBadgeService;
private final DiscordAlarmSender discordAlarmSender;
private final AlarmService alarmService;
private final ValueConfig valueConfig;
private final MemberCounter memberCounter;

@Transactional
public MemberUpdateServiceResponse updateUserProfile(final MemberServiceUpdateUserProfileRequest request) {
Expand All @@ -58,8 +60,9 @@ public MemberUpdateServiceResponse updateUserProfile(final MemberServiceUpdateUs

ArrayList<Badge> badges = new ArrayList<>();
if (isNewMember(member)) {
val allMemberCount = memberCounter.count();
addWelcomeBadge(member, badges);
discordAlarmSender.send(SIGN_IN_MESSAGE + member.getId(), INFO);
alarmService.send(String.format(SIGN_IN_MESSAGE, request.username(), allMemberCount), INFO);
}
member.updateUsername(request.username());
return MemberUpdateServiceResponse.of(badges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.smeem.domain.plan.exception.PlanException;
import com.smeem.domain.topic.exception.TopicException;
import com.smeem.domain.training.exception.TrainingTimeException;
import com.smeem.external.discord.DiscordAlarmSender;
import com.smeem.external.discord.AlarmService;
import com.smeem.external.firebase.exception.FcmException;
import com.smeem.external.oauth.apple.exception.AppleException;
import com.smeem.external.oauth.exception.AuthException;
Expand All @@ -25,7 +25,7 @@
@RequiredArgsConstructor
public class ExceptionInterceptor {

private final DiscordAlarmSender discordAlarmSender;
private final AlarmService alarmService;

@ExceptionHandler(TrainingTimeException.class)
public ResponseEntity<FailureResponse> trainingTimeException(TrainingTimeException exception) {
Expand Down Expand Up @@ -89,6 +89,6 @@ public ResponseEntity<FailureResponse> baseException(RuntimeException exception)
}

private void sendDiscordAlarm(RuntimeException exception) {
discordAlarmSender.send(exception.getMessage(), ERROR);
alarmService.send(exception.getMessage(), ERROR);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class ValueConfig {
@Value("${smeem.client.version.ios.force}")
private String CLIENT_VERSION_IOS_FORCE_VERSION;

public static final String SIGN_IN_MESSAGE = "새로운 유저가 가입했습니다! ✍️ : ";
public static final String SIGN_IN_MESSAGE = "새로운 유저 %s 가 가입했습니다! ✍️ \n 현재 회원 수: %d 명";

public static final boolean DEFAULT_IS_PUBLIC_VALUE = true;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.smeem.domain.member.adapter.memberbadge;


import com.smeem.domain.badge.model.Badge;
import com.smeem.domain.member.repository.MemberBadgeRepository;
import com.smeem.domain.support.RepositoryAdapter;
Expand All @@ -15,8 +14,4 @@ public class MemberBadgeCounter {
public long countByBadge(final Badge badge) {
return memberBadgeRepository.countByBadge(badge);
}

public long countByBadgeIdAndMemberId(final long badgeId, final long memberId) {
return memberBadgeRepository.countByBadgeIdAndMemberId(badgeId, memberId);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.smeem.domain.member.adapter.memberbadge;

import com.smeem.common.code.failure.MemberFailureCode;
import com.smeem.domain.badge.model.Badge;
import com.smeem.domain.member.exception.MemberException;
import com.smeem.domain.member.model.Member;
import com.smeem.domain.member.model.MemberBadge;
import com.smeem.domain.member.repository.MemberBadgeRepository;
import com.smeem.domain.support.RepositoryAdapter;
Expand All @@ -24,4 +26,8 @@ public MemberBadge findFirstByMemberIdOrderByCreatedAtDesc(final long id) {
.orElseThrow(() -> new MemberException(MemberFailureCode.EMPTY_MEMBER));
}

public boolean isExistByMemberAndBadge(Member member, Badge badge) {
return memberBadgeRepository.existsByMemberAndBadge(member, badge);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.smeem.domain.member.repository;

import com.smeem.domain.badge.model.Badge;
import com.smeem.domain.member.model.Member;
import com.smeem.domain.member.model.MemberBadge;
import org.springframework.data.jpa.repository.JpaRepository;

Expand All @@ -11,8 +12,6 @@ public interface MemberBadgeRepository extends JpaRepository<MemberBadge, Long>

List<MemberBadge> findAllByMemberId(final long memberId);
Optional<MemberBadge> findFirstByMemberIdOrderByCreatedAtDesc(final long memberId);

long countByBadge(Badge badge);

long countByBadgeIdAndMemberId(final long badgeId, final long memberId);
boolean existsByMemberAndBadge(Member member, Badge badge);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.smeem.external.discord;

public interface AlarmService {
void send(String content, DiscordAlarmCase alarmCase);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
@Component
@RequiredArgsConstructor
@Slf4j
public class DiscordAlarmSender {
public class DiscordAlarmService implements AlarmService {

private static final String APPLICATION_JSON_UTF8_VALUE = "application/json; UTF-8";

private final ObjectMapper objectMapper;
private final ValueConfig valueConfig;
private final Environment environment;

@Override
public void send(final String content, final DiscordAlarmCase alarmCase) {
try {
val restClient = RestClient.create();
Expand Down

0 comments on commit 3259475

Please sign in to comment.