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

Feature 25/유저 정보 조회 #26

Merged
merged 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[feat] 유저 정보(+가입 후 경과 기간) API 완료
  • Loading branch information
Ryeolee committed Nov 11, 2023
commit 38dea3037b6fe487ab6ccf50545c48739ba3eb35
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ public class UserController {
//
// }

@GetMapping
public BaseResponseDto getUser(HttpServletRequest request){

String userId = jwtTokenProvider.getUserId(request);

return userService.getUser(Long.valueOf(userId));
}




@PostMapping(value = "/nickname")
public BaseResponseDto emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){
Expand Down Expand Up @@ -91,11 +101,6 @@ public BaseResponseDto deleteUser(HttpServletRequest request){
return responseDto;
}






@DeleteMapping("/logout")
public BaseResponseDto logout(HttpServletRequest request) {

Expand Down Expand Up @@ -135,6 +140,4 @@ public BaseResponseDto specificUser(@RequestParam("userId") Long userId) {
return userService.specificUser(userId);
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package modernfarmer.server.farmususer.user.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor(staticName = "of")
@Getter
public class GetUserResponseDto {

private String nickName;
private String userImageUrl;
private long dDay;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import modernfarmer.server.farmususer.user.entity.User;
import modernfarmer.server.farmususer.user.repository.UserRepository;
import modernfarmer.server.farmususer.user.util.JwtTokenProvider;
import modernfarmer.server.farmususer.user.util.TimeCalculator;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -30,6 +31,7 @@ public class UserService {
private final RedisTemplate<String, String> redisTemplate;
private final UserRepository userRepository;
private final S3Uploader s3Uploader;
private final TimeCalculator timeCalculator;


// public BaseResponseDto emitProfileImage(Long userId, MultipartFile multipartFile) throws IOException {
Expand All @@ -42,6 +44,19 @@ public class UserService {
// return BaseResponseDto.of(SuccessMessage.SUCCESS,null);
// }

public BaseResponseDto getUser(Long userId){

Optional<User> user = userRepository.findById(userId);

if(user.isEmpty()){
return BaseResponseDto.of(ErrorMessage.NO_USER_DATA);
}

long dDay = timeCalculator.calFromToday(user.get().getCreatedAt());

return BaseResponseDto.of(SuccessMessage.SUCCESS, GetUserResponseDto.of(user.get().getNickname(),user.get().getProfileImage(),dDay));
}



public BaseResponseDto emitNickname(Long userId, String nickName){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package modernfarmer.server.farmususer.user.util;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.springframework.stereotype.Component;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;


@Component
public class TimeCalculator {

public long calFromToday(LocalDateTime date){

LocalDateTime currentDateTime = LocalDateTime.now();

// 날짜 차이 계산
long daysDifference = ChronoUnit.DAYS.between(date.toLocalDate(), currentDateTime.toLocalDate());


return daysDifference;

}


}