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
a4b9e6c
commit 3cbadec
Showing
7 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/com/byebye/chapterTwo/domain/applicant/controller/ApplicantController.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,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() | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/com/byebye/chapterTwo/domain/applicant/dto/Applicant.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,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 | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/byebye/chapterTwo/domain/applicant/entity/ApplicantEntity.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,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, | ||
) |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/byebye/chapterTwo/domain/applicant/exception/ApplicantErrorCode.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.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, "이미 신청했습니다") | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/byebye/chapterTwo/domain/applicant/repository/ApplicantRepository.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,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> | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/kotlin/com/byebye/chapterTwo/domain/applicant/service/ApplicantService.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,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) | ||
) | ||
} | ||
} |
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