Skip to content

Commit

Permalink
Merge pull request #50 from Kusitms-29th-Meetup-TeamE/feat/47/fix-main
Browse files Browse the repository at this point in the history
Fix: 메인페이지 api 이미지 정보 추가
  • Loading branch information
Jeongho427 authored May 18, 2024
2 parents 009010b + 974b662 commit 4803518
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@Getter
public class ReadMainActivityRes {
private List<String> personalities;
private String imageUrl;
private Boolean isLiked;
private String title;
private Long currentParticipants;
Expand All @@ -29,6 +30,7 @@ public static ReadMainActivityRes of(Activity activity, Boolean isLiked) {
.map(Personality::getDescription)
.toList()
)
.imageUrl(activity.getImageUrl())
.isLiked(isLiked)
.title(activity.getTitle())
.currentParticipants(activity.getCurrentParticipants())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public List<Activity> findActivitiesForUser(User user) {
.select(activity)
.from(activity)
.where(activity.personalities.any().in(user.getPersonalities()))
.orderBy(activity.id.desc())
.limit(3L)
.fetch();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.meetup.teame.backend.global.exception.CustomException;
import com.meetup.teame.backend.global.exception.ExceptionContent;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Objects;
Expand All @@ -16,4 +17,14 @@ public static Long getAuthenticatedUserId() {
}
return (Long) principal;
}

public static boolean isAnonymousUser() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
return false;
}
return authentication.getAuthorities().stream()
.map(GrantedAuthority::getAuthority)
.anyMatch(role -> role.equals("ROLE_ANONYMOUS"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public class KakaoController {
등록되지 않은 사용자면 "/sign-up"을 요청해서 거주지 정보를 추가로 받아줘야 합니다.
""")
@GetMapping("/login/kakao")
public ResponseEntity<Object> kakaoLogin(@RequestParam String code) throws JsonProcessingException {
public ResponseEntity<CreateOauthUserRequest> kakaoLogin(@RequestParam String code) throws JsonProcessingException {
String kakaoAccessToken = kakaoService.getKakaoAccessToken(code); //인가코드로 카카오 엑세스 토큰 받아오기
CreateOauthUserRequest request = kakaoService.getKakaoInfo(kakaoAccessToken); //엑세스 토큰으로 카카오 사용자 정보 받아오기
boolean checkExist = loginService.userExists(request.getEmail());
if(checkExist) { //이미 가입된 회원
User user = userRepository.findByEmail(request.getEmail());
HttpHeaders headers = kakaoService.getLoginHeader(user);

return ResponseEntity.ok().headers(headers).body("login");
return ResponseEntity.ok().headers(headers).body(request);
//로그인 처리하기
} else { //신규 회원
return ResponseEntity.ok().body(request);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.meetup.teame.backend.domain.experience.repository.custom;

import com.meetup.teame.backend.domain.experience.entity.Experience;
import com.meetup.teame.backend.domain.user.entity.User;

import java.util.List;

Expand All @@ -9,4 +10,6 @@ public interface ExperienceRepositoryCustom {
List<Experience> findExperiencesOrderByReview(long offset,long limit, String category);

Long countExperiences(String category);

List<Experience> findExperiencesForMain();
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,13 @@ public Long countExperiences(String category) {
.where(builder)
.fetchOne();
}

@Override
public List<Experience> findExperiencesForMain() {
return jpaQueryFactory
.selectFrom(experience)
.orderBy(experience.createdAt.desc())
.limit(4)
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.meetup.teame.backend.domain.user.dto.request.ReadCalenderReq;
import com.meetup.teame.backend.domain.user.dto.request.UpdateUserReq;
import com.meetup.teame.backend.domain.user.dto.response.ReadCalenderRes;
import com.meetup.teame.backend.domain.user.dto.response.ReadExperienceProfileRes;
import com.meetup.teame.backend.domain.user.dto.response.ReadMainRes;
import com.meetup.teame.backend.domain.user.dto.response.UserInfoRes;
import com.meetup.teame.backend.domain.user.service.UserService;
Expand Down Expand Up @@ -63,11 +64,11 @@ public ResponseEntity<Void> setUserPersonality(@RequestBody @Valid OnboardingReq
임시로 고정된 더미 유저의 캘린더 정보를 조회하는 식으로 구현되어 있습니다.
jwt토큰도 같이 전달해서 요청해주셔야 합니다.
url 쿼리 파라미터로 다음과 같은 값을 전달해 주셔야 합니다.
year : 년도
month : 월
""")
@GetMapping("/mypage/calender")
Expand All @@ -77,9 +78,9 @@ public ResponseEntity<ReadCalenderRes> readCalender(@ModelAttribute @Valid ReadC
}

@Operation(summary = "사용자 기본 정보 조회", description = """
사용자의 기본 정보를 볼 수 있는 api입니다.
추후 로그인 적용 시에는 jwt토큰도 같이 전달해서 요청해주셔야 합니다.
""")
//기본 정보 조회
Expand All @@ -91,7 +92,7 @@ public ResponseEntity<UserInfoRes> getUserInfo() {

@Operation(summary = "사용자 기본 정보 수정", description = """
사용자의 기본 정보를 수정하는 api입니다.
name, email, imageUrl, location 데이터를 받습니다.
""")
//기본 정보 수정
Expand All @@ -117,12 +118,18 @@ public ResponseEntity<List<MyReviewRes>> getMyReviews(@RequestParam(required = f

@Operation(summary = "내 활동 참여 목록 조회", description = """
내 활동 참여 목록을 조회하는 api입니다.
api 요청 시 보낼 데이터는 token 이외에 없습니다.
""")
@GetMapping("/activities")
public ResponseEntity<List<ActivitySummaryRes>> getMyActivities() {
List<ActivitySummaryRes> myActivities = userService.getMyActivities();
return ResponseEntity.ok().body(myActivities);
}

/* @PostMapping("/experience-profile")
public ResponseEntity<ReadExperienceProfileRes> createExperienceProfile() {
ReadExperienceProfileRes profile = userService.createExperienceProfile();
return ResponseEntity.ok().body(profile);
}*/
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.meetup.teame.backend.domain.user.dto.response;

import com.meetup.teame.backend.domain.chatroom.entity.Appointment;
import com.meetup.teame.backend.domain.chatroom.entity.DirectChatRoom;
import com.meetup.teame.backend.domain.chatroom.entity.GroupChatRoom;
import lombok.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.meetup.teame.backend.domain.user.dto.response;

import lombok.*;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder
@Getter
public class ReadExperienceProfileRes {

private Long id;

private String name;

private Long age;

private String gender;

private String location;

private String area;

private String introduce;


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.meetup.teame.backend.domain.user.dto.request.ReadCalenderReq;
import com.meetup.teame.backend.domain.user.dto.request.UpdateUserReq;
import com.meetup.teame.backend.domain.user.dto.response.ReadCalenderRes;
import com.meetup.teame.backend.domain.user.dto.response.ReadExperienceProfileRes;
import com.meetup.teame.backend.domain.user.dto.response.ReadMainRes;
import com.meetup.teame.backend.domain.user.dto.response.UserInfoRes;
import com.meetup.teame.backend.domain.user.entity.Gender;
Expand Down Expand Up @@ -47,12 +48,14 @@ public class UserService {
private final ActivityLikeRepository activityLikeRepository;

public ReadMainRes readMainPage() {
Long userId = SecurityContextProvider.getAuthenticatedUserId();
Long userId = 5L;
if(!SecurityContextProvider.isAnonymousUser())
userId = SecurityContextProvider.getAuthenticatedUserId();
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));
return ReadMainRes.of(
activityRepository.findActivitiesForUser(user),
experienceRepository.findAll(),
experienceRepository.findExperiencesForMain(),
2500
);
}
Expand Down Expand Up @@ -146,4 +149,11 @@ public ReadCalenderRes readCalender(ReadCalenderReq readCalenderReq) {
groupChatRoomRepository.findAppointmentForUserInMonth(user, readCalenderReq.getYear(), readCalenderReq.getMonth())
);
}

/*public ReadExperienceProfileRes createExperienceProfile() {
Long userId = SecurityContextProvider.getAuthenticatedUserId();
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));
}*/
}

0 comments on commit 4803518

Please sign in to comment.