further progressing, not yet finished
This commit is contained in:
@ -0,0 +1,74 @@
|
||||
package de.jottyfan.timetrack.modules.calendar;
|
||||
|
||||
import static de.jottyfan.timetrack.db.done.Tables.T_DONE;
|
||||
import static de.jottyfan.timetrack.db.done.Tables.T_PROJECT;
|
||||
import static de.jottyfan.timetrack.db.done.Tables.T_MODULE;
|
||||
import static de.jottyfan.timetrack.db.done.Tables.T_JOB;
|
||||
import static de.jottyfan.timetrack.db.done.Tables.T_BILLING;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.Record7;
|
||||
import org.jooq.SelectJoinStep;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author henkej
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public class CalendarDoneRepository {
|
||||
private static final Logger LOGGER = LogManager.getLogger(CalendarDoneRepository.class);
|
||||
|
||||
@Autowired
|
||||
private DSLContext jooq;
|
||||
|
||||
/**
|
||||
* get all already recorded dates from the data base
|
||||
*
|
||||
* @return the event beans; an empty list at least
|
||||
*/
|
||||
public List<EventBean> getAllDates() {
|
||||
SelectJoinStep<Record7<Integer, LocalDateTime, LocalDateTime, String, String, String, String>> sql = jooq
|
||||
// @formatter:off
|
||||
.select(T_DONE.PK,
|
||||
T_DONE.TIME_FROM,
|
||||
T_DONE.TIME_UNTIL,
|
||||
T_PROJECT.NAME,
|
||||
T_MODULE.NAME,
|
||||
T_JOB.NAME,
|
||||
T_BILLING.NAME)
|
||||
.from(T_DONE)
|
||||
.leftJoin(T_PROJECT).on(T_PROJECT.PK.eq(T_DONE.FK_PROJECT))
|
||||
.leftJoin(T_MODULE).on(T_MODULE.PK.eq(T_DONE.FK_MODULE))
|
||||
.leftJoin(T_JOB).on(T_JOB.PK.eq(T_DONE.FK_JOB))
|
||||
.leftJoin(T_BILLING).on(T_BILLING.PK.eq(T_DONE.FK_BILLING));
|
||||
// @formatter:on
|
||||
LOGGER.trace(sql.toString());
|
||||
List<EventBean> list = new ArrayList<>();
|
||||
for (Record7<Integer, LocalDateTime, LocalDateTime, String, String, String, String> r : sql.fetch()) {
|
||||
String id = String.valueOf(r.get(T_DONE.PK));
|
||||
String job = r.get(T_JOB.NAME);
|
||||
String project = r.get(T_PROJECT.NAME);
|
||||
String module = r.get(T_MODULE.NAME);
|
||||
String billing = r.get(T_BILLING.NAME);
|
||||
LocalDateTime start = r.get(T_DONE.TIME_FROM);
|
||||
LocalDateTime end = r.get(T_DONE.TIME_UNTIL);
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(billing).append(billing == null ? "" : "; ");
|
||||
buf.append(job).append(job == null ? "" : " - ");
|
||||
buf.append(module).append(module == null ? "" : ": ");
|
||||
buf.append(project);
|
||||
String title = buf.toString();
|
||||
list.add(EventBean.ofEvent(id, title, start, end));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ import com.google.gson.GsonBuilder;
|
||||
public class CalendarService {
|
||||
|
||||
@Autowired
|
||||
private DummyRepository dummyRepository;
|
||||
private CalendarDoneRepository repository;
|
||||
|
||||
// TODO: implement a davical database reader as a repository
|
||||
// TODO: implement a caldav client as repository
|
||||
@ -28,7 +28,7 @@ public class CalendarService {
|
||||
public String getJsonEvents() {
|
||||
Gson gson = new GsonBuilder().registerTypeAdapter(LocalDate.class, new LocalDateAdapter())
|
||||
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter()).create();
|
||||
return gson.toJson(dummyRepository.getExamples());
|
||||
return gson.toJson(repository.getAllDates());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
package de.jottyfan.timetrack.modules.calendar;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public class DummyRepository {
|
||||
|
||||
/**
|
||||
* get example dates
|
||||
*
|
||||
* @return the example dates
|
||||
*/
|
||||
public List<EventBean> getExamples() {
|
||||
List<EventBean> list = new ArrayList<>();
|
||||
|
||||
EventBean event1 = EventBean.ofAllDayEvent("e1", "all day event", LocalDate.of(2023, 5, 8));
|
||||
event1.setBackgroundColor("darkcyan");
|
||||
|
||||
list.add(event1);
|
||||
|
||||
EventBean event2 = EventBean.ofEvent("e2", "overlapping", LocalDate.of(2023, 5, 8).atTime(10, 0),
|
||||
LocalDate.of(2023, 5, 9).atTime(10, 0));
|
||||
|
||||
list.add(event2);
|
||||
|
||||
EventBean event3 = EventBean.ofEvent("e3", "developing", LocalDate.of(2023, 5, 10).atTime(8, 0),
|
||||
LocalDate.of(2023, 5, 10).atTime(10, 0));
|
||||
|
||||
list.add(event3);
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user