Skip to content

Commit

Permalink
Merge pull request #91 from KCY-Fit-a-Pet/feat/83
Browse files Browse the repository at this point in the history
โœจ ๊ธฐ๋ก ์กฐํšŒ ๋ฐ ์ƒ์„ฑ API & Util ๋ฐ ์‚ฌ์šฉ์ž ์ •์˜ ํ•จ์ˆ˜ ์ ์šฉ
  • Loading branch information
heejinnn authored Feb 1, 2024
2 parents 498644a + 2e73481 commit cf0444d
Show file tree
Hide file tree
Showing 71 changed files with 1,677 additions and 159 deletions.
6 changes: 2 additions & 4 deletions src/main/java/com/kcy/fitapet/FitapetApplication.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.kcy.fitapet;

import com.kcy.fitapet.global.common.repository.ExtendedJpaRepositoryFactory;
import com.kcy.fitapet.global.common.repository.ExtendedRepositoryFactory;
import jakarta.annotation.PostConstruct;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

import java.util.TimeZone;

@SpringBootApplication
@EnableJpaRepositories(repositoryFactoryBeanClass = ExtendedJpaRepositoryFactory.class)
@EnableJpaRepositories(repositoryFactoryBeanClass = ExtendedRepositoryFactory.class)
public class FitapetApplication {
public static void main(String[] args) {
SpringApplication.run(FitapetApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.kcy.fitapet.domain.care.dao;

import com.kcy.fitapet.domain.care.domain.CareCategory;
import com.kcy.fitapet.global.common.repository.ExtendedRepository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.kcy.fitapet.global.common.repository.ExtendedJpaRepository;

import java.util.List;

public interface CareCategoryRepository extends ExtendedRepository<CareCategory, Long> {
public interface CareCategoryRepository extends ExtendedJpaRepository<CareCategory, Long> {
List<CareCategory> findAllByPet_Id(Long petId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.kcy.fitapet.domain.care.domain.CareDate;
import com.kcy.fitapet.domain.care.type.WeekType;
import com.kcy.fitapet.global.common.repository.ExtendedRepository;
import com.kcy.fitapet.global.common.repository.ExtendedJpaRepository;

import java.util.List;

public interface CareDateRepository extends ExtendedRepository<CareDate, Long> {
public interface CareDateRepository extends ExtendedJpaRepository<CareDate, Long> {
List<CareDate> findAllByCare_IdAndWeek(Long careId, WeekType week);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.kcy.fitapet.domain.care.dao;

import com.kcy.fitapet.domain.care.domain.Care;
import com.kcy.fitapet.global.common.repository.ExtendedRepository;
import org.springframework.data.jpa.repository.JpaRepository;
import com.kcy.fitapet.global.common.repository.ExtendedJpaRepository;

public interface CareRepository extends ExtendedRepository<Care, Long> {
public interface CareRepository extends ExtendedJpaRepository<Care, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ public CareInfoRes findCaresByPetId(Long petId) {
List<CareInfoRes.CareDto> careDtos = new ArrayList<>();
for (Care care : cares) {
WeekType todayWeek = WeekType.fromLegacyType(LocalDateTime.now().getDayOfWeek().toString());
log.info("todayWeek: {}", todayWeek);
List<CareDate> careDates = careSearchService.findCareDatesCareIdAndWeek(care.getId(), todayWeek);
for (CareDate careDate : careDates) {
LocalDateTime today = LocalDateTime.now();
log.info("today: {}", today);

boolean isClear = careLogSearchService.existsByCareDateIdOnLogDate(careDate.getId(), today);
log.info("isClear: {}", isClear);
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/com/kcy/fitapet/domain/member/api/AccountApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

Expand All @@ -46,8 +48,8 @@ public ResponseEntity<?> getProfile(@PathVariable("id") Long id) {
}

@Operation(summary = "๋‹‰๋„ค์ž„ ์กด์žฌ ํ™•์ธ")
@GetMapping("/exists")
@Parameter(name = "uid", description = "ํ™•์ธํ•  ์œ ์ € ๋‹‰๋„ค์ž„", in = ParameterIn.QUERY, required = true)
@GetMapping("/exists")
@PreAuthorize("isAnonymous()")
public ResponseEntity<?> getExistsUid(@RequestParam("uid") @NotBlank String uid) {
boolean exists = memberAccountService.existsUid(uid);
Expand All @@ -73,11 +75,11 @@ public ResponseEntity<?> putProfile(
}

@Operation(summary = "ID/PW ์ฐพ๊ธฐ")
@PostMapping("/search")
@Parameters({
@Parameter(name = "type", description = "์ฐพ์„ ํƒ€์ž…", example = "uid/password", in = ParameterIn.QUERY, required = true),
@Parameter(name = "code", description = "์ธ์ฆ๋ฒˆํ˜ธ", in = ParameterIn.QUERY, required = true),
})
@PostMapping("/search")
@PreAuthorize("isAnonymous()")
public ResponseEntity<?> postSearchIdOrPassword(
@RequestParam("type") @NotBlank SmsPrefix type,
Expand Down Expand Up @@ -107,4 +109,26 @@ public ResponseEntity<?> putNotify(
memberAccountService.updateNotification(id, user.getUserId(), type);
return ResponseEntity.ok(SuccessResponse.noContent());
}

@Operation(summary = "๊ด€๋ฆฌ ์ค‘์ธ ๋ฐ˜๋ ค๋™๋ฌผ ๋‚ ์งœ๋ณ„ ์Šค์ผ€์ค„ ์ „์ฒด ์กฐํšŒ")
@GetMapping("/{user_id}/schedules")
@PreAuthorize("isAuthenticated() and #userId == principal.userId")
public ResponseEntity<?> getCalendarSchedules(
@PathVariable("user_id") Long userId,
@RequestParam(value = "year") Integer year,
@RequestParam(value = "month") Integer month,
@RequestParam(value = "day") Integer day
) {
LocalDateTime date = LocalDate.of(year, month, day).atStartOfDay();
log.info("date: {}", date);
return ResponseEntity.ok(SuccessResponse.from("schedules", memberAccountService.findPetSchedules(userId, date).getSchedules()));
}

@Operation(summary = "๊ด€๋ฆฌ ์ค‘์ธ ๋ฐ˜๋ ค๋™๋ฌผ์˜ ๋ชจ๋“  ๋ฉ”๋ชจ ์นดํ…Œ๊ณ ๋ฆฌ ์กฐํšŒ")
@Parameter(name = "id", description = "์กฐํšŒํ•  ํ”„๋กœํ•„ ID", in = ParameterIn.PATH, required = true)
@GetMapping("/{id}/memo-categories")
@PreAuthorize("isAuthenticated() and #id == principal.userId")
public ResponseEntity<?> getMemoCategories(@PathVariable("id") Long id) {
return ResponseEntity.ok(SuccessResponse.from("rootMemoCategories", memberAccountService.getMemoCategories(id)));
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.kcy.fitapet.domain.member.dao;

import com.kcy.fitapet.domain.member.domain.Manager;
import com.kcy.fitapet.global.common.repository.ExtendedRepository;
import org.springframework.data.jpa.repository.Query;
import com.kcy.fitapet.global.common.repository.ExtendedJpaRepository;

import java.util.List;

public interface ManagerRepository extends ExtendedRepository<Manager, Long> {
public interface ManagerRepository extends ExtendedJpaRepository<Manager, Long> {
boolean existsByMember_IdAndPet_Id(Long memberId, Long petId);
List<Manager> findAllByMember_Id(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.kcy.fitapet.domain.member.dao;

import java.util.List;

public interface MemberQueryDslRepository {
List<Long> findMyPetIds(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.kcy.fitapet.domain.member.dao;

import com.kcy.fitapet.domain.member.domain.QManager;
import com.kcy.fitapet.domain.member.domain.QMember;
import com.kcy.fitapet.domain.pet.domain.QPet;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@RequiredArgsConstructor
public class MemberQueryDslRepositoryImpl implements MemberQueryDslRepository {
private final JPAQueryFactory queryFactory;
private final QMember member = QMember.member;
private final QManager manager = QManager.manager;
private final QPet pet = QPet.pet;

@Override
public List<Long> findMyPetIds(Long memberId) {
return queryFactory.select(pet.id)
.from(member)
.leftJoin(manager).on(manager.member.id.eq(member.id))
.leftJoin(pet).on(pet.id.eq(manager.pet.id))
.where(member.id.eq(memberId))
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import java.util.Optional;

public interface MemberRepository extends ExtendedRepository<Member, Long> {
public interface MemberRepository extends ExtendedRepository<Member, Long>, MemberQueryDslRepository {
Optional<Member> findByUid(String uid);
Optional<Member> findByPhone(String phone);
boolean existsByUidOrPhone(String uid, String phone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
import com.kcy.fitapet.domain.member.exception.SmsErrorCode;
import com.kcy.fitapet.domain.member.service.module.MemberSearchService;
import com.kcy.fitapet.domain.member.type.MemberAttrType;
import com.kcy.fitapet.domain.memo.dto.MemoCategoryInfoDto;
import com.kcy.fitapet.domain.memo.service.module.MemoSearchService;
import com.kcy.fitapet.domain.notification.type.NotificationType;
import com.kcy.fitapet.domain.pet.domain.Pet;
import com.kcy.fitapet.domain.pet.dto.PetInfoRes;
import com.kcy.fitapet.domain.pet.service.module.PetSearchService;
import com.kcy.fitapet.domain.schedule.dto.ScheduleInfoDto;
import com.kcy.fitapet.domain.schedule.service.module.ScheduleSearchService;
import com.kcy.fitapet.global.common.redis.sms.SmsRedisHelper;
import com.kcy.fitapet.global.common.redis.sms.type.SmsPrefix;
import com.kcy.fitapet.global.common.response.code.StatusCode;
Expand All @@ -25,6 +29,8 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Service
Expand All @@ -33,6 +39,9 @@
public class MemberAccountService {
private final MemberSearchService memberSearchService;

private final ScheduleSearchService scheduleSearchService;
private final MemoSearchService memoSearchService;

private final SmsRedisHelper smsRedisHelper;

private final PasswordEncoder bCryptPasswordEncoder;
Expand Down Expand Up @@ -91,6 +100,31 @@ public void updateNotification(Long requestId, Long userId, NotificationType typ
member.updateNotificationFromType(type);
}

@Transactional(readOnly = true)
public ScheduleInfoDto findPetSchedules(Long userId, LocalDateTime date) {
List<Pet> pets = memberSearchService.findAllManagerByMemberId(userId)
.stream().map(Manager::getPet).toList();
List<Long> petIds = pets.stream().map(Pet::getId).toList();

List<ScheduleInfoDto.ScheduleInfo> scheduleInfo = scheduleSearchService.findSchedulesByCalender(date, petIds);
return ScheduleInfoDto.of(scheduleInfo);
}

@Transactional(readOnly = true)
public List<MemoCategoryInfoDto.MemoCategoryInfo> getMemoCategories(Long userId) {
List<Long> petIds = memberSearchService.findMyPetIds(userId);
log.info("userId: {}, petIds: {}", userId, petIds);

List<Long> rootMemoCategoryIds = memoSearchService.findRootMemoCategoriesIdByPetIds(petIds);
List<MemoCategoryInfoDto.MemoCategoryInfo> rootMemoCategories = new ArrayList<>();

for (Long rootMemoCategoryId : rootMemoCategoryIds) {
rootMemoCategories.add(memoSearchService.findMemoCategoryWithMemoCount(rootMemoCategoryId));
}

return rootMemoCategories;
}

/**
* ์‚ฌ์šฉ์ž ์ž…๋ ฅ ๋‹‰๋„ค์ž„๊ณผ ๊ธฐ์กด ๋‹‰๋„ค์ž„์ด ์ผ์น˜ํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ์—†์œผ๋ฉด ์˜ˆ์™ธ <br/>
* @param member Member : ์‚ฌ์šฉ์ž ์ •๋ณด
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Service
Expand Down Expand Up @@ -43,6 +42,11 @@ public List<Manager> findAllManagerByMemberId(Long memberId) {
return managerRepository.findAllByMember_Id(memberId);
}

@Transactional(readOnly = true)
public List<Long> findMyPetIds(Long memberId) {
return memberRepository.findMyPetIds(memberId);
}

@Transactional(readOnly = true)
public boolean isExistByUidOrPhone(String uid, String phone) {
return memberRepository.existsByUidOrPhone(uid, phone);
Expand Down
Loading

0 comments on commit cf0444d

Please sign in to comment.