-
Notifications
You must be signed in to change notification settings - Fork 1
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
7c94d01
commit 2956941
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
api/src/main/kotlin/com/few/api/web/controller/hello/_HelloController.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,46 @@ | ||
package com.few.api.web.controller.hello | ||
|
||
import com.few.api.web.controller.hello.request._HelloBody | ||
import com.few.api.web.controller.hello.request._HelloParam | ||
import com.few.api.web.support.ApiResponse | ||
import com.few.api.web.support.ApiResponseGenerator | ||
import com.few.api.web.support.MessageCode | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.validation.annotation.Validated | ||
import org.springframework.web.bind.annotation.* | ||
|
||
@Validated | ||
@RestController | ||
@RequestMapping("/api/v1/hello") | ||
class _HelloController { | ||
|
||
/** | ||
* @param param 객체로 파라미터를 받는 경우 | ||
* @param club RequestParam을 사용하는 경우 | ||
*/ | ||
@GetMapping | ||
fun helloGet( | ||
param: _HelloParam?, | ||
@RequestParam(required = true) club: String | ||
): ApiResponse<ApiResponse.SuccessBody<Map<String, String>>> { | ||
val name = param?.name ?: "few" | ||
val age = param?.age ?: 0 | ||
val club = club | ||
val data = | ||
mapOf("hello" to "world", "name" to name, "age" to age.toString(), "club" to club) | ||
return ApiResponseGenerator.success(data, HttpStatus.OK) | ||
} | ||
|
||
@PostMapping | ||
fun helloPost( | ||
@RequestBody body: _HelloBody | ||
): ApiResponse<ApiResponse.SuccessBody<Map<String, String>>> { | ||
val data = mapOf("hello" to "world", "name" to body.name) | ||
return ApiResponseGenerator.success(data, HttpStatus.OK, MessageCode.RESOURCE_CREATED) | ||
} | ||
|
||
@GetMapping("/error") | ||
fun helloError(): ApiResponse<ApiResponse.Success> { | ||
throw RuntimeException("Hello Error") | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
api/src/main/kotlin/com/few/api/web/controller/hello/request/_HelloBody.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,5 @@ | ||
package com.few.api.web.controller.hello.request | ||
|
||
data class _HelloBody( | ||
val name: String | ||
) |
6 changes: 6 additions & 0 deletions
6
api/src/main/kotlin/com/few/api/web/controller/hello/request/_HelloParam.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,6 @@ | ||
package com.few.api.web.controller.hello.request | ||
|
||
data class _HelloParam( | ||
val name: String?, | ||
val age: Int? | ||
) |