This repository has been archived by the owner on Aug 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
461f057
commit a4b9e6c
Showing
11 changed files
with
154 additions
and
7 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/com/byebye/chapterTwo/domain/business/controller/BusinessController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/byebye/chapterTwo/domain/business/dto/Business.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/com/byebye/chapterTwo/domain/business/dto/req/BusinessRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/byebye/chapterTwo/domain/business/entity/BusinessEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/byebye/chapterTwo/domain/business/exception/BusinessErrorCode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "이미 신청했습니다") | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/byebye/chapterTwo/domain/business/repository/BusinessRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> { | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/com/byebye/chapterTwo/domain/business/service/BusinessService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)} | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,5 @@ class GooinEntity ( | |
|
||
var description: String = "", | ||
|
||
var userId: Long, | ||
var userName: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters