Skip to content

Commit

Permalink
✨ 내가 조회한 크리에이터 기능 추가 (#118)
Browse files Browse the repository at this point in the history
* 🎨 인터페이스 구현체 작성

* 🗃️ DB 구조 변경

* ✨ 서비스 로직 작성 완료

* ✨ 사용자 조회 시 기록 실행

* ♻️ 마이페이지 코드 리팩토링

* 🎨 응답 구조 변경 (dto 객체 생성)

* ✨ 마이페이지 응답에 내가 조회한 크리에이터 목록 추가

* 🎨 응답 구조 yyyy.MM.dd 로 변경
  • Loading branch information
MinseoKangQ authored Nov 15, 2024
1 parent 0a9d64e commit c201df3
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ public SuccessResponse<?> createCreator(

// 크리에이터 상세 페이지 조회
@GetMapping("/{nickname}")
public SuccessResponse<?> getCreator(@PathVariable String nickname) {

GetCreatorRes getCreatorRes = creatorService.getCreator(nickname);
public SuccessResponse<?> getCreator(Authentication authentication, @PathVariable String nickname) {

CustomOAuth2User customOAuth2User = (CustomOAuth2User) authentication.getPrincipal();
String providerId = customOAuth2User.getUsername();
GetCreatorRes getCreatorRes = creatorService.getCreator(providerId, nickname);
return SuccessResponse.of(getCreatorRes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ SuccessResponse<?> createCreator(
schema = @Schema(implementation = SuccessResponse.class)))
})
@GetMapping
SuccessResponse<?> getCreator(@PathVariable String nickname);
SuccessResponse<?> getCreator(Authentication authentication, @PathVariable String nickname);

@Operation(summary = "크리에이터 등록 초기 화면 불러 오기")
@ApiResponses(value = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ void createCreator(
String contactEmail
);

GetCreatorRes getCreator(String nickname);
GetCreatorRes getCreator(String providerId, String nickname);

GetCreatorRes getCreatorInfo(Authentication authentication);
PageResponse<CreatorInfo> filteringCreator(Pageable pageable, Integer price, String category, String align);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.example.gather_back_end.util.format.WorkTypeConverter;
import org.example.gather_back_end.util.jwt.dto.CustomOAuth2User;
import org.example.gather_back_end.util.response.PageResponse;
import org.example.gather_back_end.view.service.ViewService;
import org.example.gather_back_end.work.dto.GetWorkRes;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
Expand All @@ -30,6 +31,7 @@ public class CreatorServiceImpl implements CreatorService {
private final UserRepository userRepository;
private final PortfolioRepository portfolioRepository;
private final WorkRepository workRepository;
private final ViewService viewService;

// 크리에이터 등록
@Override
Expand All @@ -49,24 +51,29 @@ public void createCreator(

// 크리에이터 상세 페이지 조회
@Override
public GetCreatorRes getCreator(String nickname){
public GetCreatorRes getCreator(String providerId, String nickname){

User user = userRepository.getByNickname(nickname);
// 상세 페이지의 유저
User foundUser = userRepository.getByNickname(nickname);

List<GetPortfolioRes> getPortfolioResList = portfolioRepository.getAllByUser(user);
List<GetWorkRes> getWorkResList = workRepository.findAllByUser(user);
// 본 기록 저장
viewService.execute(providerId, foundUser.getNickname());

// 응답 담기
List<GetPortfolioRes> getPortfolioResList = portfolioRepository.getAllByUser(foundUser);
List<GetWorkRes> getWorkResList = workRepository.findAllByUser(foundUser);

// GetCreatorRes에 하나하나 다 담아야함
GetCreatorRes res = new GetCreatorRes(
nickname,
user.getProfileImgUrl(),
user.getIntroductionTitle(),
user.getIntroductionContent(),
foundUser.getProfileImgUrl(),
foundUser.getIntroductionTitle(),
foundUser.getIntroductionContent(),
getPortfolioResList,
getWorkResList,
user.getContactKakaoId(),
user.getContactEmail()
);
foundUser.getContactKakaoId(),
foundUser.getContactEmail()
);

return res;

Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/example/gather_back_end/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@ public class User extends BaseEntity {
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Work> workList = new ArrayList<>();

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<UsersViewRecord> usersViewRecordList = new ArrayList<>();

// 유저 생성
public static User createUserInfo(String profileImgUrl, String username, String name, String email, String role, String nickname) {
return User.builder()
Expand Down

This file was deleted.

23 changes: 18 additions & 5 deletions src/main/java/org/example/gather_back_end/domain/ViewRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,24 @@ public class ViewRecord extends BaseEntity {

// 몇 번 봤는지
@Builder.Default
private Integer viewCount = 0;
private Integer viewCount = 1;

// 크리에이터명
private String nickname;
// 포폴 본 사람 닉네임
private String currentLoginUserNickname;

@OneToMany(mappedBy = "viewRecord", cascade = CascadeType.ALL, orphanRemoval = true)
private List<UsersViewRecord> usersViewRecordList = new ArrayList<>();
// 포폴 봄을 당한 사람 닉네임
private String currentSeenUserNickname;

// 엔티티 생성
public static ViewRecord createViewRecord(String currentLoginUserNickname, String currentSeenUserNickname) {
return ViewRecord.builder()
.currentLoginUserNickname(currentLoginUserNickname)
.currentSeenUserNickname(currentSeenUserNickname)
.build();
}

// viewCount 증가
public void updateViewCount() {
this.viewCount++;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ Page<User> customFiltering(
Pageable pageable
);

@Query("SELECT u FROM User u " +
"JOIN u.workList w " +
"JOIN u.portfolioList p " +
"WHERE u.introductionTitle IS NOT NULL " + // 소개글 제목 존재
"AND SIZE(u.workList) > 0 " + // 작업 가능 항목 등록
"AND SIZE(u.portfolioList) > 0 ")
User findByMyPage(User user); // 마이페이지 유저 찾기
@Query("SELECT CASE WHEN COUNT(u) > 0 THEN TRUE ELSE FALSE END " +
"FROM User u " +
"JOIN u.workList w " +
"JOIN u.portfolioList p " +
"WHERE u.id = :userId " +
"AND u.introductionTitle IS NOT NULL " +
"AND SIZE(u.workList) > 0 " +
"AND SIZE(u.portfolioList) > 0 ")
boolean isUserCreator(@Param("userId") Long userId);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.example.gather_back_end.repository;

import java.util.List;
import java.util.Optional;
import org.example.gather_back_end.domain.ViewRecord;
import org.example.gather_back_end.view.exception.ViewRecordNotFoundException;
Expand All @@ -14,4 +15,10 @@ default ViewRecord getById(Long id) {
}

Optional<ViewRecord> findById(Long id);
Optional<ViewRecord> findByCurrentLoginUserNicknameAndCurrentSeenUserNickname(
String currentLoginUserNickname,
String currentSeenUserNickname
);

List<ViewRecord> findByCurrentLoginUserNickname(String currentLoginUserNickname);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.example.gather_back_end.user.controller;

import lombok.RequiredArgsConstructor;
import org.example.gather_back_end.user.dto.GetMyPageRes;
import org.example.gather_back_end.user.dto.GetUserRes;
import org.example.gather_back_end.user.service.UserService;
import org.example.gather_back_end.util.jwt.dto.CustomOAuth2User;
import org.example.gather_back_end.util.response.SuccessResponse;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;
Expand All @@ -17,17 +19,17 @@ public class UserController implements UserControllerApi {
// 유저 프로필 이미지 & 이름 GetMapping
@GetMapping("/header-info")
public SuccessResponse<?> getUser(Authentication authentication){

GetUserRes res = userService.getUser(authentication);

return SuccessResponse.of(res);

}

// 마이페이지
@GetMapping("/my-page")
public SuccessResponse<?> getMyPage(Authentication authentication){

return SuccessResponse.of(userService.getMyPage(authentication));
public SuccessResponse<?> getMyPage(Authentication authentication) {
CustomOAuth2User customOAuth2User = (CustomOAuth2User) authentication.getPrincipal();
String providerId = customOAuth2User.getUsername();
GetMyPageRes res = userService.getMyPage(providerId);
return SuccessResponse.of(res);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.example.gather_back_end.user.dto;

public record GetMyPageProfileInfo(
String profileImgUrl, // 프로필 이미지
String role, // 크리에이터인지 아닌지
String email
) {

// 정적 팩토리 메서드
public static GetMyPageProfileInfo of(String profileImgUrl, String role, String email) {
return new GetMyPageProfileInfo(profileImgUrl, role, email);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

import lombok.Builder;
import org.example.gather_back_end.domain.PromotionRequest;

import java.time.LocalDateTime;
import org.example.gather_back_end.util.format.DateUtils;

@Builder
public record GetMyPagePromotionRes(
LocalDateTime createDay,
String createDay,
String title,
Integer period,
Integer targetNumberOfPeople,
Integer budget
) {
public static GetMyPagePromotionRes from(PromotionRequest promotionRequest) {

String formattedDate = DateUtils.formatToDate(promotionRequest.getCreateAt());

return GetMyPagePromotionRes.builder()
.createDay(promotionRequest.getCreateAt())
.createDay(formattedDate)
.title(promotionRequest.getTitle())
.period(promotionRequest.getPeriod())
.targetNumberOfPeople(promotionRequest.getTargetNumberOfPeople())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package org.example.gather_back_end.user.dto;

import lombok.Builder;
import org.example.gather_back_end.domain.User;

import java.util.List;
import lombok.Builder;
import org.example.gather_back_end.creator.dto.filtering.CreatorInfo;

@Builder
public record GetMyPageRes(
String profileImgUrl, // 프로필 이미지
String role, // 크리에이터인지 아닌지
String email,
List<GetMyPagePromotionRes> getMyPagePromotionResList
GetMyPageProfileInfo profileInfo, // 프로필 정보
List<GetMyPagePromotionRes> promotionInfo, // 홍보 전략 요청 사항
List<CreatorInfo> creatorInfo // 내가 조회한 크리에이터 목록
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public interface UserService {
GetUserRes getUser(Authentication authentication);

// 마이페이지 정보 가져오기
GetMyPageRes getMyPage(Authentication authentication);
GetMyPageRes getMyPage(String providerId);
}
Loading

0 comments on commit c201df3

Please sign in to comment.