Skip to content
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

Updated to springboot 2.4.11 #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<version>2.6.3</version>
</parent>

<groupId>org.springframework.samples</groupId>
Expand Down
4 changes: 2 additions & 2 deletions spring-petclinic-client/src/scripts/app.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';
/* App Module */
var petClinicApp = angular.module('petClinicApp', [
'ui.router', 'infrastructure', 'layoutNav', 'layoutFooter', 'layoutWelcome',
'ui.router', 'infrastructure', 'hdiv', 'layoutNav', 'layoutFooter', 'layoutWelcome',
'ownerList', 'ownerDetails', 'ownerForm', 'petForm', 'visits', 'vetList']);

petClinicApp.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', '$httpProvider', function(
$stateProvider, $urlRouterProvider, $locationProvider, $httpProvider) {

// safari turns to be lazy sending the Cache-Control header
$httpProvider.defaults.headers.common["Cache-Control"] = 'no-cache';
$httpProvider.interceptors.push('HttpErrorHandlingInterceptor');
//$httpProvider.interceptors.push('HttpErrorHandlingInterceptor');

$locationProvider.hashPrefix('!');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ angular.module('ownerForm')
var id = self.owner.id;

if (id) {
delete self.owner.pets;
$http.put('owners/' + id, self.owner).then(function () {
$state.go('ownerDetails', {ownerId: ownerId});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ angular.module('petForm')
});

self.submit = function () {
var id = self.pet.id || 0;
var id = self.pet.id || undefined;

var data = {
id: id,
Expand Down
12 changes: 12 additions & 0 deletions spring-petclinic-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.samples</groupId>
Expand Down Expand Up @@ -89,6 +94,13 @@
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<jvmArguments>
-Dhdiv.config.dir=../../config
-Dhdiv.server.name=petclinic-server
-Dhdiv.console.token=6a367E2eb97db59020a47340
-Dhdiv.console.url="http://localhost:8180/hdiv-console-services"
-Dhdiv.root.app.name=petclinic-app
</jvmArguments>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,27 @@
*/
package org.springframework.samples.petclinic.web;

import com.fasterxml.jackson.annotation.JsonFormat;
import java.util.Collection;
import java.util.Date;

import javax.validation.constraints.Size;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
import org.springframework.samples.petclinic.model.Owner;
import org.springframework.samples.petclinic.model.Pet;
import org.springframework.samples.petclinic.model.PetType;
import org.springframework.samples.petclinic.service.ClinicService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Size;

import java.util.Collection;
import java.util.Date;
import java.util.Map;
import com.fasterxml.jackson.annotation.JsonFormat;

/**
* @author Juergen Hoeller
Expand All @@ -39,134 +45,153 @@
@RestController
public class PetResource extends AbstractResourceController {

private final ClinicService clinicService;

@Autowired
public PetResource(ClinicService clinicService) {
this.clinicService = clinicService;
}

@GetMapping("/petTypes")
Collection<PetType> getPetTypes() {
return clinicService.findPetTypes();
}

@PostMapping("/owners/{ownerId}/pets")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void processCreationForm(
@RequestBody PetRequest petRequest,
@PathVariable("ownerId") int ownerId) {

Pet pet = new Pet();
Owner owner = this.clinicService.findOwnerById(ownerId);
owner.addPet(pet);

save(pet, petRequest);
}

@PutMapping("/owners/{ownerId}/pets/{petId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void processUpdateForm(@RequestBody PetRequest petRequest) {
save(clinicService.findPetById(petRequest.getId()), petRequest);
}

private void save(Pet pet, PetRequest petRequest) {

pet.setName(petRequest.getName());
pet.setBirthDate(petRequest.getBirthDate());

for (PetType petType : clinicService.findPetTypes()) {
if (petType.getId() == petRequest.getTypeId()) {
pet.setType(petType);
}
}

clinicService.savePet(pet);
}

@GetMapping("/owners/*/pets/{petId}")
public PetDetails findPet(@PathVariable("petId") int petId) {
Pet pet = this.clinicService.findPetById(petId);
return new PetDetails(pet);
}

static class PetRequest {
int id;
@JsonFormat(pattern = "yyyy-MM-dd")
Date birthDate;
@Size(min = 1)
String name;
int typeId;

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public Date getBirthDate() {
return birthDate;
}

public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getTypeId() {
return typeId;
}

public void setTypeId(int typeId) {
this.typeId = typeId;
}
}

static class PetDetails {

int id;
String name;
String owner;
@DateTimeFormat(pattern = "yyyy-MM-dd")
Date birthDate;
PetType type;

PetDetails(Pet pet) {
this.id = pet.getId();
this.name = pet.getName();
this.owner = pet.getOwner().getFirstName() + " " + pet.getOwner().getLastName();
this.birthDate = pet.getBirthDate();
this.type = pet.getType();
}

public int getId() {
return id;
}

public String getName() {
return name;
}

public String getOwner() {
return owner;
}

public Date getBirthDate() {
return birthDate;
}

public PetType getType() {
return type;
}
}
private final ClinicService clinicService;

@Autowired
public PetResource(final ClinicService clinicService) {
this.clinicService = clinicService;
}

@GetMapping("/petTypes")
Collection<PetType> getPetTypes() {
return clinicService.findPetTypes();
}

@PostMapping("/owners/{ownerId}/pets")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void processCreationForm(
@RequestBody final PetRequest petRequest,
@PathVariable("ownerId") final int ownerId) {

Pet pet = new Pet();
Owner owner = clinicService.findOwnerById(ownerId);
owner.addPet(pet);

save(pet, petRequest);
}

@PutMapping("/owners/{ownerId}/pets/{petId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void processUpdateForm(@RequestBody final PetRequest petRequest) {
save(clinicService.findPetById(petRequest.getId()), petRequest);
}

private void save(final Pet pet, final PetRequest petRequest) {

pet.setName(petRequest.getName());
pet.setBirthDate(petRequest.getBirthDate());

for (PetType petType : clinicService.findPetTypes()) {
if (petType.getId() == petRequest.getTypeId()) {
pet.setType(petType);
}
}

clinicService.savePet(pet);
}

@GetMapping("/owners/*/pets/{petId}")
public PetDetails findPet(@PathVariable("petId") final int petId) {
Pet pet = clinicService.findPetById(petId);
return new PetDetails(pet);
}

static class PetRequest {

private int id;

public Integer getId() {
return id;
}

@JsonFormat(pattern = "yyyy-MM-dd")
Date birthDate;

@Size(min = 1)
String name;

int typeId;

public void setId(final int id) {
this.id = id;
}

public Date getBirthDate() {
return birthDate;
}

public void setBirthDate(final Date birthDate) {
this.birthDate = birthDate;
}

public String getName() {
return name;
}

public void setName(final String name) {
this.name = name;
}

public int getTypeId() {
return typeId;
}

public void setTypeId(final int typeId) {
this.typeId = typeId;
}
}

static class PetDetails {
private int id;

public Integer getId() {
return id;
}

String name;

String owner;

@DateTimeFormat(pattern = "yyyy-MM-dd")
Date birthDate;

PetType type;

PetDetails() {
}

PetDetails(final Pet pet) {
id = pet.getId();
name = pet.getName();
owner = pet.getOwner().getFirstName() + " " + pet.getOwner().getLastName();
birthDate = pet.getBirthDate();
type = pet.getType();
}

public PetRequest map(final Class<PetRequest> destinationClass) {
PetRequest request = new PetRequest();
request.setId(id);
request.setBirthDate(birthDate);
request.setName(name);
request.setTypeId(type.getId());
return request;
}

public String getName() {
return name;
}

public String getOwner() {
return owner;
}

public Date getBirthDate() {
return birthDate;
}

public PetType getType() {
return type;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ spring.profiles.active=prod

server.compression.enabled=true
server.compression.mime-types=application/json,text/css,application/javascript
server.compression.min-response-size=2048
server.compression.min-response-size=2048
Loading