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

[feat] 족보 공유 관련 API 분리, 시큐리티 whiteList에 추가 #233

Merged
merged 4 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -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,22 @@
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<FavoriteStoreResponse> 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(FavoriteStoreResponse::of).toList());
}
}
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