쿠폰 번호 다운로드 API 수정

- MediaType openxmlformats 으로 수정
This commit is contained in:
Klaus 2024-01-02 06:27:58 +09:00
parent f45e07c879
commit 123b21cab2
1 changed files with 18 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package kr.co.vividnext.sodalive.can.coupon
import kr.co.vividnext.sodalive.common.ApiResponse
import kr.co.vividnext.sodalive.common.SodaException
import kr.co.vividnext.sodalive.member.Member
import org.springframework.core.io.InputStreamResource
import org.springframework.data.domain.Pageable
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
@ -15,6 +16,8 @@ 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
import java.net.URLEncoder
import java.nio.charset.StandardCharsets
@RestController
@RequestMapping("/can/coupon")
@ -68,10 +71,22 @@ class CanCouponController(private val service: CanCouponService) {
if (member == null) throw SodaException("로그인 정보를 확인해주세요.")
val fileName = "쿠폰번호리스트.xlsx"
val encodedFileName = URLEncoder.encode(
fileName,
StandardCharsets.UTF_8.toString()
).replace("+", "%20")
val contentDisposition = "attachment; filename*=UTF-8''$encodedFileName"
val headers = HttpHeaders().apply {
add(HttpHeaders.CONTENT_DISPOSITION, contentDisposition)
}
val response = service.downloadCouponNumberList(couponId)
ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attatchment;filename=$fileName")
.contentType(MediaType.parseMediaType("application/vnd.ms-excel"))
.body(response)
.headers(headers)
.contentType(
MediaType
.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
)
.body(InputStreamResource(response))
}
}