Skip to content

Commit

Permalink
Merge pull request #26 from Mojacknong/feature_25/유저-정보-조회
Browse files Browse the repository at this point in the history
Feature 25/유저 정보 조회
  • Loading branch information
Ryeolee authored Nov 15, 2023
2 parents 0bd2ee0 + 93d5f89 commit 6759a6e
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD

on:
push:
branches: ["feature_21/-유저-오픈-페인-API"]
branches: ["feature_25/유저-정보-조회"]

pull_request:
branches: ["dev"]
Expand Down
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 All @@ -47,10 +57,10 @@ public BaseResponseDto emitNickname(HttpServletRequest request, @RequestBody Pro
}

@PostMapping(value = "/select-information", produces = MediaType.APPLICATION_JSON_VALUE)
public BaseResponseDto selectProfileImageAndNickname(HttpServletRequest request, @RequestParam(value = "file", required = false) MultipartFile multipartFile, @RequestParam("nickName")String nickName) throws IOException {
public BaseResponseDto selectProfileImageAndNickname(HttpServletRequest request, @RequestPart(value = "file", required = false) MultipartFile multipartFile, @RequestParam("nickName")String nickName) throws IOException {

String userId = jwtTokenProvider.getUserId(request);
log.info(userId);

BaseResponseDto responseDto = userService.selectProfileImageAndNickname(Long.valueOf(userId), multipartFile,nickName);

return responseDto;
Expand Down Expand Up @@ -91,11 +101,6 @@ public BaseResponseDto deleteUser(HttpServletRequest request){
return responseDto;
}






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

Expand All @@ -122,6 +127,15 @@ public BaseResponseDto reissueToken(HttpServletRequest request) {
return reissueTokenResponseDto;
}

@PatchMapping(value = "/delete/user-profile")
public BaseResponseDto deleteUserProfile(HttpServletRequest request) {

String userId = jwtTokenProvider.getUserId(request);

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


@GetMapping(value = "/all-user")
public BaseResponseDto allUser() {

Expand All @@ -135,6 +149,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 @@ -33,6 +33,10 @@ public interface UserRepository extends JpaRepository<User, Long> {
@Query("update User as u set u.early = 0 where u.id = :userId")
void updateEarly( @Param("userId") Long userId);

@Modifying
@Query("update User as u set u.profileImage = null where u.id = :userId")
void updateUserProfileDefault( @Param("userId") Long userId);


// @Modifying
// @Query("update User as u set u.profileImage = :profileImage where u.id = :userId")
Expand Down
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 All @@ -51,7 +66,7 @@ public BaseResponseDto emitNickname(Long userId, String nickName){
return BaseResponseDto.of(SuccessMessage.SUCCESS,null);
}

public BaseResponseDto selectProfileImageAndNickname(Long userId,MultipartFile multipartFile,
public BaseResponseDto selectProfileImageAndNickname(Long userId, MultipartFile multipartFile,
String nickName) throws IOException {

if(multipartFile.isEmpty()){
Expand Down Expand Up @@ -105,6 +120,15 @@ public BaseResponseDto allUser() {

}

public BaseResponseDto deleteUserProfile(Long userId) {

userRepository.updateUserProfileDefault(userId);

log.info("유저 프로필 삭제 완료");
return BaseResponseDto.of(SuccessMessage.SUCCESS, null);

}

public BaseResponseDto specificUser(Long userId) {


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;

}


}

0 comments on commit 6759a6e

Please sign in to comment.