Skip to content

Commit

Permalink
feat: 연도, 태그 별 연도 조회 기능 구현(#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
whereami2048 committed May 20, 2024
1 parent a85f71c commit f1e8e8a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ interface ExperienceRepository {
fun findByExperienceId(id: UUID): Experience
fun findAllByUserId(userId: UUID): List<Experience>
fun findByUserIdAndYearDesc(year: Int, userId: UUID): List<Experience>
fun findByYearAndParentTagId(year: Int, parentTagId: UUID): List<Experience>
fun findByYearAndChildTagId(year: Int, childTagId: UUID): List<Experience>
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ class ExperienceReader(
fun readByYearDesc(year: Int, userId: UUID): List<Experience> {
return experienceRepository.findByUserIdAndYearDesc(year, userId)
}

fun readByYearAndParentTagId(year: Int, parentTagId: UUID) : List<Experience> {
return experienceRepository.findByYearAndParentTagId(year, parentTagId)
}

fun readByYearAndChildTagId(year: Int, childTagId: UUID): List<Experience> {
return experienceRepository.findByYearAndChildTagId(year, childTagId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.bamyanggang.persistence.experience.jpa.entity.ExperienceJpaEntity;
import com.bamyanggang.persistence.experience.jpa.repository.ExperienceJpaRepository;
import com.bamyanggang.persistence.experience.mapper.ExperienceMapper;
import com.bamyanggang.persistence.user.UserRepositoryImpl;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
Expand All @@ -18,7 +17,6 @@
public class ExperienceRepositoryImpl implements ExperienceRepository {
private final ExperienceJpaRepository experienceJpaRepository;
private final ExperienceMapper experienceMapper;
private final UserRepositoryImpl userRepositoryImpl;

@Override
public void save(Experience experience) {
Expand Down Expand Up @@ -49,9 +47,32 @@ public List<Experience> findAllByUserId(UUID userId) {
public List<Experience> findByUserIdAndYearDesc(int year, UUID userId) {
LocalDateTime startYear = LocalDateTime.of(year, 1, 1, 0, 0);
LocalDateTime endYear = LocalDateTime.of(year, 12, 31, 23, 59);

List<ExperienceJpaEntity> experienceJpaEntities = experienceJpaRepository
.findByUserIdAndCreatedAtBetweenOrderByCreatedAtDesc(userId, startYear, endYear);

return experienceJpaEntities.stream().map(experienceMapper::toExperienceDomainEntity).toList();
}

@Override
public List<Experience> findByYearAndParentTagId(int year, UUID parentTagId) {
LocalDateTime startYear = LocalDateTime.of(year, 1, 1, 0, 0);
LocalDateTime endYear = LocalDateTime.of(year, 12, 31, 23, 59);

List<ExperienceJpaEntity> experienceJpaEntities = experienceJpaRepository
.findByParentTagIdAndCreatedAtBetweenOrderByCreatedAtDesc(parentTagId, startYear, endYear);

return experienceJpaEntities.stream().map(experienceMapper::toExperienceDomainEntity).toList();
}

@Override
public List<Experience> findByYearAndChildTagId(int year, UUID childTagId) {
LocalDateTime startYear = LocalDateTime.of(year, 1, 1, 0, 0);
LocalDateTime endYear = LocalDateTime.of(year, 12, 31, 23, 59);

List<ExperienceJpaEntity> experienceJpaEntities = experienceJpaRepository
.findByChildTagIdAndCreatedAtBetweenOrderByCreatedAtDesc(childTagId, startYear, endYear);

return experienceJpaEntities.stream().map(experienceMapper::toExperienceDomainEntity).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
public interface ExperienceJpaRepository extends JpaRepository<ExperienceJpaEntity, UUID> {
List<ExperienceJpaEntity> findAllByUserId(UUID userId);
List<ExperienceJpaEntity> findByUserIdAndCreatedAtBetweenOrderByCreatedAtDesc(UUID userId, LocalDateTime startYear, LocalDateTime endYear);
List<ExperienceJpaEntity> findByParentTagIdAndCreatedAtBetweenOrderByCreatedAtDesc(UUID parentTagId, LocalDateTime startYear, LocalDateTime endYear);
List<ExperienceJpaEntity> findByChildTagIdAndCreatedAtBetweenOrderByCreatedAtDesc(UUID childTagId, LocalDateTime startYear, LocalDateTime endYear);
}

0 comments on commit f1e8e8a

Please sign in to comment.