-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from DSM-PICK/add-Attendance
🔀 :: (PICK-52)Add attendance
- Loading branch information
Showing
17 changed files
with
288 additions
and
3 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
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/dsm/pick2024/domain/attendance/domain/Attendance.kt
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 dsm.pick2024.domain.attendance.domain | ||
|
||
import dsm.pick2024.domain.afterschool.enums.Status | ||
import java.util.* | ||
|
||
data class Attendance( | ||
val id: UUID? = null, | ||
val userId: UUID, | ||
val grade: Int, | ||
val classNum: Int, | ||
val num: Int, | ||
val name: String, | ||
val club: String, | ||
val period6: Status, | ||
val period7: Status, | ||
val period8: Status, | ||
val period9: Status, | ||
val period10: Status | ||
) |
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/dsm/pick2024/domain/attendance/entity/AttendanceJpaEntity.kt
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,36 @@ | ||
package dsm.pick2024.domain.attendance.entity | ||
|
||
import dsm.pick2024.domain.afterschool.enums.Status | ||
import dsm.pick2024.global.base.BaseUUIDEntity | ||
import java.util.UUID | ||
import javax.persistence.Column | ||
import javax.persistence.Entity | ||
import javax.persistence.EnumType | ||
import javax.persistence.Enumerated | ||
|
||
@Entity(name = "tbl_attendance") | ||
class AttendanceJpaEntity( | ||
id: UUID?, | ||
@Column(columnDefinition = "BINARY(16)") | ||
val userId: UUID, | ||
@Column(nullable = false) | ||
val name: String, | ||
@Column(nullable = false) | ||
val grade: Int, | ||
@Column(name = "class_num", nullable = false) | ||
val classNum: Int, | ||
@Column(nullable = false) | ||
val num: Int, | ||
@Column(name = "club") | ||
val club: String? = null, | ||
@Enumerated(value = EnumType.STRING) | ||
val period6: Status, | ||
@Enumerated(value = EnumType.STRING) | ||
val period7: Status, | ||
@Enumerated(value = EnumType.STRING) | ||
val period8: Status, | ||
@Enumerated(value = EnumType.STRING) | ||
val period9: Status, | ||
@Enumerated(value = EnumType.STRING) | ||
val period10: Status | ||
) : BaseUUIDEntity(id) |
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/dsm/pick2024/domain/attendance/mapper/AttendanceMapper.kt
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,45 @@ | ||
package dsm.pick2024.domain.attendance.mapper | ||
|
||
import dsm.pick2024.domain.attendance.domain.Attendance | ||
import dsm.pick2024.domain.attendance.entity.AttendanceJpaEntity | ||
import dsm.pick2024.global.base.GenericMapper | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class AttendanceMapper : GenericMapper<AttendanceJpaEntity, Attendance> { | ||
override fun toEntity(domain: Attendance) = | ||
domain.run { | ||
AttendanceJpaEntity( | ||
id = id, | ||
userId = userId, | ||
grade = grade, | ||
classNum = classNum, | ||
num = num, | ||
name = name, | ||
club = club, | ||
period6 = period6, | ||
period7 = period7, | ||
period8 = period8, | ||
period9 = period9, | ||
period10 = period10 | ||
) | ||
} | ||
|
||
override fun toDomain(entity: AttendanceJpaEntity) = | ||
entity.run { | ||
Attendance( | ||
id = id, | ||
userId = userId, | ||
grade = grade, | ||
classNum = classNum, | ||
num = num, | ||
name = name, | ||
club = club!!, | ||
period6 = period6, | ||
period7 = period7, | ||
period8 = period8, | ||
period9 = period9, | ||
period10 = period10 | ||
) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/dsm/pick2024/domain/attendance/persistence/AttendancePersistenceAdapter.kt
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,24 @@ | ||
package dsm.pick2024.domain.attendance.persistence | ||
|
||
import com.querydsl.jpa.impl.JPAQueryFactory | ||
import dsm.pick2024.domain.attendance.domain.Attendance | ||
import dsm.pick2024.domain.attendance.mapper.AttendanceMapper | ||
import dsm.pick2024.domain.attendance.persistence.repository.AttendanceRepository | ||
import dsm.pick2024.domain.attendance.port.out.AttendancePort | ||
import org.springframework.stereotype.Component | ||
import java.util.* | ||
|
||
@Component | ||
class AttendancePersistenceAdapter( | ||
private val attendanceJpaRepository: AttendanceRepository, | ||
private val attendanceMapper: AttendanceMapper, | ||
private val jpaQueryFactory: JPAQueryFactory | ||
) : AttendancePort { | ||
override fun saveAll(attendance: MutableList<Attendance>) { | ||
val entities = attendance.map { attendanceMapper.toEntity(it) } | ||
attendanceJpaRepository.saveAll(entities) | ||
} | ||
|
||
override fun findByUserId(userId: UUID) = | ||
attendanceJpaRepository.findByUserId(userId).let { attendanceMapper.toDomain(it) } | ||
} |
11 changes: 11 additions & 0 deletions
11
...main/kotlin/dsm/pick2024/domain/attendance/persistence/repository/AttendanceRepository.kt
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 dsm.pick2024.domain.attendance.persistence.repository | ||
|
||
import dsm.pick2024.domain.attendance.entity.AttendanceJpaEntity | ||
import org.springframework.data.repository.Repository | ||
import java.util.UUID | ||
|
||
interface AttendanceRepository : Repository<AttendanceJpaEntity, UUID> { | ||
fun saveAll(entity: Iterable<AttendanceJpaEntity>) | ||
|
||
fun findByUserId(userId: UUID): AttendanceJpaEntity | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/dsm/pick2024/domain/attendance/port/in/ChangeAttendanceUseCase.kt
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,7 @@ | ||
package dsm.pick2024.domain.attendance.port.`in` | ||
|
||
import dsm.pick2024.domain.attendance.presentation.dto.request.ChangeAttendanceRequest | ||
|
||
interface ChangeAttendanceUseCase { | ||
fun changeAttendance(request: List<ChangeAttendanceRequest>) | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/dsm/pick2024/domain/attendance/port/in/SaveAllAttendanceUseCase.kt
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,5 @@ | ||
package dsm.pick2024.domain.attendance.port.`in` | ||
|
||
interface SaveAllAttendanceUseCase { | ||
fun saveAll(key: String) | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/dsm/pick2024/domain/attendance/port/out/AttendancePort.kt
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,5 @@ | ||
package dsm.pick2024.domain.attendance.port.out | ||
|
||
interface AttendancePort : | ||
SaveAll, | ||
FindByUserIdPort |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/dsm/pick2024/domain/attendance/port/out/FindByUserIdPort.kt
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,8 @@ | ||
package dsm.pick2024.domain.attendance.port.out | ||
|
||
import dsm.pick2024.domain.attendance.domain.Attendance | ||
import java.util.UUID | ||
|
||
interface FindByUserIdPort { | ||
fun findByUserId(userId: UUID): Attendance? | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/dsm/pick2024/domain/attendance/port/out/SaveAll.kt
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,7 @@ | ||
package dsm.pick2024.domain.attendance.port.out | ||
|
||
import dsm.pick2024.domain.attendance.domain.Attendance | ||
|
||
interface SaveAll { | ||
fun saveAll(attendance: MutableList<Attendance>) | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/dsm/pick2024/domain/attendance/presentation/AttendanceController.kt
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,31 @@ | ||
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.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.PatchMapping | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@Tag(name = "attendance API") | ||
@RestController | ||
@RequestMapping("/attendance") | ||
class AttendanceController( | ||
private val saveAllAttendanceUseCase: SaveAllAttendanceUseCase, | ||
private val changeAttendanceUseCase: ChangeAttendanceUseCase | ||
) { | ||
|
||
@Operation(summary = "데이터 저장 api") | ||
@PostMapping("/all") | ||
fun all(@RequestParam(name = "key") key: String) = | ||
saveAllAttendanceUseCase.saveAll(key) | ||
|
||
@Operation(summary = "자습 or 방과후 상태관리") | ||
@PatchMapping("/modify") | ||
fun changeAttendance(changeAttendanceRequest: List<ChangeAttendanceRequest>) = | ||
changeAttendanceUseCase.changeAttendance(changeAttendanceRequest) | ||
} |
9 changes: 9 additions & 0 deletions
9
...kotlin/dsm/pick2024/domain/attendance/presentation/dto/request/ChangeAttendanceRequest.kt
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,9 @@ | ||
package dsm.pick2024.domain.attendance.presentation.dto.request | ||
|
||
import dsm.pick2024.domain.afterschool.enums.Status | ||
import java.util.UUID | ||
|
||
data class ChangeAttendanceRequest( | ||
val userId: UUID, | ||
val statusList: List<Status> | ||
) |
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/dsm/pick2024/domain/attendance/service/ChangeAttendanceService.kt
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,38 @@ | ||
package dsm.pick2024.domain.attendance.service | ||
|
||
import dsm.pick2024.domain.attendance.domain.Attendance | ||
import dsm.pick2024.domain.attendance.port.`in`.ChangeAttendanceUseCase | ||
import dsm.pick2024.domain.attendance.port.out.FindByUserIdPort | ||
import dsm.pick2024.domain.attendance.port.out.SaveAll | ||
import dsm.pick2024.domain.attendance.presentation.dto.request.ChangeAttendanceRequest | ||
import dsm.pick2024.domain.user.exception.UserNotFoundException | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class ChangeAttendanceService( | ||
private val saveAll: SaveAll, | ||
private val findByUserIdPort: FindByUserIdPort | ||
) : ChangeAttendanceUseCase { | ||
|
||
@Transactional | ||
override fun changeAttendance(request: List<ChangeAttendanceRequest>) { | ||
val update = mutableListOf<Attendance>() | ||
|
||
request.map { | ||
it -> | ||
val attendance = findByUserIdPort.findByUserId(it.userId) | ||
?: throw UserNotFoundException | ||
val list = it.statusList | ||
val add = attendance.copy( | ||
period6 = list.getOrElse(0) { attendance.period6 }, | ||
period7 = list.getOrElse(1) { attendance.period7 }, | ||
period8 = list.getOrElse(2) { attendance.period8 }, | ||
period9 = list.getOrElse(1) { attendance.period9 }, | ||
period10 = list.getOrElse(2) { attendance.period10 } | ||
) | ||
update.add(add) | ||
} | ||
saveAll.saveAll(update) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...main/kotlin/dsm/pick2024/domain/attendance/service/SaveAllAttendanceSaveAllUserService.kt
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,38 @@ | ||
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) | ||
} | ||
} |
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
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