diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/controller/ApplicantController.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/controller/ApplicantController.kt new file mode 100644 index 0000000..1a57db1 --- /dev/null +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/controller/ApplicantController.kt @@ -0,0 +1,33 @@ +package com.byebye.chapterTwo.domain.applicant.controller + +import com.byebye.chapterTwo.domain.applicant.entity.ApplicantEntity +import com.byebye.chapterTwo.domain.applicant.service.ApplicantService +import com.byebye.chapterTwo.global.common.BaseResponse +import org.springframework.web.bind.annotation.* + +@RestController +@RequestMapping("/applicant") +class ApplicantController ( + private val applicantService: ApplicantService +){ + @PostMapping("/{id}") + fun applicant(@PathVariable id: Long) : BaseResponse { + return applicantService.applicant(id) + } + + @GetMapping("/{id}") + fun getApplicantById(@PathVariable id: Long): BaseResponse> { + return applicantService.myApplicantsById(id) + } + + @GetMapping("/my/{id}") + fun getApplicantByName(): BaseResponse> { + return applicantService.myApplicantsByName() + } + + @GetMapping("/all") + fun getAllApplicants(): BaseResponse> { + return applicantService.getApplicants() + } + +} \ No newline at end of file diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/dto/Applicant.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/dto/Applicant.kt new file mode 100644 index 0000000..b11268f --- /dev/null +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/dto/Applicant.kt @@ -0,0 +1,13 @@ +package com.byebye.chapterTwo.domain.applicant.dto + +data class Applicant( + val id : Long? = null, + val gooinId: Long, + val userName : String, +){ + constructor(id:Long, userName: String) : this( + id = null?:0, + gooinId = id, + userName = userName + ) +} diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/entity/ApplicantEntity.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/entity/ApplicantEntity.kt new file mode 100644 index 0000000..e42774a --- /dev/null +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/entity/ApplicantEntity.kt @@ -0,0 +1,15 @@ +package com.byebye.chapterTwo.domain.applicant.entity + +import jakarta.persistence.Entity +import jakarta.persistence.GeneratedValue +import jakarta.persistence.GenerationType +import jakarta.persistence.Id + +@Entity +class ApplicantEntity ( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id : Long? = null, + var gooinId : Long, + var userName: String, + ) \ No newline at end of file diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/exception/ApplicantErrorCode.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/exception/ApplicantErrorCode.kt new file mode 100644 index 0000000..2221fc6 --- /dev/null +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/exception/ApplicantErrorCode.kt @@ -0,0 +1,14 @@ +package com.byebye.chapterTwo.domain.applicant.exception + +import com.byebye.chapterTwo.global.auth.exception.CustomErrorCode +import org.springframework.http.HttpStatus + +enum class ApplicantErrorCode ( + override val status: HttpStatus, + override val message: String, +) : CustomErrorCode { + + APPLICANT_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/applicant/repository/ApplicantRepository.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/repository/ApplicantRepository.kt new file mode 100644 index 0000000..7b56dc7 --- /dev/null +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/repository/ApplicantRepository.kt @@ -0,0 +1,9 @@ +package com.byebye.chapterTwo.domain.applicant.repository + +import com.byebye.chapterTwo.domain.applicant.entity.ApplicantEntity +import org.springframework.data.jpa.repository.JpaRepository + +interface ApplicantRepository : JpaRepository { + fun findAllByUserName(username: String): List + fun findAllByGooinId(id: Long): List +} \ No newline at end of file diff --git a/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/service/ApplicantService.kt b/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/service/ApplicantService.kt new file mode 100644 index 0000000..637f74e --- /dev/null +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/applicant/service/ApplicantService.kt @@ -0,0 +1,45 @@ +package com.byebye.chapterTwo.domain.applicant.service + +import com.byebye.chapterTwo.domain.applicant.entity.ApplicantEntity +import com.byebye.chapterTwo.domain.applicant.repository.ApplicantRepository +import com.byebye.chapterTwo.global.auth.jwt.JwtUtils +import com.byebye.chapterTwo.global.common.BaseResponse +import org.springframework.stereotype.Service + +@Service +class ApplicantService( + private val applicantRepository: ApplicantRepository, + private val jwtUtils: JwtUtils +) { + fun applicant(id: Long): BaseResponse{ + applicantRepository.save(ApplicantEntity( + id = null, + gooinId = id, + userName = jwtUtils.getMember().name + )) + return BaseResponse( + message = "지원 성공" + ) + } + + fun getApplicants(): BaseResponse> { + return BaseResponse( + message = "조회 성공", + data = applicantRepository.findAll() + ) + } + + fun myApplicantsByName() : BaseResponse> { + return BaseResponse( + message = "조회 성공", + data = applicantRepository.findAllByUserName(jwtUtils.getMember().name) + ) + } + + fun myApplicantsById(id: Long) : BaseResponse> { + return BaseResponse( + message = "조회 성공", + data = applicantRepository.findAllByGooinId(id) + ) + } +} \ 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 index 2183ca1..4005320 100644 --- a/src/main/kotlin/com/byebye/chapterTwo/domain/business/exception/BusinessErrorCode.kt +++ b/src/main/kotlin/com/byebye/chapterTwo/domain/business/exception/BusinessErrorCode.kt @@ -8,7 +8,6 @@ enum class BusinessErrorCode ( override val message: String, ) : CustomErrorCode { - BUSINESS_NOT_FOUND(HttpStatus.NOT_FOUND, "신청하고 싶은 구인 요청을 찾을 수 없습니다"), - BUSINESS_ALREADY_EXIST(HttpStatus.CONFLICT, "이미 신청했습니다") + BUSINESS_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 회사를 찾을 수 없습니다") } \ No newline at end of file