Skip to content
Snippets Groups Projects
Commit 30f3d61c authored by Alexandre Grison's avatar Alexandre Grison
Browse files

Fixes

parent e27b13ba
Branches
No related tags found
No related merge requests found
......@@ -5,22 +5,12 @@
<configuration />
</facet>
<facet type="kotlin-language" name="Kotlin">
<configuration version="1">
<option name="compilerInfo">
<KotlinCompilerInfo>
<option name="compilerSettings">
<CompilerSettings />
</option>
<option name="k2jsCompilerArguments">
<K2JSCompilerArguments />
</option>
<option name="k2jvmCompilerArguments">
<K2JVMCompilerArguments>
<configuration version="2" platform="JVM 1.8" useProjectSettings="false">
<compilerSettings />
<compilerArguments>
<option name="jvmTarget" value="1.8" />
</K2JVMCompilerArguments>
</option>
<option name="_commonCompilerArguments">
<DummyImpl>
<option name="languageVersion" value="1.1" />
<option name="apiVersion" value="1.1" />
<option name="pluginClasspaths">
<array>
<option value="$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-maven-allopen/1.1.2/kotlin-maven-allopen-1.1.2.jar" />
......@@ -35,18 +25,7 @@
<option value="plugin:org.jetbrains.kotlin.allopen:annotation=org.springframework.cache.annotation.Cacheable" />
</array>
</option>
</DummyImpl>
</option>
</KotlinCompilerInfo>
</option>
<option name="useProjectSettings" value="false" />
<option name="versionInfo">
<KotlinVersionInfo>
<option name="apiLevel" value="1.1" />
<option name="languageLevel" value="1.1" />
<option name="targetPlatformName" value="JVM 1.8" />
</KotlinVersionInfo>
</option>
</compilerArguments>
</configuration>
</facet>
</component>
......
......@@ -2,7 +2,7 @@ package io.realworld.exception
import org.springframework.validation.Errors
data class InvalidException(val errors: Errors) : RuntimeException()
data class InvalidException(val errors: Errors?) : RuntimeException()
object InvalidRequest {
fun check(errors: Errors) {
......
......@@ -116,7 +116,7 @@ class ApiKeySecuredAspect(@Autowired val userService: UserService) {
if (StringUtils.isEmpty(e.message)) rs.reason else e.message,
rs.value)
} else {
LOG.error("ERROR accessing resource", e)
LOG.error("ERROR accessing resource")
}
throw e
}
......
......@@ -9,7 +9,7 @@ import javax.validation.constraints.Size
class Login {
@NotNull(message = "can't be missing")
@Size(min = 1, message = "can't be empty")
@Pattern(regexp="^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$", message="must be a valid email")
@Pattern(regexp="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$", message="must be a valid email")
var email: String? = ""
@NotNull(message = "can't be missing")
......
......@@ -14,7 +14,7 @@ class Register {
@NotNull(message = "can't be missing")
@Size(min = 1, message = "can't be empty")
@Pattern(regexp="^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$", message="must be a valid email")
@Pattern(regexp="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$", message="must be a valid email")
var email: String? = ""
@NotNull(message = "can't be missing")
......
package io.realworld.model.inout
import com.fasterxml.jackson.annotation.JsonRootName
import javax.validation.constraints.NotNull
import javax.validation.constraints.Pattern
import javax.validation.constraints.Size
@JsonRootName("user")
data class UpdateUser(var username: String? = null,
var email: String? = null,
var password: String? = null,
var image: String? = null,
var bio: String? = null)
\ No newline at end of file
class UpdateUser {
@Size(min = 1, message = "can't be empty")
@Pattern(regexp="^\\w+$", message = "must be alphanumeric")
var username: String? = null
@Size(min = 1, message = "can't be empty")
@Pattern(regexp="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$", message="must be a valid email")
var email: String? = null
var password: String? = null
var image: String? = ""
var bio: String? = ""
}
\ No newline at end of file
......@@ -20,6 +20,7 @@ import io.realworld.repository.specification.ArticlesSpecifications
import io.realworld.service.UserService
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Sort
import org.springframework.http.HttpStatus
import org.springframework.validation.Errors
import org.springframework.validation.FieldError
import org.springframework.web.bind.annotation.*
......@@ -147,6 +148,7 @@ class ArticleHandler(val repository: ArticleRepository,
}
@ApiKeySecured
@ResponseStatus(HttpStatus.OK)
@DeleteMapping("/api/articles/{slug}")
fun deleteArticle(@PathVariable slug: String) {
repository.findBySlug(slug)?.let {
......@@ -183,13 +185,18 @@ class ArticleHandler(val repository: ArticleRepository,
}
@ApiKeySecured
@ResponseStatus(HttpStatus.OK)
@DeleteMapping("/api/articles/{slug}/comments/{id}")
fun deleteComment(@PathVariable slug: String, @PathVariable id: Long) {
repository.findBySlug(slug)?.let {
val currentUser = userService.currentUser()
val comment = commentRepository.findById(id).orElseThrow({ NotFoundException() })
if (comment.article.id == it.id)
return commentRepository.delete(comment)
if (comment.article.id != it.id)
throw ForbiddenRequestException()
if (comment.author.id != currentUser.id)
throw ForbiddenRequestException()
return commentRepository.delete(comment)
}
throw NotFoundException()
}
......
......@@ -29,7 +29,7 @@ class InvalidRequestHandler {
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
fun processValidationError(ex: InvalidException): Any {
val errors = mutableMapOf<String, MutableList<String>>()
ex.errors.fieldErrors.forEach {
ex.errors?.fieldErrors?.forEach {
if (errors.containsKey(it.field))
errors.get(it.field)!!.add(it.defaultMessage)
else
......
......@@ -57,7 +57,9 @@ class UserHandler(val repository: UserRepository,
@ApiKeySecured
@PutMapping("/api/user")
fun updateUser(@RequestBody user: UpdateUser): Any {
fun updateUser(@Valid @RequestBody user: UpdateUser, errors: Errors): Any {
InvalidRequest.check(errors)
val currentUser = service.currentUser()
// check for errors
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment