Skip to content

Commit 22a9b92

Browse files
authored
Merge pull request GoodSpace-Kr#116 from borntocode2/main
[feat] create getGifticon
2 parents 9384ce2 + a33facf commit 22a9b92

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

src/main/kotlin/goodspace/teaming/admin/controller/GifticonController.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package goodspace.teaming.admin.controller
22

33
import goodspace.teaming.gifticon.Entity.Gifticon
44
import goodspace.teaming.gifticon.dto.GifticonRequestDto
5+
import goodspace.teaming.gifticon.dto.GifticonResponseDto
56
import goodspace.teaming.gifticon.service.GifticonService
67
import io.swagger.v3.oas.annotations.Operation
78
import io.swagger.v3.oas.annotations.tags.Tag
@@ -37,10 +38,13 @@ class GifticonController(
3738
summary = "기프티콘 조회",
3839
description = "기프티콘 코드, 기프티콘 만료기한 ex)\"20250925\", 기프티콘 등급(\"BASIC\"\",STANDARD\",\"ELITE\")"
3940
)
40-
fun getGifticon(@RequestParam userId: Long): ResponseEntity<List<Gifticon>>{
41+
fun getGifticon(@RequestParam userId: Long): ResponseEntity<List<GifticonResponseDto>>{
4142
val gifticons = gifticonService.getGifticonsByUserId(userId)
4243

43-
return ResponseEntity.ok(gifticons)
44+
val dtos: List<GifticonResponseDto> = gifticonService.getGifticonsByUserId(userId)
45+
46+
47+
return ResponseEntity.ok(dtos)
4448
}
4549

4650
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package goodspace.teaming.gifticon.dto
2+
3+
import goodspace.teaming.gifticon.Entity.Grade
4+
5+
class GifticonResponseDto (
6+
val code: String,
7+
val expirationDateStr: String,
8+
val grade: Grade
9+
)

src/main/kotlin/goodspace/teaming/gifticon/service/GifticonService.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package goodspace.teaming.gifticon.service
22

33
import goodspace.teaming.gifticon.Entity.*
4+
import goodspace.teaming.gifticon.dto.GifticonResponseDto
45
import goodspace.teaming.gifticon.repository.GifticonRepository
56
import goodspace.teaming.global.entity.room.RoomType
67
import goodspace.teaming.global.entity.user.User
@@ -54,11 +55,18 @@ class GifticonService (
5455
}
5556

5657
@Transactional(readOnly = true)
57-
fun getGifticonsByUserId(userId: Long): List<Gifticon> {
58+
fun getGifticonsByUserId(userId: Long): List<GifticonResponseDto> {
5859
val user = userRepository.findById(userId)
5960
.orElseThrow { IllegalArgumentException("해당 회원을 찾을 수 없습니다.") }
6061

61-
return user.gifticonList
62+
return user.gifticonList.map {
63+
gifticon ->
64+
GifticonResponseDto(
65+
code = gifticon.code,
66+
grade = gifticon.grade,
67+
expirationDateStr = mapLocalDateTimeToExpiration(gifticon.expirationDate)
68+
)
69+
}
6270
}
6371

6472
fun checkExpiration(expiration: String) {
@@ -75,6 +83,11 @@ class GifticonService (
7583
return date.atStartOfDay()
7684
}
7785

86+
fun mapLocalDateTimeToExpiration(dateTime: LocalDateTime): String {
87+
val formatter = DateTimeFormatter.ofPattern("yyyyMMdd")
88+
return dateTime.toLocalDate().format(formatter)
89+
}
90+
7891
private fun mapRoomTypeToGrade(roomType: RoomType): Grade? {
7992
return when(roomType){
8093
RoomType.BASIC -> Grade.BASIC

0 commit comments

Comments
 (0)