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

API 추가/수정 #90

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,13 @@ public BaseResponse<String> likePost(@RequestBody @Valid PostsRequest.PostIdRequ
postsService.likePost(userId, request.getPostId());
return new BaseResponse<>(null);
}

@Operation(summary = "대여 기록 삭제", description = "대여 기록 삭제 API")
@DeleteMapping("/history")
@ResponseStatus(HttpStatus.OK)
public BaseResponse<String> deletePostHistory(@RequestBody @Valid PostsRequest.BorrowHistRequest request) {
String userId = MDC.get(JWTUtil.MDC_USER_ID);
postsService.deleteBorrowHistory(userId, request.getBorrowSeq());
return new BaseResponse<>(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,9 @@ public static class ReviewRequest {
public static class PostIdRequest {
private String postId;
}

@Data
public static class BorrowHistRequest {
private Long borrowSeq;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ public interface PostsService {
PostsResponse.ReviewsResponse ViewReviewService(String userId, String postId);

void likePost(String userId, String postId);

void deleteBorrowHistory(String userId, Long borrowSeq);
}
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,12 @@ public void likePost(String userId, String postId) {
itemsLikeRepository.save(itemsLike);
}

@Transactional
@Override
public void deleteBorrowHistory(String userId, Long borrowSeq) {
itemsRepository.deleteBorrowHistory(userId, borrowSeq);
}


//모듈화 코드

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import site.billbill.apiserver.api.auth.dto.request.LocationRequest;
import site.billbill.apiserver.api.users.dto.request.BlacklistRequest;
import site.billbill.apiserver.api.users.dto.request.PasswordRequest;
import site.billbill.apiserver.api.users.dto.request.ProfileRequest;
import site.billbill.apiserver.api.users.dto.request.WithdrawRequest;
import site.billbill.apiserver.api.users.dto.response.*;
import site.billbill.apiserver.api.users.service.UserService;
Expand Down Expand Up @@ -158,4 +159,12 @@ public BaseResponse<String> updatePassword(@RequestBody PasswordRequest request)
public BaseResponse<List<CodeDetailJpaEntity>> getWithdrawCodeList() {
return new BaseResponse<>(userService.getWithdrawCodeList());
}

@Operation(summary = "회원 프로필 수정", description = "내 프로필을 수정하는 API")
@ResponseStatus(HttpStatus.OK)
@PatchMapping("/profile")
public BaseResponse<String> updateProfile(@RequestBody ProfileRequest request) {
userService.updateProfile(request);
return new BaseResponse<>(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package site.billbill.apiserver.api.users.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
public class ProfileRequest {
@Schema(description = "닉네임", example = "nickname")
private String nickname;
@Schema(description = "프로필 이미지 URL", example = "profile url")
private String profileUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import site.billbill.apiserver.api.auth.dto.request.DeviceRequest;
import site.billbill.apiserver.api.auth.dto.request.LocationRequest;
import site.billbill.apiserver.api.users.dto.request.PasswordRequest;
import site.billbill.apiserver.api.users.dto.request.ProfileRequest;
import site.billbill.apiserver.api.users.dto.request.WithdrawRequest;
import site.billbill.apiserver.api.users.dto.response.*;
import site.billbill.apiserver.common.utils.posts.ItemHistoryType;
Expand Down Expand Up @@ -39,4 +40,6 @@ public interface UserService {
void updatePassword(PasswordRequest request);

List<CodeDetailJpaEntity> getWithdrawCodeList();

void updateProfile(ProfileRequest request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import site.billbill.apiserver.api.auth.dto.request.DeviceRequest;
import site.billbill.apiserver.api.auth.dto.request.LocationRequest;
import site.billbill.apiserver.api.users.dto.request.PasswordRequest;
import site.billbill.apiserver.api.users.dto.request.ProfileRequest;
import site.billbill.apiserver.api.users.dto.request.WithdrawRequest;
import site.billbill.apiserver.api.users.dto.response.*;
import site.billbill.apiserver.common.enums.exception.ErrorCode;
Expand Down Expand Up @@ -225,6 +226,13 @@ public List<CodeDetailJpaEntity> getWithdrawCodeList() {
return codeDetailRepository.findByIdGroupCodeOrderBySeqAsc("WITHDRAW_CODE");
}

@Override
@Transactional
public void updateProfile(ProfileRequest request) {
String userId = MDC.get(JWTUtil.MDC_USER_ID);
userRepository.updateProfileById(userId, request);
}


/**
* Method that check password is right
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public interface ItemDslRepository {

List<WishlistResponse> getWishlists(String userId, Pageable pageable);

void deleteBorrowHistory(String userId, Long borrowSeq);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import site.billbill.apiserver.api.users.dto.response.BorrowHistoryResponse;
import site.billbill.apiserver.api.users.dto.response.PostHistoryResponse;
import site.billbill.apiserver.api.users.dto.response.WishlistResponse;
import site.billbill.apiserver.common.enums.exception.ErrorCode;
import site.billbill.apiserver.common.utils.posts.ItemHistoryType;
import site.billbill.apiserver.exception.CustomException;
import site.billbill.apiserver.model.chat.QChatChannelJpaEntity;
import site.billbill.apiserver.model.post.*;
import site.billbill.apiserver.model.user.QUserJpaEntity;
import site.billbill.apiserver.model.user.UserJpaEntity;

import java.time.OffsetDateTime;
import java.util.List;

@Slf4j
Expand All @@ -31,7 +37,7 @@ public class ItemDslRepositoryImpl implements ItemDslRepository {
private final JPAQueryFactory queryFactory;

@Override
public Page<ItemsJpaEntity> findItemsWithConditions(String category, Pageable pageable, String sortField, String keyword,Double latitude,Double longitude) {
public Page<ItemsJpaEntity> findItemsWithConditions(String category, Pageable pageable, String sortField, String keyword, Double latitude, Double longitude) {
QItemsJpaEntity items = QItemsJpaEntity.itemsJpaEntity;
QItemsBorrowJpaEntity borrow = QItemsBorrowJpaEntity.itemsBorrowJpaEntity;
QItemsCategoryJpaEntity categoryEntity = QItemsCategoryJpaEntity.itemsCategoryJpaEntity;
Expand Down Expand Up @@ -279,4 +285,19 @@ public List<WishlistResponse> getWishlists(String userId, Pageable pageable) {

return qb.fetch();
}

@Override
public void deleteBorrowHistory(String userId, Long borrowSeq) {
QBorrowHistJpaEntity qBorrowHist = QBorrowHistJpaEntity.borrowHistJpaEntity;
QUserJpaEntity qUser = QUserJpaEntity.userJpaEntity;

UserJpaEntity user = queryFactory.selectFrom(qUser).where(qUser.userId.eq(userId)).fetchOne();
if(user == null) throw new CustomException(ErrorCode.NotFound, "회원 정보를 찾을 수 없습니다.", HttpStatus.NOT_FOUND);

queryFactory.update(qBorrowHist)
.set(qBorrowHist.delYn, true)
.set(qBorrowHist.updatedAt, OffsetDateTime.now())
.where(qBorrowHist.borrowSeq.eq(borrowSeq))
.execute();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package site.billbill.apiserver.repository.user;

import site.billbill.apiserver.api.users.dto.request.ProfileRequest;

public interface UserDslRepository {
void withdrawUserById(String userId);

void updateProfileById(String userId, ProfileRequest request);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package site.billbill.apiserver.repository.user;

import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.querydsl.jpa.impl.JPAUpdateClause;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import site.billbill.apiserver.api.users.dto.request.ProfileRequest;
import site.billbill.apiserver.model.user.QUserJpaEntity;

import java.time.OffsetDateTime;
Expand All @@ -23,4 +26,18 @@ public void withdrawUserById(String userId) {
.set(qUser.updatedAt, OffsetDateTime.now())
.execute();
}

@Override
public void updateProfileById(String userId, ProfileRequest request) {
QUserJpaEntity qUser = QUserJpaEntity.userJpaEntity;

JPAUpdateClause qb = query.update(qUser)
.where(qUser.userId.eq(userId))
.set(qUser.updatedAt, OffsetDateTime.now());

if (request.getNickname() != null) qb.set(qUser.nickname, request.getNickname());
if (request.getProfileUrl() != null) qb.set(qUser.profile, request.getProfileUrl());

qb.execute();
}
}
Loading