v1.2.9.10 diet_user.macro

This commit is contained in:
bossanyit 2023-06-28 21:44:00 +02:00
parent acc914f170
commit 8d45635684
9 changed files with 36 additions and 6 deletions

View File

@ -11,7 +11,7 @@ plugins {
} }
group = "com.aitrainer" group = "com.aitrainer"
version = "1.2.9" version = "1.2.10"
java.sourceCompatibility = JavaVersion.VERSION_17 java.sourceCompatibility = JavaVersion.VERSION_17
repositories { repositories {

View File

@ -0,0 +1,7 @@
START TRANSACTION;
ALTER TABLE `diet_user` ADD COLUMN `macro` char(255) NULL;
UPDATE configuration set config_value = "1.2.10", date_change=CURRENT_DATE WHERE config_key = "db_version";
COMMIT;

View File

@ -21,4 +21,11 @@ class DietUserController(private val dietUserRepository: DietUserRepository) {
return if (dietUser == null) ResponseEntity.notFound().build() else return if (dietUser == null) ResponseEntity.notFound().build() else
ResponseEntity.ok().body(dietUser) ResponseEntity.ok().body(dietUser)
} }
@PostMapping("/diet_user/{customerId}")
fun updateCustomer(@PathVariable customerId: Long, @RequestBody dietUser: DietUser): ResponseEntity<DietUser> {
dietUserRepository.findByCustomerId(customerId) ?: return ResponseEntity.notFound().build()
val changedUser = dietUserRepository.save(dietUser)
return ResponseEntity.ok().body(changedUser)
}
} }

View File

@ -10,5 +10,6 @@ import javax.validation.constraints.NotNull
@Entity @Entity
data class DietUser( data class DietUser(
@Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) var dietUserId: Long = 0, @Expose @Id @GeneratedValue(strategy = GenerationType.IDENTITY) var dietUserId: Long = 0,
@Expose @get: NotNull val customerId: Long @Expose @get: NotNull val customerId: Long,
@Expose @get: NotNull var macro: String = "",
) )

View File

@ -16,7 +16,7 @@ logging.config=classpath:logback-spring.xml
logging.file=logs logging.file=logs
# if the database structure has been changed, increment this version number # if the database structure has been changed, increment this version number
application.version=1.2.9 application.version=1.2.10
jwt.secret=aitrainer jwt.secret=aitrainer

View File

@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml
logging.file=logs logging.file=logs
# if the database structue has been changed, increment this version number # if the database structue has been changed, increment this version number
application.version=1.2.9 application.version=1.2.10
jwt.secret=aitrainer jwt.secret=aitrainer

View File

@ -14,7 +14,7 @@ logging.config=classpath:logback-spring.xml
logging.file=logs logging.file=logs
# if the database structue has been changed, increment this version number # if the database structue has been changed, increment this version number
application.version=1.2.9 application.version=1.2.10
jwt.secret=aitrainer jwt.secret=aitrainer

View File

@ -17,7 +17,7 @@ logging.config=classpath:logback-spring.xml
logging.file=logs logging.file=logs
# if the database structure has been changed, increment this version number # if the database structure has been changed, increment this version number
application.version=1.2.9 application.version=1.2.10
jwt.secret=aitrainer jwt.secret=aitrainer

View File

@ -50,6 +50,21 @@ class DietUserTest {
.contentType(MediaType.APPLICATION_JSON)) .contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk) .andExpect(status().isOk)
.andExpect(jsonPath("$.customerId").value(1)) .andExpect(jsonPath("$.customerId").value(1))
dietUser.macro = "Test macro"
mockMvc.perform(post("/api/diet_user/999")
.header("Authorization", "Bearer $authToken")
.contentType(MediaType.APPLICATION_JSON)
.content(gson.toJson(dietUser)))
.andExpect(status().isNotFound)
mockMvc.perform(post("/api/diet_user/${dietUser.customerId}")
.header("Authorization", "Bearer $authToken")
.contentType(MediaType.APPLICATION_JSON)
.content(gson.toJson(dietUser)))
.andExpect(status().isOk)
.andExpect(jsonPath("$.customerId").value(1))
.andExpect(jsonPath("$.macro").value("Test macro"))
} }
} }