Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
feat :: 회사 도메인 개발
Browse files Browse the repository at this point in the history
  • Loading branch information
LimiteDiTempo committed Aug 26, 2024
1 parent 461f057 commit a4b9e6c
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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<List<BusinessEntity>> {
return businessService.getBusiness()
}

@PostMapping
fun addBusiness(@RequestBody dto: BusinessRequest): BaseResponse<String> {
return businessService.addBusiness(dto)
}

@GetMapping("/{id}")
fun getBusinessDetail(@PathVariable("id") id: Long): BaseResponse<BusinessEntity> {
return businessService.getById(id)
}

}
Original file line number Diff line number Diff line change
@@ -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
)
}
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -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, "이미 신청했습니다")

}
Original file line number Diff line number Diff line change
@@ -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<BusinessEntity, Long> {
}
Original file line number Diff line number Diff line change
@@ -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<String>{
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<List<BusinessEntity>>{
return BaseResponse(
message = "조회 성공",
data = businessRepository.findAll()
)
}

fun getById(id:Long):BaseResponse<BusinessEntity>{
return BaseResponse(
message = "조회 성공",
data = businessRepository.findById(id).orElseThrow{ CustomException(BusinessErrorCode.BUSINESS_NOT_FOUND)}
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ class GooinEntity (

var description: String = "",

var userId: Long,
var userName: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class GooinMapper {
id = entity.id!!,
title = entity.title,
description = entity.description,
userId = entity.userId
userName = entity.userName
)
}

Expand All @@ -20,7 +20,7 @@ class GooinMapper {
id = domain.id?: 0,
title = domain.title,
description = domain.description,
userId = domain.userId
userName = domain.userName
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GooinService(
gooinRepository.save(
gooinMapper.toEntity(Gooin(
dto,
jwtUtils.getMember().id!!
jwtUtils.getMember().name!!
)
)
)
Expand Down

0 comments on commit a4b9e6c

Please sign in to comment.