Skip to content

Commit

Permalink
Merge pull request #29 from Nexters/yihyun/add/apis
Browse files Browse the repository at this point in the history
Chore change of APIs
  • Loading branch information
hyh1016 authored Aug 17, 2024
2 parents d723a12 + 3b47a9d commit 90247f2
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.nexters.gaetteok.common.filter;

import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;

import java.io.IOException;

@Slf4j
@Component
public class RequestLoggingFilter extends OncePerRequestFilter {

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
log.info("[{}] {}, token: {}, parameterCount: {}", request.getMethod(), request.getRequestURI(), request.getHeader("Authorization"), request.getParameterMap().values().size());
request.getParameterMap().forEach((key, value) -> log.info("Request Parameter: {}={}", key, value));
filterChain.doFilter(request, response);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.nexters.gaetteok.user.constant;

import lombok.Getter;

@Getter
public enum MainScreenImage {

BEFORE_WALKING("https://kr.object.ncloudstorage.com/gaetteok-image/home/home_beforewalking.png"),
AFTER_WALKING("https://kr.object.ncloudstorage.com/gaetteok-image/home/home_afterwalking.png"),
;

private final String imageUrl;

MainScreenImage(String imageUrl) {
this.imageUrl = imageUrl;
}

public static String getImageUrl(boolean walkDone) {
return walkDone ? AFTER_WALKING.imageUrl : BEFORE_WALKING.imageUrl;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
import com.nexters.gaetteok.domain.User;
import com.nexters.gaetteok.jwt.UserInfo;
import com.nexters.gaetteok.user.application.UserApplication;
import com.nexters.gaetteok.user.constant.MainScreenImage;
import com.nexters.gaetteok.user.presentation.request.ReportUserRequest;
import com.nexters.gaetteok.user.presentation.response.GetUserResponse;
import com.nexters.gaetteok.user.presentation.response.GetUserStatusResponse;
import com.nexters.gaetteok.user.presentation.response.ReportUserResponse;
import com.nexters.gaetteok.user.presentation.response.UpdateUserLocationResponse;
import com.nexters.gaetteok.walklog.application.WalkLogApplication;
import com.nexters.gaetteok.weather.enums.City;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -26,11 +29,14 @@
public class UserController implements UserSpecification {

private final UserApplication userApplication;
private final WalkLogApplication walkLogApplication;
private final AtomicInteger atomicInteger = new AtomicInteger(1);

@GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<GetUserResponse> getUser(UserInfo userInfo) {
return ResponseEntity.ok(GetUserResponse.of(userApplication.getUser(userInfo.getUserId())));
public ResponseEntity<GetUserStatusResponse> getUser(UserInfo userInfo) {
User user = userApplication.getUser(userInfo.getUserId());
boolean todayWalkLogExists = walkLogApplication.isTodayWalkLogExists(userInfo.getUserId());
return ResponseEntity.ok(GetUserStatusResponse.of(user, todayWalkLogExists, MainScreenImage.getImageUrl(todayWalkLogExists)));
}

@PatchMapping(value = "/nickname", produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.nexters.gaetteok.jwt.UserInfo;
import com.nexters.gaetteok.user.presentation.request.ReportUserRequest;
import com.nexters.gaetteok.user.presentation.response.GetUserResponse;
import com.nexters.gaetteok.user.presentation.response.GetUserStatusResponse;
import com.nexters.gaetteok.user.presentation.response.ReportUserResponse;
import com.nexters.gaetteok.user.presentation.response.UpdateUserLocationResponse;
import com.nexters.gaetteok.weather.enums.City;
Expand All @@ -28,10 +29,10 @@ public interface UserSpecification {
description = "유저 조회 성공",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = GetUserResponse.class)
schema = @Schema(implementation = GetUserStatusResponse.class)
)
)
ResponseEntity<GetUserResponse> getUser(
ResponseEntity<GetUserStatusResponse> getUser(
@Parameter(hidden = true) UserInfo userInfo
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.nexters.gaetteok.user.presentation.response;

import com.nexters.gaetteok.domain.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;

import java.time.LocalDateTime;

@Getter
public class GetUserStatusResponse {

@Schema(description = "유저 ID", example = "1")
private final long id;

@Schema(description = "유저 닉네임", example = "뽀삐")
private final String nickname;

@Schema(description = "유저 프로필 이미지 URL", example = "https://profile.com/1")
private final String profileImageUrl;

@Schema(description = "유저 코드", example = "1a2b3c")
private final String code;

@Schema(description = "산책 완료 여부", example = "true")
private final boolean walkDone;

@Schema(description = "메인 화면 이미지 URL", example = "https://main.com/wait.jpg")
private final String mainScreenImageUrl;

@Schema(description = "유저 생성일", example = "2021-08-01T00:00:00")
private final LocalDateTime createdAt;

@Builder
public GetUserStatusResponse(long id, String nickname, String profileImageUrl, String code, boolean walkDone, String mainScreenImageUrl, LocalDateTime createdAt) {
this.id = id;
this.nickname = nickname;
this.profileImageUrl = profileImageUrl;
this.code = code;
this.walkDone = walkDone;
this.mainScreenImageUrl = mainScreenImageUrl;
this.createdAt = createdAt;
}

public static GetUserStatusResponse of(User user, boolean walkDone, String mainScreenImageUrl) {
return GetUserStatusResponse.builder()
.id(user.getId())
.nickname(user.getNickname())
.profileImageUrl(user.getProfileUrl())
.code(user.getCode())
.walkDone(walkDone)
.mainScreenImageUrl(mainScreenImageUrl)
.createdAt(user.getCreatedAt())
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,18 @@
import com.nexters.gaetteok.walklog.mapper.WalkLogMapper;
import com.nexters.gaetteok.walklog.presentation.request.CreateWalkLogRequest;
import com.nexters.gaetteok.walklog.presentation.request.PatchWalkLogRequest;
import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -91,6 +90,8 @@ public WalkLog create(long userId, CreateWalkLogRequest request, MultipartFile p
.content(request.getContent())
.walkTime(request.getWalkTime())
.userId(userId)
.createdAt(LocalDateTime.now())
.updatedAt(LocalDateTime.now())
.build());
return WalkLogMapper.toDomain(walkLog, me);
}
Expand Down Expand Up @@ -226,10 +227,14 @@ public WalkLog update(long id, long userId, PatchWalkLogRequest request, Multipa
.content(request.getContent() != null ? request.getContent() : walkLog.getContent())
.userId(userId)
.walkTime(walkLog.getWalkTime())
.updatedAt(LocalDateTime.now())
.build()
);

return WalkLogMapper.toDomain(walkLog, me);
}

public boolean isTodayWalkLogExists(long userId) {
return walkLogRepository.isTodayWalkLogExists(userId, LocalDate.now());
}
}
4 changes: 4 additions & 0 deletions api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ spring:
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
servlet:
multipart:
max-file-size: 20MB
max-request-size: 20MB

ncloud:
accessKey: ${NCP_ACCESS_KEY}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

public enum WalkTime {

NONE("없음"), // 없음
WITHIN_20_MINUTES("20분 내외"), // 20분 내외
BETWEEN_20_AND_40_MINUTES("20분~40분"), // 20분~40분
BETWEEN_40_MINUTES_AND_1_HOUR("40분~1시간"), // 40분~1시간
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;

import java.time.LocalDateTime;

Expand Down Expand Up @@ -41,15 +42,19 @@ public class WalkLogEntity {
@Column(updatable = false)
private LocalDateTime createdAt;

@LastModifiedDate
private LocalDateTime updatedAt;

@Builder
public WalkLogEntity(long id, String photoUrl, String title, String content, WalkTime walkTime, long userId, LocalDateTime createdAt) {
public WalkLogEntity(long id, String photoUrl, String title, String content, WalkTime walkTime, long userId, LocalDateTime createdAt, LocalDateTime updatedAt) {
this.id = id;
this.photoUrl = photoUrl;
this.title = title;
this.content = content;
this.walkTime = walkTime;
this.userId = userId;
this.createdAt = createdAt;
this.updatedAt = updatedAt;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.nexters.gaetteok.domain.WalkLog;
import com.nexters.gaetteok.persistence.entity.WalkLogEntity;

import java.time.LocalDate;
import java.util.List;

public interface CustomWalkLogRepository {
Expand All @@ -17,4 +18,6 @@ public interface CustomWalkLogRepository {

WalkLogEntity getMaxIdLessThan(long walkLogId);

boolean isTodayWalkLogExists(long walkLogId, LocalDate date);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

import com.nexters.gaetteok.domain.WalkLog;
import com.nexters.gaetteok.persistence.entity.WalkLogEntity;
import com.querydsl.core.types.Ops;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

import static com.nexters.gaetteok.persistence.entity.QFriendEntity.friendEntity;
import static com.nexters.gaetteok.persistence.entity.QUserEntity.userEntity;
import static com.nexters.gaetteok.persistence.entity.QWalkLogEntity.walkLogEntity;
import static com.querydsl.core.types.dsl.Expressions.dateTimeOperation;

@Repository
@RequiredArgsConstructor
Expand Down Expand Up @@ -108,4 +111,20 @@ public WalkLogEntity getMaxIdLessThan(long walkLogId) {
.orderBy(walkLogEntity.id.desc())
.fetchFirst();
}

@Override
public boolean isTodayWalkLogExists(long userId, LocalDate date) {
Long id = jpaQueryFactory
.select(walkLogEntity.id)
.from(walkLogEntity)
.where(
walkLogEntity.userId.eq(userId),
dateTimeOperation(LocalDate.class, Ops.DateTimeOps.DATE, walkLogEntity.createdAt).eq(date)
)
.fetchFirst();

return id != null;
}


}

0 comments on commit 90247f2

Please sign in to comment.