Skip to content

Commit

Permalink
[feat] 족보 공유 관련 API 분리, 시큐리티 whiteList에 추가 (#233)
Browse files Browse the repository at this point in the history
* [refac] Refactor api path, Add shared favaroite GET api

* [feat] Add shared favaroite GET api

* [feat] Add businessLogicWhileList path

* [feat] Add response dto
  • Loading branch information
PicturePark1101 authored Dec 25, 2024
1 parent 7b5942d commit 1434169
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteGetResponse;
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteUserNicknameGetResponse;
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteOwnershipGetResponse;
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteSharedGetResponse;
import org.hankki.hankkiserver.api.favorite.service.response.FavoritesWithStatusGetResponse;
import org.hankki.hankkiserver.auth.UserId;
import org.hankki.hankkiserver.common.code.CommonSuccessCode;
Expand Down Expand Up @@ -69,13 +70,13 @@ public HankkiResponse<FavoritesWithStatusGetResponse> getFavoritesWithStatus(@Us
return HankkiResponse.success(CommonSuccessCode.OK, favoriteQueryService.findFavoritesWithStatus(FavoritesWithStatusGetCommand.of(id, storeId)));
}

@PostMapping("/favorites/{favoriteId}/shared")
@PostMapping("/favorites/shared/{favoriteId}")
public HankkiResponse<Void> createSharedFavorite(@UserId final Long userId, @PathVariable(name = "favoriteId") long favoriteId, @RequestBody @Valid final FavoriteSharedPostRequest request) {
favoriteCommandService.createSharedFavorite(FavoriteSharedPostCommand.of(userId, favoriteId, request.title(), request.details()));
return HankkiResponse.success(CommonSuccessCode.CREATED);
}

@GetMapping("/favorites/{favoriteId}/ownership")
@GetMapping("/favorites/shared/{favoriteId}/ownership")
public HankkiResponse<FavoriteOwnershipGetResponse> checkFavoriteOwnership(@UserId Long userId, @PathVariable("favoriteId") final long favoriteId) {
return HankkiResponse.success(CommonSuccessCode.OK, favoriteQueryService.checkFavoriteOwnership(FavoriteOwnershipGetCommand.of(userId, favoriteId)));
}
Expand All @@ -84,4 +85,9 @@ public HankkiResponse<FavoriteOwnershipGetResponse> checkFavoriteOwnership(@User
public HankkiResponse<FavoriteUserNicknameGetResponse> getFavoriteUserNickname(@PathVariable("favoriteId") final long id) {
return HankkiResponse.success(CommonSuccessCode.OK, favoriteQueryService.getFavoriteUserNickname(id));
}

@GetMapping("/favorites/shared/{favoriteId}")
public HankkiResponse<FavoriteSharedGetResponse> getSharedFavorite(@PathVariable(name = "favoriteId") final long id) {
return HankkiResponse.success(CommonSuccessCode.OK, favoriteQueryService.findSharedFavorite(id));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.hankki.hankkiserver.api.favorite.service.command.FavoritesGetCommand;
import org.hankki.hankkiserver.api.favorite.service.command.FavoritesWithStatusGetCommand;
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteGetResponse;
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteSharedGetResponse;
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteUserNicknameGetResponse;
import org.hankki.hankkiserver.api.favorite.service.response.FavoriteOwnershipGetResponse;
import org.hankki.hankkiserver.api.favorite.service.response.FavoritesWithStatusGetResponse;
Expand Down Expand Up @@ -46,6 +47,12 @@ public FavoritesWithStatusGetResponse findFavoritesWithStatus(final FavoritesWit
LinkedHashMap::new)));
}

@Transactional(readOnly = true)
public FavoriteSharedGetResponse findSharedFavorite(final long id) {
Favorite favorite = favoriteFinder.findByIdWithFavoriteStore(id);
return FavoriteSharedGetResponse.of(favorite, getNicknameByOwnerId(getOwnerIdById(id)), findStoresInFavorite(favorite));
}

private boolean isStoreAlreadyAdded(final List<FavoriteStore> favoriteStore, final Long commandStoreId) {
return favoriteStore.stream()
.anyMatch(f -> f.getStore().getId().equals(commandStoreId));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.hankki.hankkiserver.api.favorite.service.response;

import static org.hankki.hankkiserver.api.favorite.service.response.util.FavoriteResponseUtil.transformDetail;

import java.util.List;
import org.hankki.hankkiserver.domain.favorite.model.Favorite;
import org.hankki.hankkiserver.domain.store.model.Store;

public record FavoriteSharedGetResponse(
String title,
List<String> details,
String nickname,
List<FavoriteSharedResponse> stores
) {
public static FavoriteSharedGetResponse of(final Favorite favorite, final String nickname, final List<Store> stores) {
return new FavoriteSharedGetResponse(
favorite.getName(),
transformDetail(favorite.getDetail()),
nickname,
stores.stream().map(FavoriteSharedResponse::of).toList());
}

record FavoriteSharedResponse(
Long id,
String name,
String imageUrl,
String category,
int lowestPrice,
int heartCount
) {
static FavoriteSharedResponse of(final Store store) {
return new FavoriteSharedResponse(
store.getId(),
store.getName(),
store.getImageUrlOrElseNull(),
store.getCategory().getName(),
store.getLowestPrice(),
store.getHeartCount());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class SecurityConfig {

private static final String[] authWhiteList = {"/api/v1/auth/login", "/api/v1/auth/reissue", "/actuator/health"};
private static final String[] businessLogicWhileList = {"/api/v1/stores/categories", "/api/v1/stores/sort-options", "/api/v1/stores/price-categories",
"/api/v1/stores", "/api/v1/stores/pins", "/api/v1/stores/{articleId:\\d+}/thumbnail", "/api/v1/universities"};
"/api/v1/stores", "/api/v1/stores/pins", "/api/v1/stores/{articleId:\\d+}/thumbnail", "/api/v1/universities", "/api/v1/favorites/shared/{favoriteId:\\d+}"};

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
Expand Down

0 comments on commit 1434169

Please sign in to comment.