Skip to content

Commit

Permalink
feat: 단체 정보에 사용자 북마크 여부 함께 반환 (#335)
Browse files Browse the repository at this point in the history
* feat: CompanyType에 Education 추가

* feat: Organization 반환 시 isBookmarked 추가
  • Loading branch information
kimday0326 authored Jun 27, 2024
1 parent ecc0fba commit 4e8cfeb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.sponus.coredomain.domain.bookmark.Bookmark;
import com.sponus.coredomain.domain.bookmark.repository.BookmarkRepository;
import com.sponus.coredomain.domain.organization.Organization;
import com.sponus.coredomain.domain.organization.repository.OrganizationLinkRepository;
import com.sponus.coredomain.domain.organization.repository.OrganizationRepository;
import com.sponus.sponusbe.domain.bookmark.dto.request.BookmarkToggleRequest;
import com.sponus.sponusbe.domain.bookmark.dto.response.BookmarkToggleResponse;
Expand Down Expand Up @@ -45,5 +44,4 @@ public BookmarkToggleResponse bookmarkToggle(Organization organization, Bookmark
});
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public record OrganizationGetResponse(
int bookmarkCount,
int viewCount,
OrganizationType organizationType,
String subType
String subType,
boolean isBookmarked
) {
public static OrganizationGetResponse of(Organization organization) {

public static OrganizationGetResponse of(Organization organization, boolean isBookmarked) {
return OrganizationGetResponse.builder()
.id(organization.getId())
.name(organization.getName())
Expand All @@ -28,6 +30,7 @@ public static OrganizationGetResponse of(Organization organization) {
.viewCount(organization.getViewCount())
.organizationType(organization.getOrganizationType())
.subType(organization.getSubType())
.isBookmarked(isBookmarked)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public ApiResponse<Long> join(@RequestBody OrganizationCreateRequest request) {

@GetMapping
public ApiResponse<PageResponse<OrganizationGetResponse>> getOrganizations(
@AuthOrganization Organization authOrganization,
@ModelAttribute @Valid PageCondition pageCondition,
@ModelAttribute @Valid OrganizationType organizationType) {
return ApiResponse.onSuccess(organizationService.getOrganizations(pageCondition, organizationType));
return ApiResponse.onSuccess(
organizationService.getOrganizations(authOrganization, pageCondition, organizationType));
}

@PostMapping(value = "/{organizationId}/profileImage", consumes = "multipart/form-data")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
Expand All @@ -13,6 +14,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import com.sponus.coredomain.domain.bookmark.repository.BookmarkRepository;
import com.sponus.coredomain.domain.organization.Club;
import com.sponus.coredomain.domain.organization.Company;
import com.sponus.coredomain.domain.organization.Organization;
Expand Down Expand Up @@ -40,6 +42,7 @@
@RequiredArgsConstructor
public class OrganizationService {
private final OrganizationRepository organizationRepository;
private final BookmarkRepository bookmarkRepository;
private final S3Service s3Service;
private final PasswordEncoder passwordEncoder;
private final SearchHistoryRepository searchHistoryRepository;
Expand Down Expand Up @@ -75,12 +78,21 @@ private Organization findOrganizationById(Long organizationId) {
}

public PageResponse<OrganizationGetResponse> getOrganizations(
Organization authOrganization,
PageCondition pageCondition,
OrganizationType organizationType) {
// TODO: FETCH JOIN으로 변경
Set<Long> bookmarkedOrganizationIds = bookmarkRepository.findByOrganization(authOrganization).stream()
.map((bookmark) -> bookmark.getTarget().getId())
.collect(Collectors.toSet());
Pageable pageable = PageRequest.of(pageCondition.getPage() - 1, pageCondition.getSize());
List<OrganizationGetResponse> organizations = organizationRepository.findOrganizations(
organizationType, pageable).stream()
.map(OrganizationGetResponse::of).toList();
organizationType, pageable)
.stream()
.map(organization ->
OrganizationGetResponse.of(organization, bookmarkedOrganizationIds.contains(organization.getId())))
.toList();

return PageResponse.of(
PageableExecutionUtils.getPage(organizations, pageable,
() -> organizationRepository.countByOrganizationType(organizationType)));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.sponus.coredomain.domain.organization.enums;

public enum CompanyType {
NONE, FOOD, HEALTH, LIFESTYLE, BEAUTY, ETC
NONE, FOOD, HEALTH, LIFESTYLE, BEAUTY, EDUCATION, ETC
}

0 comments on commit 4e8cfeb

Please sign in to comment.