-
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.
[genetic] genetic creature mutate api
- Loading branch information
Showing
7 changed files
with
136 additions
and
15 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
hyunsub-genetic/src/main/kotlin/kim/hyunsub/genetic/bo/GeneticCreatureMutateBo.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,61 @@ | ||
package kim.hyunsub.genetic.bo | ||
|
||
import kim.hyunsub.common.web.error.ErrorCode | ||
import kim.hyunsub.common.web.error.ErrorCodeException | ||
import kim.hyunsub.common.web.model.SimpleResponse | ||
import kim.hyunsub.genetic.model.api.ApiGeneticCreature | ||
import kim.hyunsub.genetic.model.api.toApi | ||
import kim.hyunsub.genetic.model.dto.GeneticCreatureParams | ||
import kim.hyunsub.genetic.repository.entity.GeneticCreature | ||
import kim.hyunsub.genetic.repository.mapper.GeneticCreatureMapper | ||
import kim.hyunsub.genetic.repository.mapper.generateId | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class GeneticCreatureMutateBo( | ||
private val geneticCreatureMapper: GeneticCreatureMapper, | ||
) { | ||
fun create(userId: String, params: GeneticCreatureParams): ApiGeneticCreature { | ||
val entity = GeneticCreature( | ||
id = geneticCreatureMapper.generateId(), | ||
userId = userId, | ||
name = params.name, | ||
birthday = params.birthday, | ||
punch = params.punch, | ||
isMale = params.isMale, | ||
type1 = params.type1, | ||
type2 = params.type2, | ||
type3 = params.type3, | ||
type4 = params.type4, | ||
) | ||
|
||
geneticCreatureMapper.insert(entity) | ||
|
||
return entity.toApi() | ||
} | ||
|
||
fun update(userId: String, creatureId: String, params: GeneticCreatureParams): ApiGeneticCreature { | ||
val entity = geneticCreatureMapper.selectOne(creatureId, userId) | ||
?: throw ErrorCodeException(ErrorCode.NOT_FOUND) | ||
|
||
val newEntity = entity.copy( | ||
name = params.name, | ||
birthday = params.birthday, | ||
punch = params.punch, | ||
isMale = params.isMale, | ||
type1 = params.type1, | ||
type2 = params.type2, | ||
type3 = params.type3, | ||
type4 = params.type4, | ||
) | ||
|
||
geneticCreatureMapper.update(newEntity) | ||
|
||
return newEntity.toApi() | ||
} | ||
|
||
fun delete(userId: String, creatureId: String): SimpleResponse { | ||
geneticCreatureMapper.deleteOne(creatureId, userId) | ||
return SimpleResponse() | ||
} | ||
} |
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
45 changes: 45 additions & 0 deletions
45
...genetic/src/main/kotlin/kim/hyunsub/genetic/controller/GeneticCreatureMutateController.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 kim.hyunsub.genetic.controller | ||
|
||
import kim.hyunsub.common.web.model.SimpleResponse | ||
import kim.hyunsub.common.web.model.UserAuth | ||
import kim.hyunsub.genetic.bo.GeneticCreatureMutateBo | ||
import kim.hyunsub.genetic.model.api.ApiGeneticCreature | ||
import kim.hyunsub.genetic.model.dto.GeneticCreatureParams | ||
import org.springframework.web.bind.annotation.DeleteMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.PutMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/api/v1") | ||
class GeneticCreatureMutateController( | ||
private val geneticCreatureMutateBo: GeneticCreatureMutateBo, | ||
) { | ||
@PostMapping("/creatures") | ||
fun create( | ||
user: UserAuth, | ||
@RequestBody params: GeneticCreatureParams, | ||
): ApiGeneticCreature { | ||
return geneticCreatureMutateBo.create(user.idNo, params) | ||
} | ||
|
||
@PutMapping("/creatures/{creatureId}") | ||
fun update( | ||
user: UserAuth, | ||
@PathVariable creatureId: String, | ||
@RequestBody params: GeneticCreatureParams, | ||
): ApiGeneticCreature { | ||
return geneticCreatureMutateBo.update(user.idNo, creatureId, params) | ||
} | ||
|
||
@DeleteMapping("/creatures/{creatureId}") | ||
fun delete( | ||
user: UserAuth, | ||
@PathVariable creatureId: String, | ||
): SimpleResponse { | ||
return geneticCreatureMutateBo.delete(user.idNo, creatureId) | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
hyunsub-genetic/src/main/kotlin/kim/hyunsub/genetic/model/dto/GeneticCreatureParams.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,12 @@ | ||
package kim.hyunsub.genetic.model.dto | ||
|
||
data class GeneticCreatureParams( | ||
val name: String, | ||
val birthday: String, | ||
val punch: String, | ||
val isMale: Boolean, | ||
val type1: Int, | ||
val type2: Int, | ||
val type3: Int, | ||
val type4: Int, | ||
) |
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