-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [STMT-261] 활동 상세 목록 조회 API 구현 (#128)
* 🩹 [STMT-261] 활동 조회 응답에 location 추가 * ✅ [STMT-261] 테스트에 location 추가 * ✨ [STMT-261] 활동 상세 리스트 조회 API 메서드, DTO 정의 * ✨ [STMT-261] 활동 상세 리스트 조회 usecase 구현 * ✨ [STMT-261] 활동 상세 리스트 조회 persistence adapter 구현 * 🔧 [STMT-261] application-local 설정 파일에 로깅 debug 레벨 설정 * ✅ [STMT-261] 테스트용 활동 stub 데이터 추가 * 🩹 [STMT-261] 응답에 활동 유형 추가 * ✨ [STMT-261] 스터디 id 검증 로직 추가 * ✅ [STMT-261] 활동 상세 목록 조회 API 테스트 케이스 작성 * 📝 [STMT-261] API 명세서 작성 * 📝 [STMT-261] 가입 스터디 목록 조회 API: 명세서 누락된 부분 추가
- Loading branch information
Showing
31 changed files
with
751 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 34 additions & 12 deletions
46
src/main/java/com/stumeet/server/activity/adapter/in/ActivityQueryApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,56 @@ | ||
package com.stumeet.server.activity.adapter.in; | ||
|
||
import com.stumeet.server.activity.adapter.in.response.ActivityDetailResponse; | ||
import com.stumeet.server.activity.adapter.in.response.ActivityListDetailedPageResponses; | ||
import com.stumeet.server.activity.application.port.in.ActivityQueryUseCase; | ||
import com.stumeet.server.activity.application.port.in.query.ActivityListDetailedQuery; | ||
import com.stumeet.server.common.annotation.WebAdapter; | ||
import com.stumeet.server.common.auth.model.LoginMember; | ||
import com.stumeet.server.common.model.ApiResponse; | ||
import com.stumeet.server.common.response.SuccessCode; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@WebAdapter | ||
@RequestMapping("/api/v1") | ||
@RequiredArgsConstructor | ||
public class ActivityQueryApi { | ||
|
||
private final ActivityQueryUseCase activityQueryUseCase; | ||
|
||
@GetMapping("/studies/{studyId}/activities/{activityId}") | ||
public ResponseEntity<ApiResponse<ActivityDetailResponse>> getById( | ||
@PathVariable Long studyId, | ||
@PathVariable Long activityId, | ||
@AuthenticationPrincipal LoginMember member | ||
) { | ||
ActivityDetailResponse response = activityQueryUseCase.getById(studyId, activityId, member.getId()); | ||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(ApiResponse.success(SuccessCode.GET_SUCCESS, response)); | ||
} | ||
private final ActivityQueryUseCase activityQueryUseCase; | ||
|
||
@GetMapping("/studies/{studyId}/activities/{activityId}") | ||
public ResponseEntity<ApiResponse<ActivityDetailResponse>> getById( | ||
@PathVariable Long studyId, | ||
@PathVariable Long activityId, | ||
@AuthenticationPrincipal LoginMember member | ||
) { | ||
ActivityDetailResponse response = activityQueryUseCase.getById(studyId, activityId, member.getId()); | ||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(ApiResponse.success(SuccessCode.GET_SUCCESS, response)); | ||
} | ||
|
||
@GetMapping("/studies/activities/detail") | ||
public ResponseEntity<ApiResponse<ActivityListDetailedPageResponses>> getDetailsByCondition( | ||
@AuthenticationPrincipal LoginMember member, | ||
@RequestParam Integer size, | ||
@RequestParam Integer page, | ||
@RequestParam(required = false) Boolean isNotice, | ||
@RequestParam(required = false) Long studyId, | ||
@RequestParam(required = false) String category | ||
) { | ||
ActivityListDetailedQuery query = | ||
ActivityListDetailedQuery.of(size, page, isNotice, member.getId(), studyId, category); | ||
ActivityListDetailedPageResponses response = activityQueryUseCase.getDetails(query); | ||
|
||
return ResponseEntity.status(HttpStatus.OK) | ||
.body(ApiResponse.success(SuccessCode.GET_SUCCESS, response)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ava/com/stumeet/server/activity/adapter/in/response/ActivityListDetailedPageResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.stumeet.server.activity.adapter.in.response; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ActivityListDetailedPageResponse( | ||
Long id, | ||
String category, | ||
String title, | ||
String content, | ||
LocalDateTime startDate, | ||
LocalDateTime endDate, | ||
String location, | ||
ActivityParticipantSimpleResponse author, | ||
LocalDateTime createdAt | ||
) { | ||
} |
12 changes: 12 additions & 0 deletions
12
...va/com/stumeet/server/activity/adapter/in/response/ActivityListDetailedPageResponses.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.stumeet.server.activity.adapter.in.response; | ||
|
||
import java.util.List; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ActivityListDetailedPageResponses( | ||
List<ActivityListDetailedPageResponse> items, | ||
PageInfoResponse pageInfo | ||
) { | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/stumeet/server/activity/adapter/in/response/PageInfoResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.stumeet.server.activity.adapter.in.response; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record PageInfoResponse( | ||
int totalPages, | ||
long totalElements, | ||
int currentPage, | ||
int pageSize | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 27 additions & 13 deletions
40
.../java/com/stumeet/server/activity/adapter/out/persistence/ActivityPersistenceAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,47 @@ | ||
package com.stumeet.server.activity.adapter.out.persistence; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import com.stumeet.server.activity.adapter.out.mapper.ActivityPersistenceMapper; | ||
import com.stumeet.server.activity.adapter.out.model.ActivityJpaEntity; | ||
import com.stumeet.server.activity.application.port.out.ActivityCreatePort; | ||
import com.stumeet.server.activity.application.port.out.ActivityQueryPort; | ||
import com.stumeet.server.activity.domain.exception.NotExistsActivityException; | ||
import com.stumeet.server.activity.domain.model.Activity; | ||
import com.stumeet.server.activity.domain.model.ActivityCategory; | ||
import com.stumeet.server.common.annotation.PersistenceAdapter; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@PersistenceAdapter | ||
@RequiredArgsConstructor | ||
public class ActivityPersistenceAdapter implements ActivityCreatePort, ActivityQueryPort { | ||
|
||
private final JpaActivityRepository jpaActivityRepository; | ||
private final ActivityPersistenceMapper activityPersistenceMapper; | ||
private final JpaActivityRepository jpaActivityRepository; | ||
private final ActivityPersistenceMapper activityPersistenceMapper; | ||
|
||
@Override | ||
public Activity create(Activity activity) { | ||
ActivityJpaEntity entity = activityPersistenceMapper.toEntity(activity); | ||
|
||
return activityPersistenceMapper.toDomain(jpaActivityRepository.save(entity)); | ||
} | ||
|
||
@Override | ||
public Activity create(Activity activity) { | ||
ActivityJpaEntity entity = activityPersistenceMapper.toEntity(activity); | ||
@Override | ||
public Activity getById(Long activityId) { | ||
ActivityJpaEntity entity = jpaActivityRepository.findById(activityId) | ||
.orElseThrow(() -> new NotExistsActivityException(activityId)); | ||
|
||
return activityPersistenceMapper.toDomain(jpaActivityRepository.save(entity)); | ||
} | ||
return activityPersistenceMapper.toDomain(entity); | ||
} | ||
|
||
@Override | ||
public Activity getById(Long activityId) { | ||
ActivityJpaEntity activityJpaEntity = jpaActivityRepository.findById(activityId) | ||
.orElseThrow(() -> new NotExistsActivityException(activityId)); | ||
@Override | ||
public Page<Activity> getDetailPagesByCondition( | ||
Pageable pageable, Boolean isNotice, Long studyId, ActivityCategory category) { | ||
Page<ActivityJpaEntity> entities = | ||
jpaActivityRepository.findDetailPagesByCondition(pageable, isNotice, studyId, category); | ||
|
||
return activityPersistenceMapper.toDomain(activityJpaEntity); | ||
} | ||
return activityPersistenceMapper.toDomainPages(entities); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...java/com/stumeet/server/activity/adapter/out/persistence/JpaActivityRepositoryCustom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.stumeet.server.activity.adapter.out.persistence; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import com.stumeet.server.activity.adapter.out.model.ActivityJpaEntity; | ||
import com.stumeet.server.activity.domain.model.ActivityCategory; | ||
|
||
public interface JpaActivityRepositoryCustom { | ||
Page<ActivityJpaEntity> findDetailPagesByCondition(Pageable pageable, Boolean isNotice, Long studyId, ActivityCategory category); | ||
} |
47 changes: 47 additions & 0 deletions
47
.../com/stumeet/server/activity/adapter/out/persistence/JpaActivityRepositoryCustomImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.stumeet.server.activity.adapter.out.persistence; | ||
|
||
import static com.stumeet.server.activity.adapter.out.model.QActivityJpaEntity.*; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.support.PageableExecutionUtils; | ||
|
||
import com.querydsl.jpa.impl.JPAQuery; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import com.stumeet.server.activity.adapter.out.model.ActivityJpaEntity; | ||
import com.stumeet.server.activity.domain.model.ActivityCategory; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class JpaActivityRepositoryCustomImpl implements JpaActivityRepositoryCustom{ | ||
|
||
private final JPAQueryFactory query; | ||
|
||
@Override | ||
public Page<ActivityJpaEntity> findDetailPagesByCondition( | ||
Pageable pageable, Boolean isNotice, Long studyId, ActivityCategory category) { | ||
List<ActivityJpaEntity> content = query | ||
.selectFrom(activityJpaEntity) | ||
.where( | ||
isNotice != null ? activityJpaEntity.isNotice.eq(isNotice) : null, | ||
studyId != null ? activityJpaEntity.study.id.eq(studyId) : null, | ||
category != null ? activityJpaEntity.category.eq(category) : null) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.orderBy(activityJpaEntity.createdAt.desc()) | ||
.fetch(); | ||
|
||
JPAQuery<Long> countQuery = query | ||
.select(activityJpaEntity.count()) | ||
.from(activityJpaEntity) | ||
.where( | ||
isNotice != null ? activityJpaEntity.isNotice.eq(isNotice) : null, | ||
studyId != null ? activityJpaEntity.study.id.eq(studyId) : null, | ||
category != null ? activityJpaEntity.category.eq(category) : null); | ||
|
||
return PageableExecutionUtils.getPage(content, pageable, countQuery::fetchOne); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/stumeet/server/activity/application/port/in/ActivityQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
package com.stumeet.server.activity.application.port.in; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import com.stumeet.server.activity.domain.model.Activity; | ||
import com.stumeet.server.activity.domain.model.ActivityCategory; | ||
|
||
public interface ActivityQuery { | ||
Activity getById(Long activityId); | ||
|
||
Page<Activity> getDetailsByCondition(Pageable pageable, Boolean isNotice, Long studyId, ActivityCategory category); | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/stumeet/server/activity/application/port/in/ActivityQueryUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package com.stumeet.server.activity.application.port.in; | ||
|
||
import com.stumeet.server.activity.adapter.in.response.ActivityDetailResponse; | ||
import com.stumeet.server.activity.adapter.in.response.ActivityListDetailedPageResponses; | ||
import com.stumeet.server.activity.application.port.in.query.ActivityListDetailedQuery; | ||
|
||
public interface ActivityQueryUseCase { | ||
ActivityDetailResponse getById(Long studyId, Long activityId, Long memberId); | ||
|
||
ActivityListDetailedPageResponses getDetails(ActivityListDetailedQuery query); | ||
} |
Oops, something went wrong.