Skip to content

Commit

Permalink
update api, add event
Browse files Browse the repository at this point in the history
  • Loading branch information
unanchoi committed Nov 10, 2023
1 parent f82a179 commit 54e121c
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.demoserver.controller
import com.example.demoserver.entity.MemberEntity
import com.example.demoserver.service.MemberService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses
Expand Down Expand Up @@ -50,8 +51,8 @@ class MemberController(
@Operation(summary = "회원가입 API")
@ApiResponses(
value = [
ApiResponse(responseCode = "201", description = "회원가입 성공"),
ApiResponse(responseCode = "400", description = "회원가입 실패")
ApiResponse(responseCode = "201", description = "회원가입 성공", content = [Content(schema = Schema(implementation = Unit::class))]),
ApiResponse(responseCode = "400", description = "회원가입 실패", content = [Content(schema = Schema(implementation = Unit::class))])
]
)
@PostMapping
Expand All @@ -76,7 +77,7 @@ class MemberController(
@ApiResponses(
value = [
ApiResponse(responseCode = "204", description = "로그인 성공"),
ApiResponse(responseCode = "400", description = "로그아웃 실패")
ApiResponse(responseCode = "400", description = "로그아웃 실패", content = [Content(schema = Schema(implementation = Nothing::class))])
]
)
@PostMapping("/sign-in")
Expand All @@ -86,7 +87,9 @@ class MemberController(
}

data class MemberSignInRequest(
@Schema(example = "unanchoi")
val username: String,
@Schema(example = "1234")
val password: String
) {

Expand All @@ -96,7 +99,7 @@ class MemberController(
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "회원가입 성공"),
ApiResponse(responseCode = "404", description = "회원가입 실패")
ApiResponse(responseCode = "404", description = "회원가입 실패" , content = [Content(schema = Schema(implementation = Nothing::class))])
]
)
@GetMapping("/{memberId}"
Expand All @@ -107,7 +110,9 @@ class MemberController(
}

data class MemberGetResponse(
@Schema(example = "unanchoi")
val username: String,
@Schema(example = "윤한이가짱")
val nickname: String
) {
companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example.demoserver.controller

import org.springframework.stereotype.Controller
import org.springframework.stereotype.Service
import org.springframework.ui.Model
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping


@Controller
@RequestMapping("/pepero")
class PeperoController(
private val peperoService: PeperoService
) {

@GetMapping
fun pepero(): String {
return "pepero"
}

@PostMapping("/result")
fun getRandomOne(model: Model) : String {
model.addAttribute("result", peperoService.getRandomOne())
return "pepero_result"
}

@GetMapping("/result")
fun peperoResult(): String{
return "pepero_result"
}

}

@Service
class PeperoService() {
fun getRandomOne() : String {
return serverPart.get((0..serverPart.size).random())
}

companion object {
private val serverPart: List<String> = listOf("김성은","소예원","임주민","김수현","이동섭","도소현","정홍준","안현주","최승준","박예준","정준서","최승빈","최영린","황선웅","김태욱","김다현","현예진","윤정원","이혜연","석미혜","김승환","이승연","현예진","신민철","남궁찬","이나경","송민규","박재연","김보람","박상준","박지영","박희정","박경린","송하연")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.example.demoserver.controller.MemberController
import com.example.demoserver.controller.MemberController.MemberGetResponse
import com.example.demoserver.entity.MemberEntity
import com.example.demoserver.repository.MemberJpaRepository
import io.swagger.v3.oas.annotations.media.Schema
import jakarta.persistence.EntityNotFoundException
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
import org.springframework.security.crypto.password.PasswordEncoder
Expand Down Expand Up @@ -55,8 +56,11 @@ class MemberService(
}

data class MemberSignInResponse(
@Schema(example = "1", description = "사용자 id")
val id : Long,
@Schema(example = "unanchoi")
val username: String,
@Schema(example = "아슈파")
val nickname: String
) {

Expand Down
Binary file added src/main/resources/static/image/server.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions src/main/resources/templates/pepero.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>빼빼로데이 기념 빼빼로 뽑기</title>

<style>
body {
margin: 10vh;
height: 60vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
h1 {
margin-bottom: 20px;
}
img {
width: 1000px;
height: 600px;
}
</style>
</head>
<body>
<img src="/image/server.png" />

<form action="/pepero/result" method="POST">
<button> 뽑기</button>

</form>
</body>
</html>
55 changes: 55 additions & 0 deletions src/main/resources/templates/pepero_result.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>

<style>
body {
margin: 10vh;
height: 60vh;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
h1 {
margin-bottom: 20px;
}
img {
width: 300px;
height: 300px;
}
#countdown {
font-size: 200px;
}
</style>

<script>
function startCountdown() {
var counter = 3;
var interval = setInterval(function() {
document.getElementById('countdown').innerHTML = counter;
counter--;
if (counter < 0 ) {
clearInterval(interval);
document.getElementById('countdown').innerHTML = '{{ result }}'
}
}, 1000);
}
</script>
</head>

<body onload="startCountdown()">
<div id="countdown"></div>
<form action="/pepero" method="GET" style="margin: 100px 0 0 0">
<button type="submit"> 돌아가기 </button>
</form>
</body>
</html>

0 comments on commit 54e121c

Please sign in to comment.