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

Add pet feature #32

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
897f35b
Update readme.md
iebouihi Dec 25, 2023
c15ba86
Update app.js
iebouihi Dec 25, 2023
ab06f8a
Create .sonarcloud.properties
iebouihi Dec 25, 2023
3e24312
Update .sonarcloud.properties
iebouihi Dec 25, 2023
2936508
Update visits.js
iebouihi Dec 25, 2023
63b3076
Update pom.xml
iebouihi Dec 25, 2023
8bd26e6
Update pom.xml
iebouihi Dec 25, 2023
cef9648
Update pom.xml
iebouihi Dec 25, 2023
8533894
Update visits.js
iebouihi Dec 25, 2023
b958a05
Update pom.xml
iebouihi Dec 25, 2023
d98e2c5
Create build.yml
iebouihi Dec 25, 2023
1057e2f
Update visits.controller.js
iebouihi Dec 25, 2023
128b06d
Update .bowerrc
iebouihi Dec 25, 2023
55a4c95
Update .bowerrc
iebouihi Dec 25, 2023
de0c69c
Update .bowerrc
iebouihi Dec 25, 2023
411cf35
Update .bowerrc
iebouihi Dec 25, 2023
202267d
Update .bowerrc
iebouihi Dec 25, 2023
c3f8555
Update .bowerrc
iebouihi Dec 25, 2023
581e3b9
Update .bowerrc
iebouihi Dec 25, 2023
579f3ac
Update .bowerrc
iebouihi Dec 25, 2023
0830364
Update pom.xml Relpve Gulp
iebouihi Dec 25, 2023
8648d5d
Update .sonarcloud.properties
iebouihi Dec 25, 2023
71f0484
Update pom.xml
iebouihi Dec 25, 2023
4f03664
Merge pull request #2 from iebouihi/sonarcloud
iebouihi Dec 25, 2023
7c01275
Create main.yml
iebouihi Apr 3, 2024
69e4f7a
Merge pull request #3 from iebouihi/code-review-ai
iebouihi Apr 3, 2024
935d2f5
AI review
Apr 3, 2024
d64fadf
TEST AI review
Apr 3, 2024
0ca1a50
TEST AI review
Apr 3, 2024
5b28d2e
TEST AI review
Apr 3, 2024
ad051c7
Merge pull request #7 from iebouihi/openai-pr
iebouihi Apr 3, 2024
62e2e0c
Add Visit Feature
Oct 2, 2024
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
37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: SonarCloud
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
name: Build and analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=iebouihi_spring-petclinic-angularjs
22 changes: 22 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: AI Code Reviewer

on:
pull_request:
types:
- opened
- synchronize
permissions: write-all
jobs:
review:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: AI Code Reviewer
uses: iebouihi/ai-codereviewer@main
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_API_MODEL: "gpt-4" # Optional: defaults to "gpt-4"
exclude: "**/*.json, **/*.md" # Optional: exclude patterns separated by commas
15 changes: 15 additions & 0 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Path to sources
#sonar.sources=spring-petclinic-client/src,spring-petclinic-server/src
#sonar.exclusions=
#sonar.inclusions=

# Path to tests
#sonar.tests=
#sonar.test.exclusions=
#sonar.test.inclusions=

# Source encoding
#sonar.sourceEncoding=UTF-8

# Exclusions for copy-paste detection
#sonar.cpd.exclusions=
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<sonar.organization>iebouihi</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -74,4 +78,5 @@
</pluginRepositories>



