diff --git a/.github/workflows/klint-check.yml b/.github/workflows/klint-check.yml index e5ef1ddb..5e779391 100644 --- a/.github/workflows/klint-check.yml +++ b/.github/workflows/klint-check.yml @@ -1,27 +1,32 @@ -name: ktlint +name: Ktlint Ci -on: - pull_request: - branches: - - main +on: [pull_request] jobs: ktlint: name: Check Code Quality runs-on: ubuntu-latest + strategy: + matrix: + os: [ ubuntu-latest ] + java-version: [ 17 ] steps: + - uses: actions/checkout@v2 + - name: Set up JDK + uses: actions/setup-java@v2 + with: + java-version: ${{ matrix.java-version }} + distribution: 'zulu' + - name: Clone repo - uses: actions/checkout@v2 + uses: actions/checkout@master with: fetch-depth: 1 - - name: Setup JDK - uses: actions/setup-java@v2 + - name: ktlint + uses: ScaCap/action-ktlint@master with: - java-version: '17' - distribution: 'adopt' - - - name: Run ktlint - run: | - ./gradlew ktlintCheck --daemon --parallel --configure-on-demand + github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} + reporter: github-pr-check # Change review + fail_on_error: true diff --git a/dump.rdb b/dump.rdb new file mode 100644 index 00000000..fd03a33f Binary files /dev/null and b/dump.rdb differ diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/domain/Attendance.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/domain/Attendance.kt index d68cf991..bbf59428 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/domain/Attendance.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/domain/Attendance.kt @@ -1,7 +1,7 @@ package dsm.pick2024.domain.attendance.domain import dsm.pick2024.domain.afterschool.enums.Status -import java.util.* +import java.util.UUID data class Attendance( val id: UUID? = null, @@ -10,7 +10,7 @@ data class Attendance( val classNum: Int, val num: Int, val name: String, - val club: String, + val club: String? = null, val period6: Status, val period7: Status, val period8: Status, diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/mapper/AttendanceMapper.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/mapper/AttendanceMapper.kt index f886a4ad..2fea9b08 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/mapper/AttendanceMapper.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/mapper/AttendanceMapper.kt @@ -34,7 +34,7 @@ class AttendanceMapper : GenericMapper { classNum = classNum, num = num, name = name, - club = club!!, + club = club, period6 = period6, period7 = period7, period8 = period8, diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/persistence/AttendancePersistenceAdapter.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/persistence/AttendancePersistenceAdapter.kt index cf4df06c..30b5734d 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/persistence/AttendancePersistenceAdapter.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/persistence/AttendancePersistenceAdapter.kt @@ -2,6 +2,7 @@ package dsm.pick2024.domain.attendance.persistence import com.querydsl.jpa.impl.JPAQueryFactory import dsm.pick2024.domain.attendance.domain.Attendance +import dsm.pick2024.domain.attendance.entity.QAttendanceJpaEntity import dsm.pick2024.domain.attendance.mapper.AttendanceMapper import dsm.pick2024.domain.attendance.persistence.repository.AttendanceRepository import dsm.pick2024.domain.attendance.port.out.AttendancePort @@ -21,4 +22,19 @@ class AttendancePersistenceAdapter( override fun findByUserId(userId: UUID) = attendanceJpaRepository.findByUserId(userId).let { attendanceMapper.toDomain(it) } + + override fun findByGradeAndClassNum( + grade: Int, + classNum: Int + ) = jpaQueryFactory + .selectFrom(QAttendanceJpaEntity.attendanceJpaEntity) + .where( + QAttendanceJpaEntity.attendanceJpaEntity.grade.eq(grade), + QAttendanceJpaEntity.attendanceJpaEntity.classNum.eq(classNum) + ) + .orderBy( + QAttendanceJpaEntity.attendanceJpaEntity.num.asc() + ) + .fetch() + .map { attendanceMapper.toDomain(it) } } diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/QueryClassAttendanceUseCase.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/QueryClassAttendanceUseCase.kt new file mode 100644 index 00000000..0308cdd4 --- /dev/null +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/QueryClassAttendanceUseCase.kt @@ -0,0 +1,10 @@ +package dsm.pick2024.domain.attendance.port.`in` + +import dsm.pick2024.domain.attendance.presentation.dto.response.QueryAttendanceResponse + +interface QueryClassAttendanceUseCase { + fun queryClassAttendance( + grade: Int, + classNum: Int + ): List +} diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/SaveAllAttendanceUseCase.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/SaveAllAttendanceUseCase.kt deleted file mode 100644 index 04ab706f..00000000 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/SaveAllAttendanceUseCase.kt +++ /dev/null @@ -1,5 +0,0 @@ -package dsm.pick2024.domain.attendance.port.`in` - -interface SaveAllAttendanceUseCase { - fun saveAll(key: String) -} diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/port/out/AttendancePort.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/port/out/AttendancePort.kt index f3d2577a..54138f1c 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/port/out/AttendancePort.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/port/out/AttendancePort.kt @@ -2,4 +2,5 @@ package dsm.pick2024.domain.attendance.port.out interface AttendancePort : SaveAll, - FindByUserIdPort + FindByUserIdPort, + QueryClassAttendancePort diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/port/out/QueryClassAttendancePort.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/port/out/QueryClassAttendancePort.kt new file mode 100644 index 00000000..bbd664bc --- /dev/null +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/port/out/QueryClassAttendancePort.kt @@ -0,0 +1,10 @@ +package dsm.pick2024.domain.attendance.port.out + +import dsm.pick2024.domain.attendance.domain.Attendance + +interface QueryClassAttendancePort { + fun findByGradeAndClassNum( + grade: Int, + classNum: Int + ): List +} diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/AttendanceController.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/AttendanceController.kt index a262507a..7d07777b 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/AttendanceController.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/AttendanceController.kt @@ -1,12 +1,13 @@ package dsm.pick2024.domain.attendance.presentation import dsm.pick2024.domain.attendance.port.`in`.ChangeAttendanceUseCase -import dsm.pick2024.domain.attendance.port.`in`.SaveAllAttendanceUseCase +import dsm.pick2024.domain.attendance.port.`in`.QueryClassAttendanceUseCase import dsm.pick2024.domain.attendance.presentation.dto.request.ChangeAttendanceRequest import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag +import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PatchMapping -import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController @@ -15,17 +16,19 @@ import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("/attendance") class AttendanceController( - private val saveAllAttendanceUseCase: SaveAllAttendanceUseCase, - private val changeAttendanceUseCase: ChangeAttendanceUseCase + private val changeAttendanceUseCase: ChangeAttendanceUseCase, + private val queryClassAttendanceUseCase: QueryClassAttendanceUseCase ) { - - @Operation(summary = "데이터 저장 api") - @PostMapping("/all") - fun all(@RequestParam(name = "key") key: String) = - saveAllAttendanceUseCase.saveAll(key) - - @Operation(summary = "자습 or 방과후 상태관리") + @Operation(summary = "자습 or 동아리 상태관리") @PatchMapping("/modify") - fun changeAttendance(changeAttendanceRequest: List) = - changeAttendanceUseCase.changeAttendance(changeAttendanceRequest) + fun changeAttendance( + @RequestBody changeAttendanceRequest: List + ) = changeAttendanceUseCase.changeAttendance(changeAttendanceRequest) + + @Operation(summary = "자습 교실 별 조회 api") + @GetMapping("/grade") + fun queryClassAttendance( + @RequestParam(name = "grade") grade: Int, + @RequestParam(name = "class_num") classNum: Int + ) = queryClassAttendanceUseCase.queryClassAttendance(grade, classNum) } diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryAttendanceResponse.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryAttendanceResponse.kt new file mode 100644 index 00000000..a380c89e --- /dev/null +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryAttendanceResponse.kt @@ -0,0 +1,15 @@ +package dsm.pick2024.domain.attendance.presentation.dto.response + +import dsm.pick2024.domain.afterschool.enums.Status +import java.util.UUID + +data class QueryAttendanceResponse( + val id: UUID, + val username: String, + val grade: Int, + val classNum: Int, + val num: Int, + val status8: Status, + val status9: Status, + val status10: Status +) diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClassAttendanceService.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClassAttendanceService.kt new file mode 100644 index 00000000..1a4d5c41 --- /dev/null +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClassAttendanceService.kt @@ -0,0 +1,28 @@ +package dsm.pick2024.domain.attendance.service + +import dsm.pick2024.domain.attendance.port.`in`.QueryClassAttendanceUseCase +import dsm.pick2024.domain.attendance.port.out.QueryClassAttendancePort +import dsm.pick2024.domain.attendance.presentation.dto.response.QueryAttendanceResponse +import org.springframework.stereotype.Service + +@Service +class QueryClassAttendanceService( + private val queryClassAttendancePort: QueryClassAttendancePort +) : QueryClassAttendanceUseCase { + override fun queryClassAttendance( + grade: Int, + classNum: Int + ) = queryClassAttendancePort.findByGradeAndClassNum(grade, classNum) + .map { it -> + QueryAttendanceResponse( + id = it.userId, + username = it.name, + grade = it.grade, + classNum = it.classNum, + num = it.num, + status8 = it.period8, + status9 = it.period9, + status10 = it.period10 + ) + } +} diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/service/SaveAllAttendanceSaveAllUserService.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/service/SaveAllAttendanceSaveAllUserService.kt deleted file mode 100644 index 603e8977..00000000 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/service/SaveAllAttendanceSaveAllUserService.kt +++ /dev/null @@ -1,38 +0,0 @@ -package dsm.pick2024.domain.attendance.service - -import dsm.pick2024.domain.afterschool.enums.Status -import dsm.pick2024.domain.attendance.domain.Attendance -import dsm.pick2024.domain.attendance.port.`in`.SaveAllAttendanceUseCase -import dsm.pick2024.domain.attendance.port.out.SaveAll -import dsm.pick2024.infrastructure.feign.client.XquareFeignClient -import org.springframework.stereotype.Service -import org.springframework.transaction.annotation.Transactional - -@Service -class SaveAllAttendanceSaveAllUserService( - private val saveAll: SaveAll, - private val xquareFeignClient: XquareFeignClient -) : SaveAllAttendanceUseCase { - - @Transactional - override fun saveAll(key: String) { - val xquare = xquareFeignClient.userAll(key) - val entity = xquare.map { - it -> - Attendance( - userId = it.id, - name = it.name, - grade = it.grade, - classNum = it.classNum, - num = it.num, - club = it.club, - period6 = Status.ATTENDANCE, - period7 = Status.ATTENDANCE, - period8 = Status.ATTENDANCE, - period9 = Status.ATTENDANCE, - period10 = Status.ATTENDANCE - ) - }.toMutableList() - saveAll.saveAll(entity) - } -} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 7f23da5b..a58b43d8 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -3,7 +3,7 @@ spring: import: "optional:configserver:" datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: ${DB_URL} + url: jdbc:mysql://mysql.xquare.app:3306/stag_new_pick username: ${DB_USERNAME} password: ${DB_PASSWORD} hikari: