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 a4b9e6c commit 3cbadec
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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<String> {
return applicantService.applicant(id)
}

@GetMapping("/{id}")
fun getApplicantById(@PathVariable id: Long): BaseResponse<List<ApplicantEntity>> {
return applicantService.myApplicantsById(id)
}

@GetMapping("/my/{id}")
fun getApplicantByName(): BaseResponse<List<ApplicantEntity>> {
return applicantService.myApplicantsByName()
}

@GetMapping("/all")
fun getAllApplicants(): BaseResponse<List<ApplicantEntity>> {
return applicantService.getApplicants()
}

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

}
Original file line number Diff line number Diff line change
@@ -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<ApplicantEntity,Long> {
fun findAllByUserName(username: String): List<ApplicantEntity>
fun findAllByGooinId(id: Long): List<ApplicantEntity>
}
Original file line number Diff line number Diff line change
@@ -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<String>{
applicantRepository.save(ApplicantEntity(
id = null,
gooinId = id,
userName = jwtUtils.getMember().name
))
return BaseResponse(
message = "지원 성공"
)
}

fun getApplicants(): BaseResponse<List<ApplicantEntity>> {
return BaseResponse(
message = "조회 성공",
data = applicantRepository.findAll()
)
}

fun myApplicantsByName() : BaseResponse<List<ApplicantEntity>> {
return BaseResponse(
message = "조회 성공",
data = applicantRepository.findAllByUserName(jwtUtils.getMember().name)
)
}

fun myApplicantsById(id: Long) : BaseResponse<List<ApplicantEntity>> {
return BaseResponse(
message = "조회 성공",
data = applicantRepository.findAllByGooinId(id)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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, "해당 회사를 찾을 수 없습니다")

}

0 comments on commit 3cbadec

Please sign in to comment.