-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lesson9 #12
base: main
Are you sure you want to change the base?
Conversation
@PostMapping("/{city}") | ||
@ResponseBody | ||
fun addCity(@PathVariable city: String): String { | ||
cityRepository.save(City(0, city)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут всё таки должна возвращаться только что созданная сущность
@Tag(name = "user", description = "The User API") | ||
@Controller | ||
@RequestMapping("/api/user") | ||
class UserController(private val userRepository: UserService, private val cityRepository: CityRepository) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest предполагает, что у тебя есть описание какого то ресурса с примерно такими операциями:
GET /api/users
- получить всех пользователейGET /api/users/{id}
- получить одного пользователяPOST /api/users
- создать пользователяPUT /api/users/{id}
- изменить пользователяDELETE /api/users/{id}
- удалить пользователя
|
||
|
||
@Operation(summary = "Add user", tags = ["user"]) | ||
@PostMapping("/save/{login}/{firstname}/{lastname}/{city}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это делается через body, вот так принимать параметры максимально небезопасно, так как многие балансировщики логируют путь
@PathVariable city: String): String { | ||
val c = cityRepository.findCityByName(city) ?: throw ResponseStatusException(NOT_FOUND, "City don't exist") | ||
userRepository.addUser(User(0, login, firstname, lastname, c.id)) | ||
return "UserSaved" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Таки надо возвращать пользователя
|
||
|
||
@Operation(summary = "Update user", tags = ["user"]) | ||
@PutMapping("/update/{id}/{login}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Поля обычно принимаются через body
import javax.persistence.* | ||
|
||
@Entity | ||
class User(@Id @GeneratedValue var id: Long? = null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А для чего все значения заполнены по умолчанию?
No description provided.