Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Formatter 로직 수정 및 Deprecated 기능 제거 #493

Merged
merged 10 commits into from
Jul 21, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
@Getter
@AllArgsConstructor
public enum SemesterType {
FIRST("1학기", MonthDay.of(3, 1)),
SECOND("2학기", MonthDay.of(9, 1));
FIRST(1, MonthDay.of(3, 1)),
SECOND(2, MonthDay.of(9, 1));

private final String value;
private final Integer value;
private final MonthDay startDate;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.gdschongik.gdsc.domain.discord.dto.request.DiscordLinkRequest;
import com.gdschongik.gdsc.domain.discord.dto.response.DiscordCheckDuplicateResponse;
import com.gdschongik.gdsc.domain.discord.dto.response.DiscordCheckJoinResponse;
import com.gdschongik.gdsc.domain.discord.dto.response.DiscordNicknameResponse;
import com.gdschongik.gdsc.domain.discord.dto.response.DiscordVerificationCodeResponse;
import com.gdschongik.gdsc.domain.member.dao.MemberRepository;
import com.gdschongik.gdsc.domain.member.domain.Member;
Expand Down Expand Up @@ -83,19 +82,6 @@ private void updateDiscordId(String discordUsername, Member currentMember) {
currentMember.updateDiscordId(discordId);
}

@Transactional(readOnly = true)
public DiscordNicknameResponse checkDiscordRoleAssignable(String discordUsername) {
Member member = memberRepository
.findByDiscordUsername(discordUsername)
.orElseThrow(() -> new CustomException(MEMBER_NOT_FOUND));

if (!member.isRegular()) {
throw new CustomException(DISCORD_ROLE_UNASSIGNABLE);
}

return DiscordNicknameResponse.of(member.getNickname());
}

@Transactional(readOnly = true)
public DiscordCheckDuplicateResponse checkUsernameDuplicate(String discordUsername) {
boolean isExist = memberRepository.existsByDiscordUsername(discordUsername);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import com.gdschongik.gdsc.domain.member.application.OnboardingMemberService;
import com.gdschongik.gdsc.domain.member.dto.request.BasicMemberInfoRequest;
import com.gdschongik.gdsc.domain.member.dto.request.OnboardingMemberUpdateRequest;
import com.gdschongik.gdsc.domain.member.dto.response.MemberBasicInfoResponse;
import com.gdschongik.gdsc.domain.member.dto.response.MemberDashboardResponse;
import com.gdschongik.gdsc.domain.member.dto.response.MemberInfoResponse;
import com.gdschongik.gdsc.domain.member.dto.response.MemberUnivStatusResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -14,7 +12,6 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -27,22 +24,6 @@ public class OnboardingMemberController {

private final OnboardingMemberService onboardingMemberService;

@Deprecated
@Operation(summary = "디스코드 회원 정보 수정", description = "디스코드 회원 정보를 수정합니다.")
@PutMapping("/me/discord")
public ResponseEntity<Void> updateMember(@Valid @RequestBody OnboardingMemberUpdateRequest request) {
onboardingMemberService.updateMember(request);
return ResponseEntity.ok().build();
}

@Deprecated
@Operation(summary = "회원 정보 조회", description = "회원 정보를 조회합니다.")
@GetMapping("/me")
public ResponseEntity<MemberInfoResponse> getMemberInfo() {
MemberInfoResponse response = onboardingMemberService.getMemberInfo();
return ResponseEntity.ok().body(response);
}

@Operation(summary = "내 대시보드 조회", description = "내 대시보드를 조회합니다. 2차 MVP 기능입니다.")
@GetMapping("/me/dashboard")
public ResponseEntity<MemberDashboardResponse> getDashboard() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.domain.member.dto.request.BasicMemberInfoRequest;
import com.gdschongik.gdsc.domain.member.dto.request.MemberTokenRequest;
import com.gdschongik.gdsc.domain.member.dto.request.OnboardingMemberUpdateRequest;
import com.gdschongik.gdsc.domain.member.dto.response.MemberBasicInfoResponse;
import com.gdschongik.gdsc.domain.member.dto.response.MemberDashboardResponse;
import com.gdschongik.gdsc.domain.member.dto.response.MemberInfoResponse;
import com.gdschongik.gdsc.domain.member.dto.response.MemberTokenResponse;
import com.gdschongik.gdsc.domain.member.dto.response.MemberUnivStatusResponse;
import com.gdschongik.gdsc.domain.membership.application.MembershipService;
Expand All @@ -39,26 +37,6 @@ public class OnboardingMemberService {
private final MemberRepository memberRepository;
private final EnvironmentUtil environmentUtil;

@Deprecated
@Transactional
public void updateMember(OnboardingMemberUpdateRequest request) {
Member currentMember = memberUtil.getCurrentMember();
validateDiscordUsernameDuplicate(currentMember);
currentMember.verifyDiscord(request.discordUsername(), request.nickname());
}

private void validateDiscordUsernameDuplicate(Member member) {
if (memberRepository.existsByDiscordUsername(member.getDiscordUsername())) {
throw new CustomException(MEMBER_DISCORD_USERNAME_DUPLICATE);
}
}

public MemberInfoResponse getMemberInfo() {
// TODO: 대시보드 API로 통합
Member currentMember = memberUtil.getCurrentMember();
return MemberInfoResponse.of(currentMember);
}

public MemberUnivStatusResponse checkUnivVerificationStatus() {
Member currentMember = memberUtil.getCurrentMember();
return MemberUnivStatusResponse.from(currentMember);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.gdschongik.gdsc.domain.member.domain.AssociateRequirement;
import com.gdschongik.gdsc.domain.member.domain.Department;
import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.global.util.formatter.PhoneFormatter;
import java.util.Optional;

public record AdminMemberResponse(
Expand All @@ -21,10 +22,7 @@ public static AdminMemberResponse from(Member member) {
member.getId(),
member.getStudentId(),
member.getName(),
Optional.ofNullable(member.getPhone())
.map(phone -> String.format(
"%s-%s-%s", phone.substring(0, 3), phone.substring(3, 7), phone.substring(7)))
.orElse(null),
PhoneFormatter.format(member.getPhone()),
DepartmentDto.from(member.getDepartment()),
member.getEmail(),
member.getDiscordUsername(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gdschongik.gdsc.domain.member.domain.Department;
import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.global.util.formatter.PhoneFormatter;
import java.util.Optional;

public record MemberBasicInfoResponse(
Expand All @@ -18,10 +19,7 @@ public static MemberBasicInfoResponse from(Member member) {
member.getId(),
member.getStudentId(),
member.getName(),
Optional.ofNullable(member.getPhone())
.map(phone -> String.format(
"%s-%s-%s", phone.substring(0, 3), phone.substring(3, 7), phone.substring(7)))
.orElse(null),
PhoneFormatter.format(member.getPhone()),
Optional.ofNullable(member.getDepartment())
.map(Department::getDepartmentName)
.orElse(null),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ public static AdminRecruitmentResponse from(Recruitment recruitment) {

return new AdminRecruitmentResponse(
recruitment.getId(),
SemesterFormatter.format(
recruitment.getAcademicYear(),
recruitment.getSemesterType().getValue()),
SemesterFormatter.format(recruitment),
recruitment.getSemesterPeriod().getStartDate(),
recruitment.getSemesterPeriod().getEndDate(),
String.format("%s원", decimalFormat.format(recruitment.getFee().getAmount())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public static AdminRecruitmentRoundResponse from(RecruitmentRound recruitmentRou

return new AdminRecruitmentRoundResponse(
recruitmentRound.getId(),
SemesterFormatter.format(
recruitmentRound.getAcademicYear(),
recruitmentRound.getSemesterType().getValue()),
SemesterFormatter.format(recruitmentRound),
recruitmentRound.getPeriod().getStartDate(),
recruitmentRound.getPeriod().getEndDate(),
recruitmentRound.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ private DiscordConstant() {}
public static final String DEFER_MESSAGE_ISSUING_CODE = "인증코드를 발급받는 중입니다...";
public static final String REPLY_MESSAGE_ISSUING_CODE = "인증코드는 %d 입니다. 인증코드는 %d분 동안 유효합니다.";

// 가입하기 커맨드
public static final String COMMAND_NAME_JOIN = "가입하기";
public static final String COMMAND_DESCRIPTION_JOIN = "가입 신청이 승인된 멤버에게 역할을 부여합니다.";
public static final String DEFER_MESSAGE_JOIN = "가입 신청을 처리하는 중입니다...";
public static final String REPLY_MESSAGE_JOIN = "가입 신청이 승인되었습니다. GDSC Hongik에 합류하신 것을 환영합니다!";

// 디스코드 ID 저장 커맨드
public static final String COMMAND_NAME_BATCH_DISCORD_ID = "디스코드id-저장하기";
public static final String COMMAND_DESCRIPTION_BATCH_DISCORD_ID = "디스코드 인증이 완료된 멤버들의 디스코드 ID를 저장합니다.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public JDA jda() {
Objects.requireNonNull(jda.awaitReady().getGuildById(discordProperty.getServerId()))
.updateCommands()
.addCommands(Commands.slash(COMMAND_NAME_ISSUING_CODE, COMMAND_DESCRIPTION_ISSUING_CODE))
.addCommands(Commands.slash(COMMAND_NAME_JOIN, COMMAND_DESCRIPTION_JOIN))
.addCommands(Commands.slash(COMMAND_NAME_BATCH_DISCORD_ID, COMMAND_DESCRIPTION_BATCH_DISCORD_ID))
.queue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public enum ErrorCode {
DISCORD_INVALID_CODE_RANGE(HttpStatus.INTERNAL_SERVER_ERROR, "디스코드 인증코드는 4자리 숫자여야 합니다."),
DISCORD_CODE_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 유저네임으로 발급된 디스코드 인증코드가 존재하지 않습니다."),
DISCORD_CODE_MISMATCH(HttpStatus.CONFLICT, "디스코드 인증코드가 일치하지 않습니다."),
DISCORD_ROLE_UNASSIGNABLE(HttpStatus.INTERNAL_SERVER_ERROR, "디스코드 역할 부여가 불가능합니다. 가입 조건을 확인해주세요."),
DISCORD_ROLE_NOT_FOUND(HttpStatus.NOT_FOUND, "디스코드 역할을 찾을 수 없습니다."),
DISCORD_NOT_SIGNUP(HttpStatus.INTERNAL_SERVER_ERROR, "아직 가입신청서를 작성하지 않은 회원입니다."),
DISCORD_NICKNAME_NOTNULL(HttpStatus.INTERNAL_SERVER_ERROR, "닉네임은 빈 값이 될 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.gdschongik.gdsc.global.util.formatter;

import com.gdschongik.gdsc.domain.common.vo.Money;
import java.text.NumberFormat;
import java.util.Locale;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.NonNull;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MoneyFormatter {

public static final NumberFormat KOREA_NUMBER_FORMAT = NumberFormat.getNumberInstance(Locale.KOREA);

public static String format(@NonNull Money money) {
return KOREA_NUMBER_FORMAT.format(money.getAmount()) + "원";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class PhoneFormatter {
public static String format(@Nullable String phone) {
return phone == null
? null
: new StringBuilder(12)
.append(phone, 0, 3)
.append('-')
.append(phone, 3, 7)
.append('-')
.append(phone, 7, 11)
.toString();
@Nullable public static String format(@Nullable String phone) {
if (phone == null) return null;
return phone.substring(0, 3) + '-' + phone.substring(3, 7) + '-' + phone.substring(7, 11);
}
}
Loading