Skip to content

Commit

Permalink
Merge branch 'dev' into feat/#863
Browse files Browse the repository at this point in the history
  • Loading branch information
seokjin8678 committed Apr 20, 2024
2 parents 415228a + 1d34181 commit 1a43cfd
Show file tree
Hide file tree
Showing 60 changed files with 960 additions and 975 deletions.
1 change: 0 additions & 1 deletion backend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
implementation("org.springframework.boot:spring-boot-starter-mail")
implementation("org.springframework.boot:spring-boot-starter-cache")
implementation("org.springframework.boot:spring-boot-starter-actuator")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public Optional<AdminFestivalDetailV1Response> findDetail(Long festivalId) {
festival.name,
school.id,
school.name,
festival.startDate,
festival.endDate,
festival.thumbnail,
festival.festivalDuration.startDate,
festival.festivalDuration.endDate,
festival.posterImageUrl,
festival.createdAt,
festival.updatedAt
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public Page<AdminFestivalV1Response> findAll(SearchCondition searchCondition) {
festival.id,
festival.name,
school.name,
festival.startDate,
festival.endDate,
festival.festivalDuration.startDate,
festival.festivalDuration.endDate,
stage.count()
))
.from(festival)
Expand Down Expand Up @@ -88,8 +88,8 @@ private OrderSpecifier<?> getOrderSpecifier(Sort sort) {
case "id" -> OrderSpecifierUtils.of(it.getDirection(), festival.id);
case "name" -> OrderSpecifierUtils.of(it.getDirection(), festival.name);
case "schoolName" -> OrderSpecifierUtils.of(it.getDirection(), school.name);
case "startDate" -> OrderSpecifierUtils.of(it.getDirection(), festival.startDate);
case "endDate" -> OrderSpecifierUtils.of(it.getDirection(), festival.endDate);
case "startDate" -> OrderSpecifierUtils.of(it.getDirection(), festival.festivalDuration.startDate);
case "endDate" -> OrderSpecifierUtils.of(it.getDirection(), festival.festivalDuration.endDate);
default -> OrderSpecifierUtils.NULL;
})
.orElse(OrderSpecifierUtils.NULL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ private JPAQuery<ArtistFestivalDetailV1Response> selectArtistDetailResponse(Long
new QArtistFestivalDetailV1Response(
festival.id,
festival.name,
festival.startDate,
festival.endDate,
festival.thumbnail,
festival.festivalDuration.startDate,
festival.festivalDuration.endDate,
festival.posterImageUrl,
festivalQueryInfo.artistInfo))
.from(stageArtist)
.innerJoin(stage).on(stageArtist.artistId.eq(artistId).and(stage.id.eq(stageArtist.stageId)))
Expand All @@ -124,26 +124,26 @@ private boolean hasCursor(LocalDate lastStartDate, Long lastFestivalId) {

private BooleanExpression getCursorBasedWhere(boolean isPast, LocalDate lastStartDate, Long lastFestivalId) {
if (isPast) {
return festival.startDate.lt(lastStartDate)
.or(festival.startDate.eq(lastStartDate)
return festival.festivalDuration.startDate.lt(lastStartDate)
.or(festival.festivalDuration.startDate.eq(lastStartDate)
.and(festival.id.gt(lastFestivalId)));
}
return festival.startDate.gt(lastStartDate)
.or(festival.startDate.eq(lastStartDate)
return festival.festivalDuration.startDate.gt(lastStartDate)
.or(festival.festivalDuration.startDate.eq(lastStartDate)
.and(festival.id.gt(lastFestivalId)));
}

private BooleanExpression getDefaultWhere(boolean isPast, LocalDate currentTime) {
if (isPast) {
return festival.endDate.lt(currentTime);
return festival.festivalDuration.endDate.lt(currentTime);
}
return festival.endDate.goe(currentTime);
return festival.festivalDuration.endDate.goe(currentTime);
}

private OrderSpecifier<LocalDate>[] getDynamicOrderBy(Boolean isPast) {
if (isPast) {
return new OrderSpecifier[]{festival.endDate.desc()};
return new OrderSpecifier[]{festival.festivalDuration.endDate.desc()};
}
return new OrderSpecifier[]{festival.startDate.asc(), festival.id.asc()};
return new OrderSpecifier[]{festival.festivalDuration.startDate.asc(), festival.id.asc()};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public List<FestivalBookmarkV1Response> findBookmarkedFestivals(
new QFestivalV1Response(
festival.id,
festival.name,
festival.startDate,
festival.endDate,
festival.thumbnail,
festival.festivalDuration.startDate,
festival.festivalDuration.endDate,
festival.posterImageUrl,
new QSchoolV1Response(
school.id,
school.name
Expand All @@ -65,7 +65,7 @@ public List<FestivalBookmarkV1Response> findBookmarkedFestivals(
private OrderSpecifier<?> dynamicOrder(FestivalBookmarkOrder festivalBookmarkOrder) {
return switch (festivalBookmarkOrder) {
case BOOKMARK -> bookmark.id.desc();
case FESTIVAL -> festival.startDate.asc();
case FESTIVAL -> festival.festivalDuration.startDate.asc();
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.event.Level;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
Expand All @@ -31,14 +30,12 @@ public class LogRequestBodyAspect {

private final Map<Level, BiConsumer<String, String>> loggerMap = new EnumMap<>(Level.class);
private final ObjectMapper objectMapper;
private final Logger errorLogger;

public LogRequestBodyAspect(ObjectMapper objectMapper, Logger errorLogger) {
public LogRequestBodyAspect(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
this.errorLogger = errorLogger;
loggerMap.put(Level.INFO, this.errorLogger::info);
loggerMap.put(Level.WARN, this.errorLogger::warn);
loggerMap.put(Level.ERROR, this.errorLogger::error);
loggerMap.put(Level.INFO, log::info);
loggerMap.put(Level.WARN, log::warn);
loggerMap.put(Level.ERROR, log::error);
}

@Around("@annotation(LogRequestBody)")
Expand All @@ -49,7 +46,7 @@ public Object handleAll(ProceedingJoinPoint pjp) throws Throwable {
Level level = annotation.level();
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();

if (attributes == null || !errorLogger.isEnabledForLevel(level)) {
if (attributes == null || !log.isEnabledForLevel(level)) {
return pjp.proceed();
}
HttpServletRequest request = attributes.getRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
Expand All @@ -31,6 +32,7 @@
@RequiredArgsConstructor
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

private static final Logger log = LoggerFactory.getLogger("ErrorLogger");
private static final String LOG_FORMAT_INFO = "\n[🔵INFO] - ({} {})\n(id: {}, role: {})\n{}\n {}: {}";
private static final String LOG_FORMAT_WARN = "\n[🟠WARN] - ({} {})\n(id: {}, role: {})";
private static final String LOG_FORMAT_ERROR = "\n[🔴ERROR] - ({} {})\n(id: {}, role: {})";
Expand Down Expand Up @@ -60,7 +62,6 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
*/

private final AuthenticateContext authenticateContext;
private final Logger errorLogger;

@ExceptionHandler(InvalidMediaTypeException.class)
public ResponseEntity<ErrorResponse> handle(InvalidMediaTypeException e) {
Expand Down Expand Up @@ -133,23 +134,17 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(
}

private void logInfo(FestaGoException e, HttpServletRequest request) {
if (errorLogger.isInfoEnabled()) {
errorLogger.info(LOG_FORMAT_INFO, request.getMethod(), request.getRequestURI(), authenticateContext.getId(),
authenticateContext.getRole(), e.getErrorCode(), e.getClass().getName(), e.getMessage());
}
log.info(LOG_FORMAT_INFO, request.getMethod(), request.getRequestURI(), authenticateContext.getId(),
authenticateContext.getRole(), e.getErrorCode(), e.getClass().getName(), e.getMessage());
}

private void logWarn(FestaGoException e, HttpServletRequest request) {
if (errorLogger.isWarnEnabled()) {
errorLogger.warn(LOG_FORMAT_WARN, request.getMethod(), request.getRequestURI(),
authenticateContext.getId(), authenticateContext.getRole(), e);
}
log.warn(LOG_FORMAT_WARN, request.getMethod(), request.getRequestURI(),
authenticateContext.getId(), authenticateContext.getRole(), e);
}

private void logError(Exception e, HttpServletRequest request) {
if (errorLogger.isErrorEnabled()) {
errorLogger.error(LOG_FORMAT_ERROR, request.getMethod(), request.getRequestURI(),
authenticateContext.getId(), authenticateContext.getRole(), e);
}
log.error(LOG_FORMAT_ERROR, request.getMethod(), request.getRequestURI(),
authenticateContext.getId(), authenticateContext.getRole(), e);
}
}
15 changes: 0 additions & 15 deletions backend/src/main/java/com/festago/config/ErrorLoggerConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ public class FestivalCreateService {

public Long createFestival(FestivalCreateCommand command) {
School school = schoolRepository.getOrThrow(command.schoolId());
Festival festival = festivalRepository.save(command.toEntity(school));
Festival festival = command.toEntity(school);
validate(festival);
festivalRepository.save(festival);
eventPublisher.publishEvent(new FestivalCreatedEvent(festival.getId()));
return festival.getId();
}

private void validate(Festival festival) {
if (festival.isBeforeStartDate(LocalDate.now(clock))) {
if (festival.isStartDateBeforeTo(LocalDate.now(clock))) {
throw new BadRequestException(ErrorCode.INVALID_FESTIVAL_START_DATE);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.festago.festival.application.command;

import com.festago.festival.domain.Festival;
import com.festago.festival.domain.FestivalDuration;
import com.festago.festival.domain.validator.FestivalUpdateValidator;
import com.festago.festival.dto.command.FestivalUpdateCommand;
import com.festago.festival.repository.FestivalRepository;
Expand All @@ -23,8 +24,8 @@ public class FestivalUpdateService {
public void updateFestival(Long festivalId, FestivalUpdateCommand command) {
Festival festival = festivalRepository.getOrThrow(festivalId);
festival.changeName(command.name());
festival.changeThumbnail(command.posterImageUrl());
festival.changeDate(command.startDate(), command.endDate());
festival.changePosterImageUrl(command.posterImageUrl());
festival.changeFestivalDuration(new FestivalDuration(command.startDate(), command.endDate()));
validators.forEach(validator -> validator.validate(festival));
}
}
Loading

0 comments on commit 1a43cfd

Please sign in to comment.