Skip to content
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
@@ -1,7 +1,7 @@
package com.somemore.domains.center.controller;
package com.somemore.center.controller;

import com.somemore.domains.center.dto.response.CenterProfileResponseDto;
import com.somemore.domains.center.usecase.query.CenterQueryUseCase;
import com.somemore.center.dto.response.CenterProfileResponseDto;
import com.somemore.center.usecase.NEWCenterQueryUseCase;
import com.somemore.global.common.response.ApiResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -19,13 +19,13 @@
@Tag(name = "Center Query API", description = "기관 관련 조회 API를 제공합니다.")
public class CenterQueryApiController {

private final CenterQueryUseCase centerQueryUseCase;
private final NEWCenterQueryUseCase centerQueryUseCase;

@Operation(summary = "기관 프로필 조회 API")
@GetMapping("/profile/{centerId}")
public ApiResponse<CenterProfileResponseDto> getCenterProfile(@PathVariable UUID centerId) {

CenterProfileResponseDto responseDto = centerQueryUseCase.getCenterProfileByCenterId(centerId);
CenterProfileResponseDto responseDto = centerQueryUseCase.getCenterProfileById(centerId);

return ApiResponse.ok(200, responseDto, "기관 프로필 조회 성공");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.somemore.center.dto.response;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.somemore.center.repository.record.CenterProfileDto;
import com.somemore.domains.center.dto.response.PreferItemResponseDto;
import com.somemore.user.repository.usercommonattribute.record.UserProfileDto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;

import java.util.List;
import java.util.UUID;

@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
@Builder
public record CenterProfileResponseDto(

@Schema(description = "기관 ID", example = "123e4567-e89b-12d3-a456-426614174000")
UUID id,

@Schema(description = "유저 ID", example = "123e4567-e89b-12d3-a456-426614174000")
UUID userId,

@Schema(description = "기관 홈페이지 링크", example = "https://fitnesscenter.com")
String homepageUrl,

@Schema(description = "기관 이름", example = "서울 도서관")
String name,

@Schema(description = "연락처", example = "010-xxxx-xxxx")
String contactNumber,

@Schema(description = "기관 프로필 이미지 URL", example = "https://example.com/images/center.jpg")
String imgUrl,

@Schema(description = "기관 소개", example = "저희 도서관은 유명해요")
String introduce,

@Schema(description = "선호 물품 리스트")
List<PreferItemResponseDto> preferItems
) {
public static CenterProfileResponseDto of(CenterProfileDto centerProfileDto, UserProfileDto userProfileDto, List<PreferItemResponseDto> preferItems) {
return CenterProfileResponseDto.builder()
.id(centerProfileDto.id())
.userId(centerProfileDto.userId())
.homepageUrl(centerProfileDto.homepageUrl())
.name(userProfileDto.name())
.contactNumber(userProfileDto.contactNumber())
.imgUrl(userProfileDto.imgUrl())
.introduce(userProfileDto.introduce())
.preferItems(preferItems)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.somemore.center.repository;

import com.somemore.center.domain.NEWCenter;
import com.somemore.center.repository.record.CenterProfileDto;

import java.util.Optional;
import java.util.UUID;
Expand All @@ -12,4 +13,6 @@ public interface NEWCenterRepository {
Optional<NEWCenter> findById(UUID id);

Optional<NEWCenter> findByUserId(UUID userId);

Optional<CenterProfileDto> findCenterProfileById(UUID centerId);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.somemore.center.repository;

import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.somemore.center.domain.NEWCenter;
import com.somemore.center.domain.QNEWCenter;
import com.somemore.center.repository.record.CenterProfileDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

Expand All @@ -13,14 +16,14 @@
@RequiredArgsConstructor
public class NEWCenterRepositoryImpl implements NEWCenterRepository {

private final NEWCenterJpaRepository NEWCenterJpaRepository;
private final NEWCenterJpaRepository centerJpaRepository;
private final JPAQueryFactory queryFactory;

private static final QNEWCenter center = QNEWCenter.nEWCenter;

@Override
public NEWCenter save(NEWCenter center) {
return NEWCenterJpaRepository.save(center);
return centerJpaRepository.save(center);
}

@Override
Expand All @@ -29,7 +32,8 @@ public Optional<NEWCenter> findById(UUID id) {
queryFactory.selectFrom(center)
.where(
center.id.eq(id),
center.deleted.eq(false))
isNotDeleted()
)
.fetchOne()
);
}
Expand All @@ -40,9 +44,31 @@ public Optional<NEWCenter> findByUserId(UUID userId) {
queryFactory.selectFrom(center)
.where(
center.userId.eq(userId),
center.deleted.eq(false))
isNotDeleted()
)
.fetchOne()

);
}

@Override
public Optional<CenterProfileDto> findCenterProfileById(UUID centerId) {
return Optional.ofNullable(
queryFactory.select(Projections.constructor(CenterProfileDto.class,
center.id,
center.userId,
center.homepageUrl))
.from(center)
.where(
center.id.eq(centerId),
isNotDeleted()
)
.fetchOne()
);
}

private BooleanExpression isNotDeleted() {
return center.deleted.isFalse();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.somemore.center.repository.record;

import java.util.UUID;

public record CenterProfileDto(
UUID id,
UUID userId,
String homepageUrl
) {
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package com.somemore.center.service;

import com.somemore.center.domain.NEWCenter;
import com.somemore.center.dto.response.CenterProfileResponseDto;
import com.somemore.center.repository.NEWCenterRepository;
import com.somemore.center.repository.record.CenterProfileDto;
import com.somemore.center.usecase.NEWCenterQueryUseCase;
import com.somemore.domains.center.dto.response.PreferItemResponseDto;
import com.somemore.domains.center.usecase.query.PreferItemQueryUseCase;
import com.somemore.global.exception.ExceptionMessage;
import com.somemore.global.exception.NoSuchElementException;
import com.somemore.user.repository.usercommonattribute.record.UserProfileDto;
import com.somemore.user.usecase.UserQueryUseCase;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class NEWCenterQueryService implements NEWCenterQueryUseCase {

private final UserQueryUseCase userQueryUseCase;
private final PreferItemQueryUseCase preferItemQueryUseCase;
private final NEWCenterRepository centerRepository;

@Override
Expand All @@ -28,4 +37,19 @@ public NEWCenter getByUserId(UUID userId) {
public UUID getIdByUserId(UUID userId) {
return getByUserId(userId).getId();
}

@Override
public CenterProfileResponseDto getCenterProfileById(UUID centerId) {

CenterProfileDto centerProfileDto = centerRepository.findCenterProfileById(centerId)
.orElseThrow(() -> new NoSuchElementException(ExceptionMessage.NOT_EXISTS_CENTER));

UserProfileDto userProfileDto = userQueryUseCase.getUserProfileByUserId(centerProfileDto.userId());

List<PreferItemResponseDto> preferItems = preferItemQueryUseCase.getPreferItemDtosByCenterId(centerProfileDto.id());

return CenterProfileResponseDto.of(centerProfileDto, userProfileDto, preferItems);
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.somemore.center.usecase;

import com.somemore.center.domain.NEWCenter;
import com.somemore.center.dto.response.CenterProfileResponseDto;

import java.util.UUID;

Expand All @@ -9,4 +10,6 @@ public interface NEWCenterQueryUseCase {
NEWCenter getByUserId(UUID userId);

UUID getIdByUserId(UUID userId);

CenterProfileResponseDto getCenterProfileById(UUID centerId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.somemore.user.repository.usercommonattribute;

import com.somemore.user.domain.UserCommonAttribute;
import com.somemore.user.repository.usercommonattribute.record.UserProfileDto;

import java.util.Optional;
import java.util.UUID;
Expand All @@ -12,4 +13,6 @@ public interface UserCommonAttributeRepository {
UserCommonAttribute save(UserCommonAttribute userCommonAttribute);

Optional<Boolean> findIsCustomizedByUserId(UUID userId);

Optional<UserProfileDto> findUserProfileByUserId(UUID userId);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.somemore.user.repository.usercommonattribute;

import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.somemore.user.domain.QUserCommonAttribute;
import com.somemore.user.domain.UserCommonAttribute;
import com.somemore.user.repository.usercommonattribute.record.UserProfileDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

Expand Down Expand Up @@ -46,6 +48,26 @@ public Optional<Boolean> findIsCustomizedByUserId(UUID userId) {
);
}

@Override
public Optional<UserProfileDto> findUserProfileByUserId(UUID userId) {
return Optional.ofNullable(
queryFactory.select(Projections.constructor(UserProfileDto.class,
userCommonAttribute.id,
userCommonAttribute.userId,
userCommonAttribute.name,
userCommonAttribute.contactNumber,
userCommonAttribute.imgUrl,
userCommonAttribute.introduce
))
.from(userCommonAttribute)
.where(
eqUserId(userId),
isNotDeleted()
)
.fetchOne()
);
}

private static BooleanExpression eqUserId(UUID userId) {
return userCommonAttribute.userId.eq(userId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.somemore.user.repository.usercommonattribute.record;

import java.util.UUID;

public record UserProfileDto(
Long id,
UUID userId,
String name,
String contactNumber,
String imgUrl,
String introduce
) {
}
8 changes: 8 additions & 0 deletions src/main/java/com/somemore/user/service/UserQueryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.somemore.user.domain.UserRole;
import com.somemore.user.repository.user.UserRepository;
import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository;
import com.somemore.user.repository.usercommonattribute.record.UserProfileDto;
import com.somemore.user.usecase.UserQueryUseCase;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -60,4 +61,11 @@ public boolean isDuplicateAccountId(String accountId) {
return userRepository.existsByAccountId(accountId);
}

@Override
public UserProfileDto getUserProfileByUserId(UUID userId) {

return userCommonAttributeRepository.findUserProfileByUserId(userId)
.orElseThrow(() -> new NoSuchElementException(NOT_EXIST_USER));
}

}
3 changes: 3 additions & 0 deletions src/main/java/com/somemore/user/usecase/UserQueryUseCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.somemore.user.domain.User;
import com.somemore.user.domain.UserCommonAttribute;
import com.somemore.user.domain.UserRole;
import com.somemore.user.repository.usercommonattribute.record.UserProfileDto;

import java.util.UUID;

Expand All @@ -19,4 +20,6 @@ public interface UserQueryUseCase {
boolean getIsCustomizedByUserId(UUID userId);

boolean isDuplicateAccountId(String accountId);

UserProfileDto getUserProfileByUserId(UUID userId);
}
Loading
Loading