Skip to content

adding-and-retrieving-professional - #2

Open
hokka1do wants to merge 4 commits into
masterfrom
adding-and-retrieving-professional
Open

adding-and-retrieving-professional#2
hokka1do wants to merge 4 commits into
masterfrom
adding-and-retrieving-professional

Conversation

@hokka1do

Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/main/java/com/hokka1do/bookme/professionals/Professional.java
@Autowired
private ProfessionalRepository professionalRepository;

@GetMapping("/professional/get")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SpringApplication.run(BookMeApplication.class, args);
}
@PostConstruct
private void initDb(){

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DB initialization should be done using sql resource files

import java.util.NoSuchElementException;

@RestController
@RequestMapping("/api/professional")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resource collection URL should be defined in the plural


@GetMapping
public List<Professional> getAllProfessionals() {
return (List<Professional>) professionalRepository.findAll();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class casting is not needed

@GetMapping("/id")
public ResponseEntity<Professional> findProfessionalById(@PathVariable(value = "id") Long professionalId) {
Professional professional = professionalRepository.findById(professionalId).orElseThrow(() ->
new NoSuchElementException(("Professional not available for Id :" + professionalId)));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not bad. But does your application return a 404 error response in such a case?

Comment thread src/main/java/com/hokka1do/bookme/service/ProfessionalService.java
@@ -1 +1,20 @@
spring.datasource.url=jdbc:h2:mem:professional-db

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use application.yaml file format for properties

public class BookMeApplication {

@Autowired
private ProfessionalRepository professionalRepository;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary , remove it

Comment thread src/main/resources/application.properties
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants