Skip to content

Commit 1ef4b19

Browse files
authored
Merge pull request #173 from doubleSlashde/feature/#165_Rest-API-New
Feature/#165 rest api new
2 parents dbed3d6 + ec823f7 commit 1ef4b19

28 files changed

+1685
-566
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ logs/
3030

3131
config.xml
3232
/db/
33+
application.properties

pom.xml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@
4848
</properties>
4949

5050
<dependencies>
51+
<dependency>
52+
<groupId>org.mapstruct</groupId>
53+
<artifactId>mapstruct</artifactId>
54+
<version>1.5.5.Final</version>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.mapstruct</groupId>
58+
<artifactId>mapstruct-processor</artifactId>
59+
<version>1.5.5.Final</version>
60+
<scope>provided</scope>
61+
</dependency>
5162
<dependency>
5263
<groupId>org.openjfx</groupId>
5364
<artifactId>javafx-controls</artifactId>
@@ -85,6 +96,27 @@
8596
<groupId>org.springframework.boot</groupId>
8697
<artifactId>spring-boot-starter-data-jpa</artifactId>
8798
</dependency>
99+
<dependency>
100+
<groupId>org.springframework.boot</groupId>
101+
<artifactId>spring-boot-starter-web</artifactId>
102+
</dependency>
103+
<dependency>
104+
<groupId>org.springdoc</groupId>
105+
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
106+
<version>2.5.0</version>
107+
</dependency>
108+
<dependency>
109+
<groupId>org.springframework.boot</groupId>
110+
<artifactId>spring-boot-starter-validation</artifactId>
111+
</dependency>
112+
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
113+
<dependency>
114+
<groupId>org.springframework.boot</groupId>
115+
<artifactId>spring-boot-starter-security</artifactId>
116+
<version>3.1.3</version>
117+
</dependency>
118+
119+
88120
<dependency>
89121
<groupId>org.glassfish.jaxb</groupId>
90122
<artifactId>jaxb-runtime</artifactId>
@@ -226,10 +258,24 @@
226258
<id>coverage</id>
227259
<build>
228260
<plugins>
261+
<plugin>
262+
<groupId>org.apache.maven.plugins</groupId>
263+
<artifactId>maven-compiler-plugin</artifactId>
264+
<version>3.11.0</version>
265+
<configuration>
266+
<annotationProcessorPaths>
267+
<path>
268+
<groupId>org.mapstruct</groupId>
269+
<artifactId>mapstruct-processor</artifactId>
270+
<version>1.5.5.Final</version>
271+
</path>
272+
</annotationProcessorPaths>
273+
</configuration>
274+
</plugin>
229275
<plugin>
230276
<groupId>org.jacoco</groupId>
231277
<artifactId>jacoco-maven-plugin</artifactId>
232-
<version>0.8.7</version>
278+
<version>0.8.10</version>
233279
<executions>
234280
<execution>
235281
<id>prepare-agent</id>

src/main/java/de/doubleslash/keeptime/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ private void registerMaximizeEventlistener(final Scene mainScene, final Stage pr
305305

306306
@Override
307307
public void stop() throws Exception {
308-
springContext.stop();
308+
springContext.close();
309309
}
310310

311311
}

src/main/java/de/doubleslash/keeptime/controller/Controller.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import de.doubleslash.keeptime.model.Settings;
3535
import de.doubleslash.keeptime.model.Work;
3636
import jakarta.annotation.PreDestroy;
37-
import javafx.collections.ObservableList;
3837

