Skip to content

Commit

Permalink
v2.3.6 (#778)
Browse files Browse the repository at this point in the history
  • Loading branch information
uwoobeat authored Sep 19, 2024
2 parents 89856b2 + add30b8 commit b99bf85
Show file tree
Hide file tree
Showing 37 changed files with 168 additions and 112 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ dependencies {

// Sentry
implementation 'io.sentry:sentry-logback:7.14.0'
implementation 'io.sentry:sentry-openfeign:7.14.0'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void validateVerifyDiscordCode(
}

public void validateAdminPermission(Member currentMember) {
if (!currentMember.getManageRole().equals(MemberManageRole.ADMIN)) {
if (currentMember.getManageRole() != MemberManageRole.ADMIN) {
throw new CustomException(INVALID_ROLE);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void validateStatusUpdatable() {
* 준회원 승급 가능 여부를 검증합니다.
*/
private void validateAssociateAvailable() {
if (role.equals(ASSOCIATE)) {
if (isAssociate()) {
throw new CustomException(MEMBER_ALREADY_ASSOCIATE);
}

Expand All @@ -152,7 +152,7 @@ private void validateRegularAvailable() {
throw new CustomException(MEMBER_ALREADY_REGULAR);
}

if (!role.equals(ASSOCIATE)) {
if (!isAssociate()) {
throw new CustomException(MEMBER_NOT_ASSOCIATE);
}
}
Expand Down Expand Up @@ -335,26 +335,26 @@ public void updateMemberInfo(

// 데이터 전달 로직
public boolean isGuest() {
return role.equals(GUEST);
return role == GUEST;
}

public boolean isAssociate() {
return role.equals(ASSOCIATE);
return role == ASSOCIATE;
}

public boolean isRegular() {
return role.equals(REGULAR);
return role == REGULAR;
}

public boolean isAdmin() {
return manageRole.equals(ADMIN);
return manageRole == ADMIN;
}

public boolean isMentor() {
return studyRole.equals(MENTOR);
return studyRole == MENTOR;
}

public boolean isStudent() {
return studyRole.equals(STUDENT);
return studyRole == STUDENT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public enum MemberStatus {
private final String value;

public boolean isDeleted() {
return this.equals(DELETED);
return this == DELETED;
}

public boolean isForbidden() {
return this.equals(FORBIDDEN);
return this == FORBIDDEN;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public void verifyPaymentStatus(String orderNanoId) {
findMembershipAndVerifyPayment(membershipId);
}

@Transactional
public void verifyPaymentStatus(Long membershipId) {
findMembershipAndVerifyPayment(membershipId);
}

private void findMembershipAndVerifyPayment(Long membershipId) {
Membership currentMembership = membershipRepository
.findById(membershipId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static Membership createMembership(Member member, RecruitmentRound recrui

// 검증 로직

public void validateRegularRequirement() {
private void validateRegularRequirement() {
if (isRegularRequirementAllSatisfied()) {
throw new CustomException(MEMBERSHIP_ALREADY_SATISFIED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ public void validatePeriodNotStarted() {
}

public boolean isFirstRound() {
return roundType.equals(RoundType.FIRST);
return roundType == RoundType.FIRST;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gdschongik.gdsc.domain.recruitment.domain;

import static com.gdschongik.gdsc.domain.recruitment.domain.RoundType.*;
import static com.gdschongik.gdsc.global.common.constant.TemporalConstant.*;
import static com.gdschongik.gdsc.global.exception.ErrorCode.*;

Expand Down Expand Up @@ -67,7 +66,7 @@ private void validatePeriodOverlap(
// 학년도, 학기, 모집회차가 모두 같은 경우
private void validateRoundOverlap(List<RecruitmentRound> recruitmentRounds, RoundType roundType) {
recruitmentRounds.stream()
.filter(recruitmentRound -> recruitmentRound.getRoundType().equals(roundType))
.filter(recruitmentRound -> recruitmentRound.getRoundType() == roundType)
.findAny()
.ifPresent(ignored -> {
throw new CustomException(RECRUITMENT_ROUND_TYPE_OVERLAP);
Expand All @@ -76,14 +75,14 @@ private void validateRoundOverlap(List<RecruitmentRound> recruitmentRounds, Roun

// 1차 모집이 없는데 2차 모집을 생성하려고 하는 경우
private void validateRoundOneExist(List<RecruitmentRound> recruitmentRounds, RoundType roundType) {
if (roundType.equals(SECOND) && recruitmentRounds.stream().noneMatch(RecruitmentRound::isFirstRound)) {
if (roundType.isSecond() && recruitmentRounds.stream().noneMatch(RecruitmentRound::isFirstRound)) {
throw new CustomException(ROUND_ONE_DOES_NOT_EXIST);
}
}

// 1차 모집을 비워둬서는 안되므로, 1차 모집을 2차 모집으로 수정하려고 하는 경우 예외 발생
private void validateRoundOneToTwo(RoundType previousRoundType, RoundType newRoundType) {
if (previousRoundType.equals(FIRST) && newRoundType.equals(SECOND)) {
if (previousRoundType.isFirst() && newRoundType.isSecond()) {
throw new CustomException(ROUND_ONE_DOES_NOT_EXIST);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ public enum RoundType {
SECOND("2차");

private final String value;

public boolean isFirst() {
return this == FIRST;
}

public boolean isSecond() {
return this == SECOND;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,15 @@ public void attend(Long studyDetailId, StudyAttendCreateRequest request) {
final Study study = studyDetail.getStudy();
final boolean isAlreadyAttended =
attendanceRepository.existsByStudentIdAndStudyDetailId(currentMember.getId(), studyDetailId);
final StudyHistory studyHistory = studyHistoryRepository
.findByStudentAndStudy(currentMember, study)
.orElseThrow(() -> new CustomException(STUDY_HISTORY_NOT_FOUND));
boolean isAppliedToStudy = studyHistoryRepository.existsByStudentAndStudy(currentMember, study);

attendanceValidator.validateAttendance(
studyDetail, request.attendanceNumber(), LocalDate.now(), isAlreadyAttended);
studyDetail, request.attendanceNumber(), LocalDate.now(), isAlreadyAttended, isAppliedToStudy);

Attendance attendance = Attendance.create(currentMember, studyDetail);
attendanceRepository.save(attendance);

log.info("[StudyService] 스터디 출석: attendanceId={}", attendance.getId());
log.info("[StudyService] 스터디 출석: attendanceId={}, memberId={}", attendance.getId(), currentMember.getId());
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@

@DomainService
public class AttendanceValidator {

public void validateAttendance(
StudyDetail studyDetail, String attendanceNumber, LocalDate date, boolean isAlreadyAttended) {
StudyDetail studyDetail,
String attendanceNumber,
LocalDate date,
boolean isAlreadyAttended,
boolean isAppliedToStudy) {
// 출석체크 날짜 검증
LocalDate attendanceDay = studyDetail.getAttendanceDay();
if (!attendanceDay.equals(date)) {
Expand All @@ -25,5 +30,10 @@ public void validateAttendance(
if (isAlreadyAttended) {
throw new CustomException(STUDY_DETAIL_ALREADY_ATTENDED);
}

// 스터디 신청 여부 검증
if (!isAppliedToStudy) {
throw new CustomException(STUDY_HISTORY_NOT_FOUND);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.gdschongik.gdsc.global.common.constant;

import java.util.List;

public class SentryConstant {

private SentryConstant() {}

public static final String ACTUATOR_KEYWORD = "actuator";

public static final List<String> KEYWORDS_TO_IGNORE = List.of(ACTUATOR_KEYWORD);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@
import com.gdschongik.gdsc.global.property.DockerProperty;
import io.sentry.Sentry;
import io.sentry.SentryOptions;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.servlet.resource.NoResourceFoundException;

@Configuration
@RequiredArgsConstructor
public class SentryConfig {

private final DockerProperty dockerProperty;

private final List<Class<? extends Throwable>> exceptionsToIgnore = List.of(
NoResourceFoundException.class, // 존재하지 않는 정적 리소스 요청
MethodArgumentNotValidException.class // @Valid 검증 실패
);

@Bean
Sentry.OptionsConfiguration<SentryOptions> customOptionsConfiguration() {
return options -> {
options.setRelease(convertTagToRelease(dockerProperty.getTag()));
exceptionsToIgnore.forEach(options::addIgnoredExceptionForType);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public enum ErrorCode {
STUDY_DETAIL_ASSIGNMENT_INVALID_UPDATE_DEADLINE(HttpStatus.CONFLICT, "수정하려고 하는 과제의 마감기한은 기존의 마감기한보다 빠르면 안됩니다."),
STUDY_DETAIL_ID_INVALID(HttpStatus.CONFLICT, "수정하려는 스터디 상세정보가 서버에 존재하지 않거나 유효하지 않습니다."),
STUDY_DETAIL_CURRICULUM_SIZE_MISMATCH(HttpStatus.BAD_REQUEST, "스터디 커리큘럼의 총 개수가 일치하지 않습니다."),

// StudyHistory
STUDY_HISTORY_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 스터디 수강 기록입니다."),
STUDY_HISTORY_DUPLICATE(HttpStatus.CONFLICT, "이미 해당 스터디를 신청했습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import feign.Capability;
import feign.Logger;
import feign.codec.Decoder;
import feign.jackson.JacksonDecoder;
import io.sentry.openfeign.SentryCapability;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignFormatterRegistrar;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -41,4 +43,9 @@ public FeignFormatterRegistrar dateTimeFormatterRegistrar() {
registrar.registerFormatters(registry);
};
}

@Bean
public Capability sentryCapability() {
return new SentryCapability();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.gdschongik.gdsc.infra.sentry;

import static com.gdschongik.gdsc.global.common.constant.SentryConstant.*;

import io.sentry.Hint;
import io.sentry.SentryOptions;
import io.sentry.protocol.SentryTransaction;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

@Component
public class CustomBeforeSendTransactionCallback implements SentryOptions.BeforeSendTransactionCallback {

@Override
public SentryTransaction execute(@NotNull SentryTransaction transaction, @NotNull Hint hint) {
String transactionEndpoint = transaction.getTransaction();

if (transactionEndpoint == null) {
return transaction;
}

if (KEYWORDS_TO_IGNORE.stream().anyMatch(transactionEndpoint::contains)) {
return null;
}

return transaction;
}
}
4 changes: 2 additions & 2 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ spring:

logging:
level:
org.springframework.orm.jpa: DEBUG
org.springframework.transaction: DEBUG
com.gdschongik.gdsc.domain.*.api.*: info
com.gdschongik.gdsc.infra.feign: debug
7 changes: 5 additions & 2 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ spring:
properties:
hibernate:
format_sql: ${FORMAT_SQL:true}
highlight_sql: ${HIGHLIGHT_SQL:true}
defer-datasource-initialization: true
open-in-view: false

logging:
level:
org.springframework.orm.jpa: DEBUG
org.springframework.transaction: DEBUG
com.gdschongik.gdsc.domain.*.api.*: debug
com.gdschongik.gdsc.infra.feign: debug
org.hibernate.orm.jdbc.bind: trace
org.hibernate.SQL: debug
org.kohsuke.github: debug
3 changes: 1 addition & 2 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ spring:

logging:
level:
org.springframework.orm.jpa: DEBUG
org.springframework.transaction: DEBUG
com.gdschongik.gdsc.domain.*.api.*: info
2 changes: 1 addition & 1 deletion src/main/resources/application-sentry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sentry:
environment: ${spring.profiles.active:local}
send-default-pii: true
logging:
minimum-event-level: info
minimum-event-level: warn
minimum-breadcrumb-level: debug

docker:
Expand Down
3 changes: 1 addition & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ spring:

logging:
level:
com.gdschongik.gdsc.domain.*.api.*: debug
com.gdschongik.gdsc.infra.feign: debug
com.gdschongik.gdsc.domain.*.api.*: info
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gdschongik.gdsc.domain.member.domain;

import static com.gdschongik.gdsc.global.common.constant.RecruitmentConstant.*;
import static com.gdschongik.gdsc.global.common.constant.TemporalConstant.*;
import static com.gdschongik.gdsc.global.exception.ErrorCode.*;
import static org.assertj.core.api.Assertions.*;

Expand Down
Loading

0 comments on commit b99bf85

Please sign in to comment.