Skip to content

Commit

Permalink
Merge pull request #17 from team-xquare/16-return-user
Browse files Browse the repository at this point in the history
🔀 :: (XQUARE-16)return user
  • Loading branch information
meltapplee authored Mar 6, 2024
2 parents 1cebdbc + df43981 commit 8cf8bb8
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ class UserPersistenceAdapter(
fun findAll(): List<User> {
return userRepository.findAll()
}

fun findUserByAccountId(accountId: String): User? {
return userRepository.findUserByAccountId(accountId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import com.xaquare.xquarebackoffice.domain.entity.User
import java.util.UUID
import org.springframework.data.jpa.repository.JpaRepository

interface UserRepository : JpaRepository<User, UUID>
interface UserRepository : JpaRepository<User, UUID> {
fun findUserByAccountId(accountId: String): User?
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ enum class ErrorCode(
FEIGN_SERVER_ERROR(500, "Feign Server Error"),
DATA_FORMAT_BAD_REQUEST(400, "data Format Bad Request"),

USER_NOT_FOUND(404, "User Not Found"),

// Internal Server Error
INTERNAL_SERVER_ERROR(500, "Internal Server Error"),
DB_ACCESS_ERROR(500, "DB Access Error")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.xaquare.xquarebackoffice.infrastructure.excel.exception

import com.xaquare.xquarebackoffice.global.error.exception.ErrorCode
import com.xaquare.xquarebackoffice.global.error.exception.XquareException

object UserNotFoundException : XquareException(
ErrorCode.USER_NOT_FOUND
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.xaquare.xquarebackoffice.infrastructure.excel.controller
package com.xaquare.xquarebackoffice.infrastructure.excel.presentation

import com.xaquare.xquarebackoffice.infrastructure.excel.service.FindAllUserService
import com.xaquare.xquarebackoffice.infrastructure.excel.service.FindUserByAccountIdService
import com.xaquare.xquarebackoffice.infrastructure.excel.service.GetUserInfo
import com.xaquare.xquarebackoffice.infrastructure.excel.service.SaveUserInfo
import com.xaquare.xquarebackoffice.infrastructure.excel.service.GetExcelSheetService
Expand All @@ -10,13 +12,16 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile
import javax.servlet.http.HttpServletResponse
import org.springframework.web.bind.annotation.PathVariable

@RestController
@RequestMapping("/excel")
class ExcelController(
private val saveUserInfo: SaveUserInfo,
private val getExcelSheetService: GetExcelSheetService,
private val getUserInfo: GetUserInfo
private val getUserInfo: GetUserInfo,
private val findUserByAccountIdService: FindUserByAccountIdService,
private val findAllUserService: FindAllUserService
) {
@GetMapping
fun createExcelSheet(httpServletResponse: HttpServletResponse) =
Expand All @@ -29,4 +34,11 @@ class ExcelController(
@GetMapping("/userInfo")
fun getUserInfo(httpServletResponse: HttpServletResponse) =
getUserInfo.execute(httpServletResponse)

@GetMapping("/find/{accountId}")
fun findUser(@PathVariable(name = "accountId") accountId: String) =
findUserByAccountIdService.execute(accountId)

@GetMapping("/find/all")
fun findAllUser() = findAllUserService.execute()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.xaquare.xquarebackoffice.infrastructure.excel.presentation.dto.response

data class UserResponse(
val name: String,
val accountId: String,
val password: String,
val grade: Int,
val classNum: Int,
val num: Int,
val profile: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.xaquare.xquarebackoffice.infrastructure.excel.service

import com.xaquare.xquarebackoffice.domain.persistence.UserPersistenceAdapter
import com.xaquare.xquarebackoffice.infrastructure.excel.presentation.dto.response.UserResponse
import org.springframework.stereotype.Service

@Service
class FindAllUserService(
private val userPersistenceAdapter: UserPersistenceAdapter
) {

fun execute(): List<UserResponse> {
val userData = userPersistenceAdapter.findAll()

return userData.map { user ->
UserResponse(
name = user.name,
accountId = user.accountId,
password = user.password,
grade = user.grade,
classNum = user.classNum,
num = user.num,
profile = user.profile!!
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.xaquare.xquarebackoffice.infrastructure.excel.service

import com.xaquare.xquarebackoffice.domain.persistence.UserPersistenceAdapter
import com.xaquare.xquarebackoffice.infrastructure.excel.exception.UserNotFoundException
import com.xaquare.xquarebackoffice.infrastructure.excel.presentation.dto.response.UserResponse
import org.springframework.stereotype.Service

@Service
class FindUserByAccountIdService(
private val userPersistenceAdapter: UserPersistenceAdapter
) {

fun execute(accountId: String): UserResponse {
val user = userPersistenceAdapter.findUserByAccountId(accountId) ?: throw UserNotFoundException

return UserResponse(
user.name,
user.accountId,
user.password,
user.grade,
user.classNum,
user.num,
user.profile!!
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class GetExcelSheetService(
grade = row.getCell(3).numericCellValue.toInt(),
classNum = row.getCell(4).numericCellValue.toInt(),
num = row.getCell(5).numericCellValue.toInt(),
profile = row.getCell(6).stringCellValue.toString() ?: ""
profile = row.getCell(6).stringCellValue.toString()
)
dataList.add(userData)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.springframework.stereotype.Service
import javax.servlet.http.HttpServletResponse
import org.apache.poi.ss.usermodel.BorderStyle
import org.apache.poi.ss.usermodel.Cell
import org.apache.poi.ss.usermodel.CellStyle
import org.apache.poi.ss.usermodel.FillPatternType
import org.apache.poi.ss.usermodel.IndexedColors
Expand Down Expand Up @@ -43,7 +42,7 @@ class GetUserInfo(

val headerRow: Row = sheet.createRow(0)
headerNames.forEachIndexed { i, header ->
val headerCell: Cell = headerRow.createCell(i).apply {
headerRow.createCell(i).apply {
setCellValue(header)
cellStyle = headerCellStyle
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import org.apache.poi.ss.usermodel.FillPatternType
import org.apache.poi.ss.usermodel.IndexedColors
import javax.servlet.http.HttpServletResponse
import org.apache.poi.ss.usermodel.BorderStyle
import org.apache.poi.ss.usermodel.Cell
import org.apache.poi.ss.usermodel.CellStyle
import org.apache.poi.ss.usermodel.Row
import org.apache.poi.ss.usermodel.Sheet
Expand Down Expand Up @@ -37,7 +36,7 @@ class SaveUserInfo {

val headerRow: Row = sheet.createRow(0)
headerNames.forEachIndexed { i, header ->
val headerCell: Cell = headerRow.createCell(i).apply {
headerRow.createCell(i).apply {
setCellValue(header)
cellStyle = headerCellStyle
}
Expand All @@ -55,7 +54,7 @@ class SaveUserInfo {
bodyData.forEachIndexed { i, bodyRowData ->
val bodyRow: Row = sheet.createRow(i + 1)
bodyRowData.forEachIndexed { j, data ->
val bodyCell: Cell = bodyRow.createCell(j).apply {
bodyRow.createCell(j).apply {
setCellValue(data)
cellStyle = bodyCellStyle
}
Expand Down

0 comments on commit 8cf8bb8

Please sign in to comment.