Skip to content

Commit

Permalink
�Api-Release-v0.0.2-20
Browse files Browse the repository at this point in the history
�Api-Release-v0.0.2-20
  • Loading branch information
imenuuu authored Dec 13, 2023
2 parents 73b3207 + 878c397 commit a539bd0
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
import com.example.matchdomain.user.entity.User;
import com.example.matchdomain.user.entity.enums.Gender;
import com.example.matchdomain.user.exception.UserAuthErrorCode;
import com.fasterxml.jackson.annotation.JsonFormat;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
Expand Down Expand Up @@ -93,7 +96,7 @@ public CommonResponse<String> updateNickname(@PathVariable Long userId, @Request

@PatchMapping("/birth/{userId}")
@Operation(summary = "ADMIN-02-07👤 유저 생일 수정 API.",description = "유저 생일 수정 API 입니다.")
public CommonResponse<String> updateBirth(@PathVariable Long userId, @RequestParam LocalDate birth){
public CommonResponse<String> updateBirth(@PathVariable Long userId, @DateTimeFormat(pattern = "yyyy-MM-dd") @RequestParam LocalDate birth){
adminUserService.updateBirth(userId, birth);
return CommonResponse.onSuccess("생일 수정 성공");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -75,33 +75,35 @@ public void unActivateUser(User user) {
donationService.deleteRegularPayment(user);
}

@Transactional
public void updateNickname(Long userId, String nickname) {
updateUserInfo(userId, user -> user.setNickname(nickname));
}

@Transactional
public void updatePhone(Long userId, String phone) {
if (userAdaptor.existsPhoneNumber(phone)) {
throw new ForbiddenException(USERS_EXISTS_PHONE);
}
updateUserInfo(userId, user -> user.setPhoneNumber(phone));
}

@Transactional
public void updateEmail(Long userId, String email) {
if (userAdaptor.existsEmail(email)) {
throw new ForbiddenException(USERS_EXISTS_EMAIL);
}
updateUserInfo(userId, user -> user.setEmail(email));
}

@Transactional
public void updateGender(Long userId, Gender gender) {
updateUserInfo(userId, user -> user.setGender(gender));
}

@Transactional
public void updateBirth(Long userId, LocalDate birth) {
updateUserInfo(userId, user -> user.setBirth(birth));
}

private void updateUserInfo(Long userId, Consumer<User> updateFunction) {
public void updateUserInfo(Long userId, Consumer<User> updateFunction) {
User user = findByUserId(userId);
updateFunction.accept(user);
userAdaptor.save(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public ResponseEntity onKnownDynamicException(BaseDynamicException baseDynamicEx
}


/*
@ExceptionHandler(value = Exception.class)
public ResponseEntity onException(Exception exception, @AuthenticationPrincipal User user,
HttpServletRequest request) {
Expand All @@ -105,6 +106,7 @@ public ResponseEntity onException(Exception exception, @AuthenticationPrincipal
return new ResponseEntity<>(CommonResponse.onFailure("500", exception.getMessage(), null), null,
HttpStatus.INTERNAL_SERVER_ERROR);
}
*/

private void getExceptionStackTrace(Exception e, User user, HttpServletRequest request, Map<String, String> errors) {
StringWriter sw = new StringWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public UserRes.UserList convertToUserList(UserRepository.UserList result) {
.name(result.getName())
.birth(String.valueOf(result.getBirth()))
.socialType(result.getSocialType().getName())
.gender(result.getGender().getValue())
.gender(result.getGender() == null ? null : result.getGender().getValue())
.email(result.getEmail())
.phoneNumber(result.getPhoneNumber())
.donationCnt(result.getDonationCnt())
Expand All @@ -186,14 +186,15 @@ public UserRes.UserAdminDetail convertToUserAdminDetail(UserRepository.UserList
.name(userDetail.getName())
.birth(String.valueOf(userDetail.getBirth()))
.socialType(userDetail.getSocialType().getName())
.gender(userDetail.getGender().getValue())
.gender(userDetail.getGender() == null ? null : userDetail.getGender().getValue())
.email(userDetail.getEmail())
.phoneNumber(userDetail.getPhoneNumber())
.donationCnt(userDetail.getDonationCnt())
.totalAmount(userDetail.getTotalAmount())
.card(userDetail.getCard())
.status(userDetail.getStatus().getValue())
.createdAt(userDetail.getCreatedAt().toString())
.nickname(userDetail.getNickname())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ public static class UserAdminDetail {
private String status;

private String createdAt;

private String nickname;
}

public static class EmailAuth {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import static com.example.matchdomain.user.entity.enums.SocialType.NORMAL;
import static com.example.matchdomain.user.exception.UserLoginErrorCode.NOT_EXIST_USER;

import javax.transaction.Transactional;

@Adaptor
@RequiredArgsConstructor
public class UserAdaptor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public interface UserRepository extends JpaRepository<User,Long> {
"FROM User U where name LIKE concat('%',:content,'%') order by createdAt desc" ,nativeQuery = true, countQuery = "select count(*) from User where name LIKE concat('%',:content,'%')")
Page<UserList> getUserListByName(Pageable pageable,@Param("content") String content);

@Query(value = "SELECT U.id 'userId', name, birth, socialType, gender, phoneNumber,email," +
@Query(value = "SELECT U.id 'userId', name, birth, socialType, gender, phoneNumber,email, nickname," +
"If((select exists (select * from UserCard UC where UC.userId=U.id)),'true','false')'card'," +
"(select count(*) from DonationUser DU where DU.userId = U.id)'donationCnt'," +
"COALESCE((SELECT SUM(DU.price) FROM DonationUser DU WHERE DU.userId = U.id), 0) AS totalAmount,U.status, U.createdAt " +
Expand Down Expand Up @@ -122,6 +122,8 @@ public interface UserList {

Status getStatus();

String getNickname();

LocalDateTime getCreatedAt();
}
}

0 comments on commit a539bd0

Please sign in to comment.