-
Notifications
You must be signed in to change notification settings - Fork 0
자습 출석 이력 영구 저장 및 무인증 조회 API 추가 #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...lin/team/incube/flooding/domain/dormitory/study/entity/StudyAttendanceHistoryJpaEntity.kt
This file contains hidden or 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,32 @@ | ||
| package team.incube.flooding.domain.dormitory.study.entity | ||
|
|
||
| import jakarta.persistence.Column | ||
| import jakarta.persistence.Entity | ||
| import jakarta.persistence.FetchType | ||
| import jakarta.persistence.GeneratedValue | ||
| import jakarta.persistence.GenerationType | ||
| import jakarta.persistence.Id | ||
| import jakarta.persistence.JoinColumn | ||
| import jakarta.persistence.ManyToOne | ||
| import jakarta.persistence.Table | ||
| import jakarta.persistence.UniqueConstraint | ||
| import team.incube.flooding.domain.user.entity.UserJpaEntity | ||
| import java.time.LocalDate | ||
|
|
||
| @Entity | ||
| @Table( | ||
| name = "tb_study_attendance_history", | ||
| uniqueConstraints = [ | ||
| UniqueConstraint(columnNames = ["user_id", "attended_date"]), | ||
| ], | ||
| ) | ||
| class StudyAttendanceHistoryJpaEntity( | ||
| @field:Id | ||
| @field:GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| val id: Long = 0, | ||
| @field:ManyToOne(fetch = FetchType.LAZY) | ||
| @field:JoinColumn(nullable = false, name = "user_id") | ||
| val user: UserJpaEntity, | ||
| @field:Column(name = "attended_date", nullable = false) | ||
| val attendedDate: LocalDate, | ||
| ) |
33 changes: 33 additions & 0 deletions
33
...m/incube/flooding/domain/dormitory/study/presentation/controller/PublicStudyController.kt
This file contains hidden or 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,33 @@ | ||
| package team.incube.flooding.domain.dormitory.study.presentation.controller | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponse | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses | ||
| import io.swagger.v3.oas.annotations.tags.Tag | ||
| import org.springframework.web.bind.annotation.GetMapping | ||
| import org.springframework.web.bind.annotation.RequestMapping | ||
| import org.springframework.web.bind.annotation.RestController | ||
| import team.incube.flooding.domain.dormitory.study.presentation.data.response.GetStudyAttendanceListResponse | ||
| import team.incube.flooding.domain.dormitory.study.service.GetPublicStudyAttendanceListService | ||
| import team.themoment.sdk.response.CommonApiResponse | ||
|
|
||
| @Tag(name = "자습(공개)", description = "인증 없이 조회 가능한 자습 관련 공개 API") | ||
| @RestController | ||
| @RequestMapping("public/study") | ||
| class PublicStudyController( | ||
| private val getPublicStudyAttendanceListService: GetPublicStudyAttendanceListService, | ||
| ) { | ||
| @Operation( | ||
| summary = "최근 1주일 자습 출석자 목록 조회 (공개)", | ||
| description = | ||
| "인증 없이 오늘을 포함한 최근 7일간 날짜별 자습 출석자 이름 리스트를 조회합니다. " + | ||
| "학번, 유저 ID 등 개인 식별 정보는 포함되지 않으며 이름만 제공합니다. " + | ||
| "스트릭(연속 출석) 계산과 같은 부가 로직은 이 API를 사용하는 클라이언트(서드파티)가 직접 수행해야 합니다.", | ||
| ) | ||
| @ApiResponses( | ||
| ApiResponse(responseCode = "200", description = "조회 성공"), | ||
| ) | ||
| @GetMapping("/attendances") | ||
| fun getAttendances(): CommonApiResponse<List<GetStudyAttendanceListResponse>> = | ||
| CommonApiResponse.success("OK", getPublicStudyAttendanceListService.execute()) | ||
| } | ||
8 changes: 8 additions & 0 deletions
8
...oding/domain/dormitory/study/presentation/data/response/GetStudyAttendanceListResponse.kt
This file contains hidden or 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,8 @@ | ||
| package team.incube.flooding.domain.dormitory.study.presentation.data.response | ||
|
|
||
| import java.time.LocalDate | ||
|
|
||
| data class GetStudyAttendanceListResponse( | ||
| val date: LocalDate, | ||
| val students: List<String>, | ||
| ) |
28 changes: 28 additions & 0 deletions
28
...eam/incube/flooding/domain/dormitory/study/repository/StudyAttendanceHistoryRepository.kt
This file contains hidden or 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,28 @@ | ||
| package team.incube.flooding.domain.dormitory.study.repository | ||
|
|
||
| import org.springframework.data.jpa.repository.JpaRepository | ||
| import org.springframework.data.jpa.repository.Query | ||
| import org.springframework.data.repository.query.Param | ||
| import team.incube.flooding.domain.dormitory.study.entity.StudyAttendanceHistoryJpaEntity | ||
| import java.time.LocalDate | ||
|
|
||
| interface StudyAttendanceHistoryRepository : JpaRepository<StudyAttendanceHistoryJpaEntity, Long> { | ||
| fun existsByUserIdAndAttendedDate( | ||
| userId: Long, | ||
| attendedDate: LocalDate, | ||
| ): Boolean | ||
|
|
||
| fun deleteByUserIdAndAttendedDate( | ||
| userId: Long, | ||
| attendedDate: LocalDate, | ||
| ) | ||
|
|
||
| @Query( | ||
| "SELECT h FROM StudyAttendanceHistoryJpaEntity h JOIN FETCH h.user " + | ||
| "WHERE h.attendedDate BETWEEN :startDate AND :endDate ORDER BY h.attendedDate ASC", | ||
| ) | ||
| fun findAllByAttendedDateBetweenOrderByAttendedDateAsc( | ||
| @Param("startDate") startDate: LocalDate, | ||
| @Param("endDate") endDate: LocalDate, | ||
| ): List<StudyAttendanceHistoryJpaEntity> | ||
| } |
7 changes: 7 additions & 0 deletions
7
...eam/incube/flooding/domain/dormitory/study/service/GetPublicStudyAttendanceListService.kt
This file contains hidden or 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,7 @@ | ||
| package team.incube.flooding.domain.dormitory.study.service | ||
|
|
||
| import team.incube.flooding.domain.dormitory.study.presentation.data.response.GetStudyAttendanceListResponse | ||
|
|
||
| interface GetPublicStudyAttendanceListService { | ||
| fun execute(): List<GetStudyAttendanceListResponse> | ||
| } |
This file contains hidden or 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
28 changes: 28 additions & 0 deletions
28
...e/flooding/domain/dormitory/study/service/impl/GetPublicStudyAttendanceListServiceImpl.kt
This file contains hidden or 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,28 @@ | ||
| package team.incube.flooding.domain.dormitory.study.service.impl | ||
|
|
||
| import org.springframework.stereotype.Service | ||
| import org.springframework.transaction.annotation.Transactional | ||
| import team.incube.flooding.domain.dormitory.study.presentation.data.response.GetStudyAttendanceListResponse | ||
| import team.incube.flooding.domain.dormitory.study.repository.StudyAttendanceHistoryRepository | ||
| import team.incube.flooding.domain.dormitory.study.service.GetPublicStudyAttendanceListService | ||
| import java.time.Clock | ||
| import java.time.LocalDate | ||
|
|
||
| @Service | ||
| @Transactional(readOnly = true) | ||
| class GetPublicStudyAttendanceListServiceImpl( | ||
| private val studyAttendanceHistoryRepository: StudyAttendanceHistoryRepository, | ||
| private val clock: Clock, | ||
| ) : GetPublicStudyAttendanceListService { | ||
| override fun execute(): List<GetStudyAttendanceListResponse> { | ||
| val endDate = LocalDate.now(clock) | ||
| val startDate = endDate.minusDays(6) | ||
| val histories = | ||
| studyAttendanceHistoryRepository.findAllByAttendedDateBetweenOrderByAttendedDateAsc(startDate, endDate) | ||
| val namesByDate = histories.groupBy({ it.attendedDate }, { it.user.name }) | ||
| return (0..6).map { i -> | ||
| val date = startDate.plusDays(i.toLong()) | ||
| GetStudyAttendanceListResponse(date = date, students = namesByDate[date] ?: emptyList()) | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.