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

fix: 수정 사항 반영 #43

Merged
merged 4 commits into from
Feb 9, 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ out/

### VS Code ###
.vscode/
/core/core-security/src/main/resources/key/AuthKey_X93DK84396.p8
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.mm.api.domain.admin.dto.response.WithdrawListResponse;
import com.mm.api.domain.admin.service.AdminService;
import com.mm.api.domain.buy.dto.response.BuyResponse;
import com.mm.api.domain.buy.service.BuyService;
import com.mm.api.domain.item.dto.response.ItemDetailResponse;

import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -29,7 +28,6 @@
@RequiredArgsConstructor
public class AdminController {
private final AdminService adminService;
private final BuyService buyService;

@Operation(summary = "url을 입력해 상품글을 크롤링합니다.", description = "zigzag url만 가능, ex) https://s.zigzag.kr/dV7jnGouAl?af=1")
@PostMapping("/items/crawl")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mm.api.domain.auth.controller;

import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -52,6 +53,13 @@ public CommonResponse<MemberInfoResponse> getMe(@AuthenticationPrincipal OAuth2U
return CommonResponse.ok(response);
}

@Operation(summary = "회원탈퇴를 합니다.")
@DeleteMapping("/api/v1/auth/withdrawal")
public CommonResponse<MemberInfoResponse> getWithdrawl(@AuthenticationPrincipal OAuth2UserDetails userDetails) {
authService.getWithdrawl(userDetails);
return CommonResponse.noContent();
}

@Operation(summary = "access token을 갱신합니다.", description = "Bearer 를 붙이지 말아주세요")
@PostMapping("/api/v1/auth/refresh-access-token")
public CommonResponse<TokenResponse> refreshAccessToken(@RequestBody RefreshTokenRequest request) {
Expand Down
10 changes: 10 additions & 0 deletions api/src/main/java/com/mm/api/domain/auth/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public MemberInfoResponse getMe(OAuth2UserDetails userDetails) {
return memberService.getMemberInfo(userDetails.getId());
}

public void getWithdrawl(OAuth2UserDetails userDetails) {
Member member = getMember(userDetails.getId());
memberRepository.delete(member);
}

private Member getMember(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new CustomException(ErrorCode.MEMBER_NOT_FOUND));
}

private KakaoAuthInfoResponse getKakaoAuthInfoResponse(KakaoAuthLoginResponse kakaoLoginAccessToken) {
return kakaoAuthInfoClient.getInfo("Bearer " + kakaoLoginAccessToken.accessToken());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mm.api.domain.dib.controller;

import java.util.List;

import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -37,10 +39,10 @@ public CommonResponse<?> postDib(@PathVariable Long itemId,
}

@Operation(summary = "특정 상품을 찜하기 취소 합니다.")
@DeleteMapping("/dib/{itemId}")
public CommonResponse<?> deleteDib(@PathVariable Long itemId,
@DeleteMapping("/dib/cancel")
public CommonResponse<?> deleteDib(@RequestParam List<Long> itemIds,
@AuthenticationPrincipal OAuth2UserDetails userDetails) {
dibService.deleteDib(itemId, userDetails);
dibService.deleteDib(itemIds, userDetails);
return CommonResponse.noContent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

import com.mm.api.domain.item.dto.response.ItemResponse;

public record DibListResponse(Boolean isLastPage, List<ItemResponse> itemResponses) {
public record DibListResponse(Boolean isLastPage, Long count, List<ItemResponse> itemResponses) {
}
20 changes: 14 additions & 6 deletions api/src/main/java/com/mm/api/domain/dib/service/DibService.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,21 @@ public void postDib(Long itemId, OAuth2UserDetails userDetails) {
dibRepository.save(dib);
}

public void deleteDib(Long itemId, OAuth2UserDetails userDetails) {
public void deleteDib(List<Long> itemIds, OAuth2UserDetails userDetails) {
Member member = getMember(userDetails.getId());
Item item = getItem(itemId);
List<Item> items = itemIds.stream()
.map(this::getItem)
.toList();

Dib dib = dibRepository.findByMemberAndItem(member, item)
.orElseThrow(() -> new CustomException(DIB_NOT_FOUND));
dibRepository.delete(dib);
items
.forEach(item -> {
Dib dib = dibRepository.findByMemberAndItem(member, item)
.orElseThrow(() -> new CustomException(DIB_NOT_FOUND));
dibRepository.delete(dib);
});
}

@Transactional(readOnly = true)
public DibListResponse getDibsMe(Integer page, OAuth2UserDetails userDetails) {
Member member = getMember(userDetails.getId());
List<Dib> dibs = dibCustomRepository.getDibsByPage(page, member);
Expand All @@ -82,7 +88,9 @@ public DibListResponse getDibsMe(Integer page, OAuth2UserDetails userDetails) {
Long pageNum = dibCustomRepository.getPageNum(member);
Boolean isLastPage = pageNum.equals(page.longValue());

return new DibListResponse(isLastPage, itemResponses);
long count = dibRepository.count();

return new DibListResponse(isLastPage, count, itemResponses);
}

private boolean isDibExist(Member member, Item item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import com.mm.api.common.response.CommonResponse;
import com.mm.api.common.swaggerAnnotation.SwaggerResponseSearch;
import com.mm.api.domain.item.dto.response.ItemListResponse;
import com.mm.api.domain.search.dto.SearchResponse;
import com.mm.api.domain.search.service.SearchService;
import com.mm.coresecurity.oauth.OAuth2UserDetails;

Expand All @@ -26,11 +26,11 @@ public class SearchController {

@Operation(summary = "키워드로 검색 합니다.")
@GetMapping("/search")
public CommonResponse<ItemListResponse> searchKeyword(
public CommonResponse<SearchResponse> searchKeyword(
@RequestParam(required = false, defaultValue = "1") Integer page,
@RequestParam String keyword,
@AuthenticationPrincipal OAuth2UserDetails userDetails) {
ItemListResponse itemResponses = searchService.searchKeyword(page, keyword, userDetails);
SearchResponse itemResponses = searchService.searchKeyword(page, keyword, userDetails);
return CommonResponse.ok(itemResponses);
}
}
10 changes: 10 additions & 0 deletions api/src/main/java/com/mm/api/domain/search/dto/SearchResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.mm.api.domain.search.dto;

import java.util.List;

import com.mm.api.domain.item.dto.response.ItemResponse;

public record SearchResponse(Boolean isLastPage,
Long count,
List<ItemResponse> itemResponses) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.springframework.transaction.annotation.Transactional;

import com.mm.api.domain.dib.service.DibService;
import com.mm.api.domain.item.dto.response.ItemListResponse;
import com.mm.api.domain.item.dto.response.ItemResponse;
import com.mm.api.domain.search.dto.SearchResponse;
import com.mm.coredomain.domain.Item;
import com.mm.coreinfraqdsl.repository.SearchCustomRepository;
import com.mm.coresecurity.oauth.OAuth2UserDetails;
Expand All @@ -23,7 +23,7 @@ public class SearchService {
private final DibService dibService;

@Transactional(readOnly = true)
public ItemListResponse searchKeyword(Integer page, String keyword, OAuth2UserDetails userDetails) {
public SearchResponse searchKeyword(Integer page, String keyword, OAuth2UserDetails userDetails) {
List<Item> items = searchCustomRepository.searchItems(page, keyword);
List<Boolean> dibs = dibService.getDib(items, userDetails);

Expand All @@ -35,6 +35,8 @@ public ItemListResponse searchKeyword(Integer page, String keyword, OAuth2UserDe
Long pageNum = searchCustomRepository.getPageNum(keyword);
Boolean isLastPage = pageNum.equals(page.longValue());

return new ItemListResponse(isLastPage, itemResponses);
Long count = searchCustomRepository.getSearchResultNumber(keyword);

return new SearchResponse(isLastPage, count, itemResponses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class AdminCustomRepositoryImpl implements AdminCustomRepository {
@Override
public List<Item> getItemsByPage(Integer page) {
return jpaQueryFactory.selectFrom(item)
.orderBy(item.id.desc())
.offset((page - 1) * PAGE_OFFSET)
.limit(PAGE_OFFSET)
.fetch();
Expand All @@ -45,6 +46,7 @@ public Long getItemsPageNum() {
public List<Buy> getBuysAdminByPage(Integer page) {
return jpaQueryFactory.selectFrom(buy)
.where(isBuy())
.orderBy(buy.id.desc())
.offset((page - 1) * PAGE_OFFSET)
.limit(PAGE_OFFSET)
.fetch();
Expand All @@ -66,6 +68,7 @@ public Long getBuysAdminPageNum() {
public List<Buy> getWithdrawsAdminByPage(Integer page) {
return jpaQueryFactory.selectFrom(buy)
.where(isWithdraw())
.orderBy(buy.id.desc())
.offset((page - 1) * PAGE_OFFSET)
.limit(PAGE_OFFSET)
.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
public interface SearchCustomRepository {
List<Item> searchItems(Integer page, String keyword);

Long getSearchResultNumber(String keyword);

Long getPageNum(String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ public List<Item> searchItems(Integer page, String keyword) {
.fetch();
}

@Override
public Long getSearchResultNumber(String keyword) {
return jpaQueryFactory.select(item.count())
.from(item)
.where(
containsKeyword(keyword)
)
.fetchOne();
}

private BooleanBuilder containsKeyword(String keyword) {
BooleanBuilder booleanBuilder = new BooleanBuilder();
if (keyword == null) {
Expand Down
4 changes: 4 additions & 0 deletions core/core-security/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ dependencies {
implementation 'io.jsonwebtoken:jjwt-api:0.12.3'
implementation 'io.jsonwebtoken:jjwt-impl:0.12.3'
implementation 'io.jsonwebtoken:jjwt-jackson:0.12.3'
implementation 'com.nimbusds:nimbus-jose-jwt'
implementation 'org.bouncycastle:bcpkix-jdk18on:1.73'

implementation 'commons-io:commons-io:2.6'

// redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
Expand Down
Loading
Loading