-
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.
Merge pull request #10 from MEOGO-DSM/9-create-review
🏄 :: (Meogo-9) create review
- Loading branch information
Showing
5 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
16 changes: 15 additions & 1 deletion
16
src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.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 |
---|---|---|
@@ -1,10 +1,24 @@ | ||
package org.meogo.domain.review.presentation | ||
|
||
import lombok.RequiredArgsConstructor | ||
import org.meogo.domain.review.presentation.dto.ReviewRequest | ||
import org.meogo.domain.review.service.CreateReviewService | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import javax.validation.Valid | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/review") | ||
class ReviewController() | ||
class ReviewController( | ||
private val createReviewService: CreateReviewService | ||
) { | ||
@PostMapping | ||
fun create( | ||
@Valid @RequestBody | ||
request: ReviewRequest | ||
) = | ||
createReviewService.execute(request) | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/org/meogo/domain/review/presentation/dto/ReviewRequest.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,11 @@ | ||
package org.meogo.domain.review.presentation.dto | ||
|
||
import javax.validation.constraints.Size | ||
|
||
data class ReviewRequest( | ||
@field:Size(min = 1, max = 300) | ||
val content: String, | ||
val schoolId: Int, | ||
val star: Long, | ||
val image: String? | ||
) |
33 changes: 33 additions & 0 deletions
33
src/main/kotlin/org/meogo/domain/review/service/CreateReviewService.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 org.meogo.domain.review.service | ||
|
||
import org.meogo.domain.review.domain.Review | ||
import org.meogo.domain.review.presentation.dto.ReviewRequest | ||
import org.meogo.domain.review.repository.ReviewRepository | ||
import org.meogo.domain.user.exception.UserNotFoundException | ||
import org.meogo.domain.user.facade.UserFacade | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import java.time.LocalDateTime | ||
|
||
@Service | ||
class CreateReviewService( | ||
private val reviewRepository: ReviewRepository, | ||
private val userFacade: UserFacade | ||
) { | ||
|
||
@Transactional | ||
fun execute(request: ReviewRequest) { | ||
val user = userFacade.currentUser() ?: throw UserNotFoundException | ||
|
||
reviewRepository.save( | ||
Review( | ||
date = LocalDateTime.now(), | ||
userId = user.id!!, | ||
schoolId = request.schoolId, | ||
star = request.star, | ||
content = request.content, | ||
picture = request.image | ||
) | ||
) | ||
} | ||
} |
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,23 @@ | ||
package org.meogo.global.config | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import org.meogo.global.error.GlobalExceptionFilter | ||
import org.meogo.global.jwt.JwtTokenFilter | ||
import org.meogo.global.jwt.JwtTokenProvider | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.security.config.annotation.SecurityConfigurerAdapter | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity | ||
import org.springframework.security.web.DefaultSecurityFilterChain | ||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter | ||
|
||
@Configuration | ||
class FilterConfig( | ||
private val objectMapper: ObjectMapper, | ||
private val jwtTokenProvider: JwtTokenProvider | ||
) : SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity>() { | ||
|
||
override fun configure(builder: HttpSecurity) { | ||
builder.addFilterBefore(JwtTokenFilter(jwtTokenProvider), UsernamePasswordAuthenticationFilter::class.java) | ||
builder.addFilterBefore(GlobalExceptionFilter(objectMapper), JwtTokenFilter::class.java) | ||
} | ||
} |
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