3938
@Service
4039
public class Controller {
@@ -84,9 +83,7 @@ public void changeProject(final Project newProject, final long minusSeconds) {
8483
final Work newWork = new Work(workEnd, workEnd.plusSeconds(minusSeconds), newProject, "");
8584

8685
model.getPastWorkItems().add(newWork);
87-
8886
model.activeWorkItem.set(newWork);
89-
9087
}
9188

9289
public Work saveCurrentWork(final LocalDateTime workEnd) {
@@ -98,19 +95,19 @@ public Work saveCurrentWork(final LocalDateTime workEnd) {
9895

9996
currentWork.setEndTime(workEnd);
10097

101-
final String time = DateFormatter
102-
.secondsToHHMMSS(Duration.between(currentWork.getStartTime(), currentWork.getEndTime()).getSeconds());
98+
final String time = DateFormatter.secondsToHHMMSS(
99+
Duration.between(currentWork.getStartTime(), currentWork.getEndTime()).getSeconds());
103100

104101
LOG.info("Saving Work from '{}' to '{}' ({}) on project '{}' with notes '{}'", currentWork.getStartTime(),
105102
currentWork.getEndTime(), time, currentWork.getProject().getName(), currentWork.getNotes());
106103

107104
// Save in db
108105
return model.getWorkRepository().save(currentWork);
109-
110106
}
111107

112108
public void addNewProject(final Project project) {
113109
LOG.info("Creating new project '{}'.", project);
110+
114111
model.getAllProjects().add(project);
115112
model.getAvailableProjects().add(project);
116113

@@ -190,7 +187,7 @@ public void deleteProject(final Project p) {
190187

191188
final int indexToRemove = p.getIndex();
192189
p.setEnabled(false); // we don't delete it because of the referenced work
193-
// items
190+
// items
194191
p.setIndex(-1);
195192

196193
model.getAvailableProjects().remove(p);
@@ -253,7 +250,7 @@ public void deleteWork(final Work workToBeDeleted) {
253250

254251
/**
255252
* Changes the indexes of the originalList parameter to have a consistent order.
256-
*
253+
*
257254
* @param originalList
258255
* list of all projects to adapt the indexes for
259256
* @param changedProject
@@ -296,7 +293,7 @@ List<Project> resortProjectIndexes(final List<Project> originalList, final Proje
296293

297294
/**
298295
* Decreases all indexes by one, after the removed index
299-
*
296+
*
300297
* @param originalList
301298
* list of all projects to adapt the indexes for
302299
* @param removedIndex
@@ -361,5 +358,4 @@ public long calcSeconds(final List<Work> workItems) {
361358

362359
return seconds;
363360
}
364-
365361
}

src/main/java/de/doubleslash/keeptime/model/Model.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javafx.collections.ObservableList;
2626
import javafx.collections.transformation.SortedList;
2727
import javafx.scene.paint.Color;
28+
import org.springframework.beans.factory.annotation.Autowired;
2829
import org.springframework.context.ConfigurableApplicationContext;
2930
import org.springframework.stereotype.Component;
3031

@@ -35,7 +36,7 @@ public class Model {
3536
private ProjectRepository projectRepository;
3637
private WorkRepository workRepository;
3738
private SettingsRepository settingsRepository;
38-
39+
@Autowired
3940
public Model(final ProjectRepository projectRepository, final WorkRepository workRepository,
4041
final SettingsRepository settingsRepository) {
4142
super();

src/main/java/de/doubleslash/keeptime/model/Project.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public class Project {
2929
@GeneratedValue(strategy = GenerationType.IDENTITY)
3030
@Column(name = "id", updatable = false, nullable = false)
3131
private long id;
32-
3332
private String name;
3433

3534
@Lob
@@ -39,9 +38,7 @@ public class Project {
3938
private Color color;
4039

4140
private boolean isWork;
42-
4341
private boolean isDefault;
44-
4542
private boolean isEnabled;
4643

4744
private int index;
@@ -50,9 +47,7 @@ public Project() {
5047
// Needed for jpa
5148
}
5249

53-
public Project(final String name, final String description, final Color color, final boolean isWork, final int index,
54-
final boolean isDefault) {
55-
super();
50+
public Project(String name, String description, Color color, boolean isWork, int index, boolean isDefault) {
5651
this.name = name;
5752
this.description = description;
5853
this.color = color;
@@ -62,48 +57,47 @@ public Project(final String name, final String description, final Color color, f
6257
this.index = index;
6358
}
6459

65-
public Project(final String name, final String description, final Color color, final boolean isWork,
66-
final int index) {
60+
public Project(String name, String description, Color color, boolean isWork, int index) {
6761
this(name, description, color, isWork, index, false);
6862
}
6963

7064
public String getName() {
7165
return name;
7266
}
7367

74-
public void setName(final String name) {
68+
public void setName(String name) {
7569
this.name = name;
7670
}
7771

7872
public Color getColor() {
7973
return color;
8074
}
8175

82-
public void setColor(final Color color) {
76+
public void setColor(Color color) {
8377
this.color = color;
8478
}
8579

8680
public boolean isWork() {
8781
return isWork;
8882
}
8983

90-
public void setWork(final boolean isWork) {
84+
public void setWork(boolean isWork) {
9185
this.isWork = isWork;
9286
}
9387

9488
public boolean isDefault() {
9589
return isDefault;
9690
}
9791

98-
public void setDefault(final boolean isDefault) {
92+
public void setDefault(boolean isDefault) {
9993
this.isDefault = isDefault;
10094
}
10195

10296
public boolean isEnabled() {
10397
return isEnabled;
10498
}
10599

106-
public void setEnabled(final boolean isEnabled) {
100+
public void setEnabled(boolean isEnabled) {
107101
this.isEnabled = isEnabled;
108102
}
109103

@@ -115,15 +109,15 @@ public int getIndex() {
115109
return index;
116110
}
117111

118-
public void setIndex(final int index) {
112+
public void setIndex(int index) {
119113
this.index = index;
120114
}
121115

122116
public String getDescription() {
123117
return description;
124118
}
125119

126-
public void setDescription(final String description) {
120+
public void setDescription(String description) {
127121
this.description = description;
128122
}
129123

@@ -132,5 +126,4 @@ public String toString() {
132126
return "Project [id=" + id + ", name=" + name + ", description=" + description + ", color=" + color + ", isWork="
133127
+ isWork + ", isDefault=" + isDefault + ", isEnabled=" + isEnabled + ", index=" + index + "]";
134128
}
135-
136-
}
129+
}

src/main/java/de/doubleslash/keeptime/model/ScreenSettings.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
// Copyright 2024 doubleSlash Net Business GmbH
2+
//
3+
// This file is part of KeepTime.
4+
// KeepTime is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
117
package de.doubleslash.keeptime.model;
218

319
import javafx.beans.property.ObjectProperty;

src/main/java/de/doubleslash/keeptime/model/Settings.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
/**
3131
* Object holding settings
32-
*
32+
*
3333
* @author nmutter
3434
*/
3535
@Entity
@@ -73,7 +73,8 @@ public class Settings {
7373

7474
private boolean confirmClose;
7575

76-
public Settings() {}
76+
public Settings() {
77+
}
7778

7879
public Settings(final Color hoverBackgroundColor, final Color hoverFontColor, final Color defaultBackgroundColor,
7980
final Color defaultFontColor, final Color taskBarColor, final boolean useHotkey,
@@ -96,7 +97,6 @@ public Settings(final Color hoverBackgroundColor, final Color hoverFontColor, fi
9697
this.remindIfNotesAreEmpty = remindIfNotesAreEmpty;
9798
this.remindIfNotesAreEmptyOnlyForWorkEntry = remindIfNotesAreEmptyOnlyForWorkEntry;
9899
this.confirmClose = confirmClose;
99-
100100
}
101101

102102
public boolean isRemindIfNotesAreEmptyOnlyForWorkEntry() {
@@ -222,5 +222,4 @@ public boolean isRemindIfNotesAreEmpty() {
222222
public void setRemindIfNotesAreEmpty(final boolean emptyNoteReminder) {
223223
this.remindIfNotesAreEmpty = emptyNoteReminder;
224224
}
225-
226225
}

src/main/java/de/doubleslash/keeptime/model/Work.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@
1818

1919
import java.time.LocalDateTime;
2020

21-
import jakarta.persistence.*;
21+
import jakarta.persistence.Column;
22+
import jakarta.persistence.Entity;
23+
import jakarta.persistence.GeneratedValue;
24+
import jakarta.persistence.GenerationType;
25+
import jakarta.persistence.Id;
26+
import jakarta.persistence.Lob;
27+
import jakarta.persistence.ManyToOne;
28+
import jakarta.persistence.Table;
2229

2330
@Entity
2431
@Table(name = "Work")
@@ -30,14 +37,12 @@ public class Work {
3037

3138
private LocalDateTime startTime;
3239
private LocalDateTime endTime;
33-
3440
@ManyToOne
3541
private Project project;
3642
@Lob
3743
private String notes;
3844

39-
public Work() {
40-
}
45+
public Work() {}
4146

4247
public Work(final LocalDateTime startTime, final LocalDateTime endTime, final Project project, final String notes) {
4348
super();
@@ -88,5 +93,4 @@ public String toString() {
8893
return "Work [id=" + id + ", startTime=" + startTime + ", endTime=" + endTime + ", projectName="
8994
+ project.getName() + ", notes=" + notes + "]";
9095
}
91-
9296
}

src/main/java/de/doubleslash/keeptime/model/persistenceconverter/ColorConverter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import javafx.scene.paint.Color;
2121

2222
public class ColorConverter implements AttributeConverter<Color, String> {
23-
2423
@Override
2524
public Color convertToEntityAttribute(final String arg0) {
2625
try {
@@ -34,5 +33,4 @@ public Color convertToEntityAttribute(final String arg0) {
3433
public String convertToDatabaseColumn(final Color arg0) {
3534
return arg0.toString();
3635
}
37-
3836
}

0 commit comments

Comments
 (0)