diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/business/controller/BusinessController.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/business/controller/BusinessController.kt new file mode 100644 index 0000000..083a665 --- /dev/null +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/business/controller/BusinessController.kt @@ -0,0 +1,29 @@ +package com.byebye.chapterTwo.domain.business.controller + +import com.byebye.chapterTwo.domain.business.dto.req.BusinessRequest +import com.byebye.chapterTwo.domain.business.entity.BusinessEntity +import com.byebye.chapterTwo.domain.business.service.BusinessService +import com.byebye.chapterTwo.global.common.BaseResponse +import org.springframework.web.bind.annotation.* + +@RestController +@RequestMapping("/business") +class BusinessController( + private val businessService: BusinessService +) { + @GetMapping + fun getBusinesses(): BaseResponse> { + return businessService.getBusiness() + } + + @PostMapping + fun addBusiness(@RequestBody dto: BusinessRequest): BaseResponse { + return businessService.addBusiness(dto) + } + + @GetMapping("/{id}") + fun getBusinessDetail(@PathVariable("id") id: Long): BaseResponse { + return businessService.getById(id) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/business/dto/Business.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/business/dto/Business.kt new file mode 100644 index 0000000..27d2c82 --- /dev/null +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/business/dto/Business.kt @@ -0,0 +1,21 @@ +package com.byebye.chapterTwo.domain.business.dto + +import com.byebye.chapterTwo.domain.business.dto.req.BusinessRequest + +data class Business( + val id: Long? = null, + var name: String, + var shortDescription: String, + var description: String, + var ceo: String, + var phoneNum: String +){ + constructor(dto: BusinessRequest) : this( + id = null?:0, + name = dto.name, + shortDescription = dto.shortDescription, + description = dto.description, + ceo = dto.ceo, + phoneNum = dto.phoneNum + ) +} diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/business/dto/req/BusinessRequest.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/business/dto/req/BusinessRequest.kt new file mode 100644 index 0000000..b484be2 --- /dev/null +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/business/dto/req/BusinessRequest.kt @@ -0,0 +1,11 @@ +package com.byebye.chapterTwo.domain.business.dto.req + +import com.fasterxml.jackson.annotation.JsonProperty + +data class BusinessRequest( + @JsonProperty("name") val name : String, + @JsonProperty("description") val description : String, + @JsonProperty("shortDescription") val shortDescription : String, + @JsonProperty("ceo") val ceo : String, + @JsonProperty("phoneNum") val phoneNum : String, +) diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/business/entity/BusinessEntity.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/business/entity/BusinessEntity.kt new file mode 100644 index 0000000..05bb142 --- /dev/null +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/business/entity/BusinessEntity.kt @@ -0,0 +1,23 @@ +package com.byebye.chapterTwo.domain.business.entity + +import jakarta.persistence.Entity +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id + +@Entity +class BusinessEntity ( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + var id : Long? = null, + + var name: String, + + var description: String, + + var shortDescription: String, + + var ceo: String, + + var phoneNum: String +) \ No newline at end of file diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/business/exception/BusinessErrorCode.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/business/exception/BusinessErrorCode.kt new file mode 100644 index 0000000..2183ca1 --- /dev/null +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/business/exception/BusinessErrorCode.kt @@ -0,0 +1,14 @@ +package com.byebye.chapterTwo.domain.business.exception + +import com.byebye.chapterTwo.global.auth.exception.CustomErrorCode +import org.springframework.http.HttpStatus + +enum class BusinessErrorCode ( + override val status: HttpStatus, + override val message: String, +) : CustomErrorCode { + + BUSINESS_NOT_FOUND(HttpStatus.NOT_FOUND, "신청하고 싶은 구인 요청을 찾을 수 없습니다"), + BUSINESS_ALREADY_EXIST(HttpStatus.CONFLICT, "이미 신청했습니다") + +} \ No newline at end of file diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/business/repository/BusinessRepository.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/business/repository/BusinessRepository.kt new file mode 100644 index 0000000..0602386 --- /dev/null +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/business/repository/BusinessRepository.kt @@ -0,0 +1,7 @@ +package com.byebye.chapterTwo.domain.business.repository + +import com.byebye.chapterTwo.domain.business.entity.BusinessEntity +import org.springframework.data.jpa.repository.JpaRepository + +interface BusinessRepository : JpaRepository { +} \ No newline at end of file diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/business/service/BusinessService.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/business/service/BusinessService.kt new file mode 100644 index 0000000..7c8bd57 --- /dev/null +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/business/service/BusinessService.kt @@ -0,0 +1,42 @@ +package com.byebye.chapterTwo.domain.business.service + +import com.byebye.chapterTwo.domain.business.dto.req.BusinessRequest +import com.byebye.chapterTwo.domain.business.entity.BusinessEntity +import com.byebye.chapterTwo.domain.business.exception.BusinessErrorCode +import com.byebye.chapterTwo.domain.business.repository.BusinessRepository +import com.byebye.chapterTwo.global.auth.exception.CustomException +import com.byebye.chapterTwo.global.common.BaseResponse +import org.springframework.stereotype.Service + +@Service +class BusinessService( + private val businessRepository: BusinessRepository, +) { + fun addBusiness(dto: BusinessRequest):BaseResponse{ + businessRepository.save(BusinessEntity(null, + name = dto.name, + description = dto.description, + shortDescription = dto.shortDescription, + ceo = dto.ceo, + phoneNum = dto.phoneNum) + ) + return BaseResponse( + message = "생성 성공!!" + ) + } + + fun getBusiness(): BaseResponse>{ + return BaseResponse( + message = "조회 성공", + data = businessRepository.findAll() + ) + } + + fun getById(id:Long):BaseResponse{ + return BaseResponse( + message = "조회 성공", + data = businessRepository.findById(id).orElseThrow{ CustomException(BusinessErrorCode.BUSINESS_NOT_FOUND)} + ) + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/dto/Gooin.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/dto/Gooin.kt index 730f930..f18fbd7 100644 --- a/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/dto/Gooin.kt +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/dto/Gooin.kt @@ -6,13 +6,13 @@ data class Gooin( val id: Long? = null, var title: String, var description: String, - val userId: Long, + val userName: String, ){ - constructor(dto: AddGooinRequest, userId: Long) : this( + constructor(dto: AddGooinRequest, userName: String) : this( id = null?:0, title = dto.title, description = dto.description, - userId = userId + userName = userName, ) fun editGooin(dto: AddGooinRequest){ diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/entity/GooinEntity.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/entity/GooinEntity.kt index 9de0eeb..535b186 100644 --- a/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/entity/GooinEntity.kt +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/entity/GooinEntity.kt @@ -15,5 +15,5 @@ class GooinEntity ( var description: String = "", - var userId: Long, + var userName: String, ) \ No newline at end of file diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/mapper/GooinMapper.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/mapper/GooinMapper.kt index 0daf49f..ba5cc8f 100644 --- a/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/mapper/GooinMapper.kt +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/mapper/GooinMapper.kt @@ -11,7 +11,7 @@ class GooinMapper { id = entity.id!!, title = entity.title, description = entity.description, - userId = entity.userId + userName = entity.userName ) } @@ -20,7 +20,7 @@ class GooinMapper { id = domain.id?: 0, title = domain.title, description = domain.description, - userId = domain.userId + userName = domain.userName ) } } \ No newline at end of file diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/service/GooinService.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/service/GooinService.kt index d9442a2..9c3c3e0 100644 --- a/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/service/GooinService.kt +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/gooin/service/GooinService.kt @@ -22,7 +22,7 @@ class GooinService( gooinRepository.save( gooinMapper.toEntity(Gooin( dto, - jwtUtils.getMember().id!! + jwtUtils.getMember().name!! ) ) )