</project>
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[See the presentation here](http://fr.slideshare.net/AntoineRey/spring-framework-petclinic-sample-application)

## Running petclinic locally

```
git clone https://github.com/spring-petclinic/spring-petclinic-angularjs.git
cd spring-petclinic-angularjs
Expand Down
3 changes: 2 additions & 1 deletion spring-petclinic-client/.bowerrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"registry": "https://registry.bower.io"
"registry": "https://registry.bower.io",
"strict-ssl": false
}
3 changes: 3 additions & 0 deletions spring-petclinic-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<properties>
<node.version>v4.4.3</node.version>
<npm.version>2.15.1</npm.version>
<sonar.sources>src</sonar.sources>
</properties>

<build>
Expand Down Expand Up @@ -56,12 +57,14 @@
<goal>bower</goal>
</goals>
</execution>
<!--
<execution>
<id>gulp build</id>
<goals>
<goal>gulp</goal>
</goals>
</execution>
-->
</executions>
</plugin>
<plugin>
Expand Down
2 changes: 1 addition & 1 deletion spring-petclinic-client/src/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var petClinicApp = angular.module('petClinicApp', [

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

console.log("Secret");
// safari turns to be lazy sending the Cache-Control header
$httpProvider.defaults.headers.common["Cache-Control"] = 'no-cache';
$httpProvider.interceptors.push('HttpErrorHandlingInterceptor');
Expand Down
20 changes: 20 additions & 0 deletions spring-petclinic-client/src/scripts/visits/visits.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,23 @@ angular.module('visits')
});
};
}]);
function aaToooLong_Non_MeaningfulMethodeBlaBlaBlaBlaaaToooLong_Non_MeaningfulMethodeBlaBlaBlaBla()
{
for (let c = 0; c < brickColumnCount; c++) {
for (let r = 0; r < brickRowCount; r++) {
const b = bricks[c][r];
if (b.status === 1) {
if (
x > b.x &&
x < b.x + brickWidth &&
y > b.y &&
y < b.y + brickHeight
) {
dy = -dy;
b.status = 0;
score++;
}
}
}
}
}
81 changes: 81 additions & 0 deletions spring-petclinic-client/src/scripts/visits/visits.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,84 @@ angular.module('visits', ['ui.router'])
template: '<visits></visits>'
})
}]);
function aaToooLong_Non_MeaningfulMethodeBlaBlaBlaBlaaaToooLong_Non_MeaningfulMethodeBlaBlaBlaBla()
{
for (let c = 0; c < brickColumnCount; c++) {
for (let r = 0; r < brickRowCount; r++) {
const b = bricks[c][r];
if (b.status === 1) {
if (
x > b.x &&
x < b.x + brickWidth &&
y > b.y &&
y < b.y + brickHeight
) {
dy = -dy;
b.status = 0;
score++;
}
}
}
}
}

function aaToooLong_Non_MeaningfulMethodeBlaBlaBlaBlaaaToooLong_Non_MeaningfulMethodeBlaBlaBlaBla2222()
{
for (let c = 0; c < brickColumnCount; c++) {
for (let r = 0; r < brickRowCount; r++) {
const b = bricks[c][r];
if (b.status === 1) {
if (
x > b.x &&
x < b.x + brickWidth &&
y > b.y &&
y < b.y + brickHeight
) {
dy = -dy;
b.status = 0;
score++;
}
}
}
}
}

function function aaToooLong_Non_MeaningfulMethodeBlaBlaBlaBlaaaToooLong_Non_MeaningfulMethodeBlaBlaBlaBla2222()
{
for (let c = 0; c < brickColumnCount; c++) {
for (let r = 0; r < brickRowCount; r++) {
const b = bricks[c][r];
if (b.status === 1) {
if (
x > b.x &&
x < b.x + brickWidth &&
y > b.y &&
y < b.y + brickHeight
) {
dy = -dy;
b.status = 0;
score++;
}
}
}
}
}()
{
for (let c = 0; c < brickColumnCount; c++) {
for (let r = 0; r < brickRowCount; r++) {
const b = bricks[c][r];
if (b.status === 1) {
if (
x > b.x &&
x < b.x + brickWidth &&
y > b.y &&
y < b.y + brickHeight
) {
dy = -dy;
b.status = 0;
score++;
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Logger;

/**
* Simple business object representing a pet.
Expand Down Expand Up @@ -62,7 +63,9 @@ public class Pet extends NamedEntity {

@OneToMany(cascade = CascadeType.ALL, mappedBy = "pet", fetch = FetchType.EAGER)
private Set<Visit> visits;

Logger logger = Logger.getLogger(Pet.class.getName());
private static final String DATABASE_PASSWORD = "superSecretPassword123!";
private static final String API_KEY = "abcd1234efgh5678";

public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
Expand Down Expand Up @@ -109,5 +112,10 @@ public void addVisit(Visit visit) {
getVisitsInternal().add(visit);
visit.setPet(this);
}
public Visit getLastPetVisit() {
List<Visit> sortedVisits = new ArrayList<>(getVisitsInternal());
PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false));
return sortedVisits.get(0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ public interface ClinicService {

Collection<Owner> findAll();

void addVisit(String petId, String visitDetails);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.springframework.samples.petclinic.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.samples.petclinic.model.*;
Expand All @@ -41,6 +43,7 @@ public class ClinicServiceImpl implements ClinicService {
private final VetRepository vetRepository;
private final OwnerRepository ownerRepository;
private final VisitRepository visitRepository;
private final static Logger logger = LoggerFactory.getLogger(ClinicServiceImpl.class);

@Autowired
public ClinicServiceImpl(PetRepository petRepository, VetRepository vetRepository, OwnerRepository ownerRepository, VisitRepository visitRepository) {
Expand Down Expand Up @@ -100,5 +103,21 @@ public Collection<Vet> findVets() throws DataAccessException {
return vetRepository.findAll();
}

@Override
public void addVisit(String petId, String visitDetails) {
try {

Pet pet = petRepository.findById(Integer.parseInt(petId));
Visit visit = new Visit();
visit.setDescription(visitDetails);
visit.setPet(pet);
visitRepository.save(visit);

} catch (Exception e) {
logger.error("An error has occurred l");
throw new RuntimeException(e);
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ public void shouldNotValidateWhenFirstNameEmpty() {
assertThat(violation.getMessage()).isEqualTo("must not be empty");
}


}