Merge pull request 'config' (#4) from config into master

Reviewed-on: http://git.plannaplan.pl/filipizydorczyk/backend/pulls/4
This commit is contained in:
Marcin Woźniak 2020-08-25 16:43:05 +02:00
commit 6bbabd2d78
33 changed files with 730 additions and 155712 deletions

View File

@ -46,6 +46,18 @@ cd restservice
mvn spring-boot:run mvn spring-boot:run
``` ```
## Packaging
Zeby spakowac apke do `jara` wystarcza dwie komendy
```
cd restservice
mvn clean package spring-boot:repackage
```
Utworzony zostanie jar w `restservice/target/restservice-1.0-SNAPSHOT.jar`. Oczywiscie zeby jar zadzialal kontenery dockerowe musza byc odpalone (lub baza danych na serwerze jesli zmienialismy propertisy z localhost)
## Troubleshooting ## Troubleshooting
Spring chyba cacheuje jakies dane dotyczace polaczenia wiec jesli spring wywali Ci blad `Connection Refused`, a wiesz, ze ta baza stoi na podanym ip i porcie to sprobuj Spring chyba cacheuje jakies dane dotyczace polaczenia wiec jesli spring wywali Ci blad `Connection Refused`, a wiesz, ze ta baza stoi na podanym ip i porcie to sprobuj

View File

@ -45,10 +45,26 @@
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </dependency>
<!-- dependency used for XLSX file format -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<!-- dependency used for XLS older file format
(added for information) -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <pluginManagement>
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins> <plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin> <plugin>

View File

@ -2,13 +2,36 @@ package com.plannaplan;
import com.plannaplan.interfaces.ProtectedAction; import com.plannaplan.interfaces.ProtectedAction;
import com.plannaplan.models.ConfigData; import com.plannaplan.models.ConfigData;
import com.plannaplan.models.FileData;
import com.plannaplan.services.CourseService;
import com.plannaplan.services.GroupService;
import com.plannaplan.services.LecturerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.plannaplan.configutils.*;
@Component
public class Configurator implements ProtectedAction { public class Configurator implements ProtectedAction {
@Autowired
private LecturerService lecturerService;
@Autowired
private CourseService courseService;
@Autowired
private GroupService groupService;
public Configurator() { public Configurator() {
} }
public void config(ConfigData data) { public void config(ConfigData data) {
FileReader reader = new FileReader(data.getFilestream());
FileData coursesData = reader.read();
FileToDatabaseMigrator mgtr = new FileToDatabaseMigrator(lecturerService, courseService, groupService);
mgtr.migrate(coursesData);
} }
@Override @Override

View File

@ -1,6 +1,16 @@
package com.plannaplan; package com.plannaplan;
import com.plannaplan.models.ConfigData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class Controller { public class Controller {
@Autowired
private Configurator configurator;
public Controller() { public Controller() {
} }
@ -22,7 +32,8 @@ public class Controller {
public void getHistoryAtPoint() { public void getHistoryAtPoint() {
} }
public void config() { public void config(ConfigData data) {
configurator.config(data);
} }
public void createTransfer() { public void createTransfer() {

View File

@ -0,0 +1,56 @@
package com.plannaplan.configutils;
import java.io.IOException;
import java.io.InputStream;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import com.plannaplan.models.FileData;
public class FileReader {
private InputStream fileInputStream;
public FileReader(InputStream fileInputStream) {
this.fileInputStream = fileInputStream;
}
public FileData read() {
FileData result = null;
try {
InputStream fis = this.fileInputStream;
XSSFWorkbook workbook = new XSSFWorkbook(fis);
XSSFSheet sheet = workbook.getSheetAt(0);
Iterator<Row> rowIt = sheet.iterator();
Row row = rowIt.next();
Iterator<Cell> cellIt = row.cellIterator();
Hashtable<String, Integer> keys = new Hashtable<>();
int index = 0;
while (cellIt.hasNext()) {
Cell c = cellIt.next();
keys.put(c.toString(), index);
index+=1;
}
rowIt.remove();
result = new FileData(keys, rowIt);
workbook.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
}

View File

@ -1,12 +1,148 @@
package com.plannaplan.configutils; package com.plannaplan.configutils;
import java.io.File; import java.util.Iterator;
import com.plannaplan.entities.Course;
import com.plannaplan.entities.Groups;
import com.plannaplan.entities.Lecturer;
import com.plannaplan.models.FileData;
import com.plannaplan.services.CourseService;
import com.plannaplan.services.GroupService;
import com.plannaplan.services.LecturerService;
import com.plannaplan.types.GroupType;
import com.plannaplan.types.WeekDay;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
public class FileToDatabaseMigrator { public class FileToDatabaseMigrator {
public FileToDatabaseMigrator() { public static String LECTURER_NAME_STRING = "imie";
public static String LECTURER_SURNAME_STRING = "nazwisko";
public static String LECTURER_TITLE_STRING = "tytul";
public static String COURSE_SYMBOL_STRING = "sym";
public static String COURSE_NAME_STRING = "nazwa";
public static String GROUP_DAY_STRING = "dzien";
public static String GROUP_TIME_STRING = "godz_od";
public static String ROOM_STRING = "sala";
public static String CAPACITY_STRING = "Mc";
LecturerService lecturerService;
CourseService courseService;
GroupService groupService;
public FileToDatabaseMigrator(LecturerService lecturerService, CourseService courseService,
GroupService groupService) {
this.lecturerService = lecturerService;
this.groupService = groupService;
this.courseService = courseService;
} }
public void migrate(File file) { public void migrate(FileData data) {
Iterator<Row> rows = data.getRows();
int course_name_index = data.getIndexOf(FileToDatabaseMigrator.COURSE_NAME_STRING);
int sym_index = data.getIndexOf(FileToDatabaseMigrator.COURSE_SYMBOL_STRING);
int title_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_TITLE_STRING);
int surname_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_SURNAME_STRING);
int name_index = data.getIndexOf(FileToDatabaseMigrator.LECTURER_NAME_STRING);
int day_index = data.getIndexOf(FileToDatabaseMigrator.GROUP_DAY_STRING);
int time_index = data.getIndexOf(FileToDatabaseMigrator.GROUP_TIME_STRING);
int room_index = data.getIndexOf(FileToDatabaseMigrator.ROOM_STRING);
int capacity_index = data.getIndexOf(FileToDatabaseMigrator.CAPACITY_STRING);
while (rows.hasNext()) {
Row row = rows.next();
Cell course_name_cell = row.getCell(course_name_index);
Cell sym = row.getCell(sym_index);
Cell title_cell = row.getCell(title_index);
Cell name_cell = row.getCell(name_index);
Cell surname_cell = row.getCell(surname_index);
Cell day_cell = row.getCell(day_index);
Cell time_cell = row.getCell(time_index);
Cell room_cell = row.getCell(room_index);
Cell capacity_cell = row.getCell(capacity_index);
String lecturer_title = "";
String lecturer_surname = "";
String lecturer_name = "";
String course_name = course_name_cell.toString().trim();
String sym_str = sym.toString().trim();
int day = (int) Double.parseDouble(day_cell.toString());
WeekDay group_day = WeekDay.getDay(day);
String room = room_cell.toString().trim();
int time = this.parseTimeToInt(time_cell.toString());
int capacity = (int) Double.parseDouble(capacity_cell.toString());
Groups group = groupService.find(time, capacity, room);
Course course = this.courseService.getCourseByName(course_name);
if (course == null) {
course = new Course();
course.setName(course_name);
course.setSymbol(sym_str);
}
courseService.save(course);
if (title_cell != null) {
lecturer_title = title_cell.toString().trim();
}
if (name_cell != null) {
lecturer_name = name_cell.toString().trim();
}
if (surname_cell != null) {
lecturer_surname = surname_cell.toString().trim();
}
Lecturer lecturer = lecturerService.getLecturer(lecturer_title, lecturer_name, lecturer_surname);
if (lecturer == null) {
lecturer = new Lecturer(lecturer_title, lecturer_name, lecturer_surname);
lecturerService.save(lecturer);
}
if (group == null) {
group = new Groups();
group.setCapacity(capacity);
group.setRoom(room);
group.setCourseId(course);
group.setTime(time);
if (capacity >= 50) {
group.setType(GroupType.LECTURE);
} else {
group.setType(GroupType.CLASS);
}
group.setDay(group_day);
group.setLecturer(lecturer);
groupService.save(group);
}
} }
}
private Integer parseTimeToInt(String time) {
String times[] = time.split("\\.");
if (times.length == 2) {
return Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]);
}
times = time.split("\\:");
if (times.length == 2) {
return Integer.parseInt(times[0]) * 60 + Integer.parseInt(times[1]);
}
return 0;
}
} }

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
import javax.persistence.Id; import javax.persistence.Id;
@ -16,12 +17,16 @@ public class Course {
private Long id; private Long id;
private String name; private String name;
private String symbol; private String symbol;
@OneToMany(mappedBy = "id") @OneToMany(mappedBy = "courseId", fetch = FetchType.EAGER)
private List<Groups> groups = new ArrayList<>(); private List<Groups> groups = new ArrayList<>();
public Course() { public Course() {
} }
public Long getId() {
return this.id;
}
public String getName() { public String getName() {
return name; return name;
} }
@ -38,4 +43,8 @@ public class Course {
this.name = name; this.name = name;
} }
public List<Groups> getGroups(){
return this.groups;
}
} }

View File

@ -30,6 +30,10 @@ public class Groups {
public Groups() { public Groups() {
} }
public Long getId() {
return this.id;
}
public Lecturer getLecturer() { public Lecturer getLecturer() {
return lecturer; return lecturer;
} }
@ -85,4 +89,14 @@ public class Groups {
public void setCourseId(Course courseId) { public void setCourseId(Course courseId) {
this.courseId = courseId; this.courseId = courseId;
} }
public String getTimeString() {
int minutes = this.getTime() % 60;
String hoursString = Integer.toString(this.getTime() / 60);
String minutesString = Integer.toString(minutes);
if (minutes < 10) {
minutesString = "0" + minutesString;
}
return String.format("%s.%s", hoursString, minutesString);
}
} }

View File

@ -14,9 +14,6 @@ public class Lecturer {
private String name; private String name;
private String surname; private String surname;
public Lecturer() {
}
public String getTitle() { public String getTitle() {
return title; return title;
} }
@ -41,4 +38,18 @@ public class Lecturer {
this.title = title; this.title = title;
} }
public Lecturer(String title, String name, String surname) {
this.title = title;
this.name = name;
this.surname = surname;
}
public Lecturer() {
}
@Override
public String toString() {
return String.format("%s %s %s", this.title, this.name, this.surname);
}
} }

View File

@ -1,21 +1,21 @@
package com.plannaplan.models; package com.plannaplan.models;
import java.io.File;
import java.util.Date; import java.util.Date;
import java.io.InputStream;
public class ConfigData { public class ConfigData {
private Date start; private Date start;
private Date end; private Date end;
private File file; private InputStream filestream;
public ConfigData(Date start, Date end, File file) { public ConfigData(Date start, Date end, InputStream filestream) {
this.start = start; this.start = start;
this.end = end; this.end = end;
this.file = file; this.filestream = filestream;
} }
public File getFile() { public InputStream getFilestream() {
return file; return filestream;
} }
public Date getEnd() { public Date getEnd() {

View File

@ -0,0 +1,39 @@
package com.plannaplan.models;
import java.util.Dictionary;
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Row;
public class FileData {
private Dictionary<String, Integer> keys;
private Iterator<Row> rows;
public FileData(Dictionary<String, Integer> keys, Iterator<Row> rows) {
this.setKeys(keys);
this.setRows(rows);
}
public Iterator<Row> getRows() {
return rows;
}
public void setRows(Iterator<Row> rows) {
this.rows = rows;
}
public Dictionary<String, Integer> getKeys() {
return keys;
}
public void setKeys(Dictionary<String, Integer> keys) {
this.keys = keys;
}
public int getIndexOf(String key) {
int index = this.keys.get(key);
return index;
}
}

View File

@ -3,9 +3,12 @@ package com.plannaplan.repositories;
import com.plannaplan.entities.Course; import com.plannaplan.entities.Course;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
public interface CourseRepository extends JpaRepository<Course, Long> { public interface CourseRepository extends JpaRepository<Course, Long> {
@Query(value = "SELECT * FROM course WHERE name = :name", nativeQuery = true)
Course findByName(@Param("name") String name);
} }

View File

@ -1,11 +1,20 @@
package com.plannaplan.repositories; package com.plannaplan.repositories;
import java.util.List;
import com.plannaplan.entities.Groups; import com.plannaplan.entities.Groups;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
public interface GroupRepository extends JpaRepository<Groups, Long> { public interface GroupRepository extends JpaRepository<Groups, Long> {
@Query(value = "SELECT * FROM groups WHERE time = :time AND room = :room AND capacity = :capacity ", nativeQuery = true)
Groups find(@Param("time") int time, @Param("room") String room, @Param("capacity") int capacity);
@Query(value = "SELECT * FROM groups WHERE course_id = :id", nativeQuery = true)
List<Groups> getByCourse(@Param("id") Long id);
} }

View File

@ -3,10 +3,12 @@ package com.plannaplan.repositories;
import com.plannaplan.entities.Lecturer; import com.plannaplan.entities.Lecturer;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
@Repository @Repository
public interface LecturerRepository extends JpaRepository<Lecturer, Long> { public interface LecturerRepository extends JpaRepository<Lecturer, Long> {
@Query(value = "SELECT * FROM lecturer WHERE name = :name AND surname = :surname AND title = :title ", nativeQuery = true)
Lecturer find(@Param("title") String title, @Param("name") String name, @Param("surname") String surname);
} }

View File

@ -1,5 +1,8 @@
package com.plannaplan.services; package com.plannaplan.services;
import java.util.List;
import com.plannaplan.entities.Course;
import com.plannaplan.repositories.CourseRepository; import com.plannaplan.repositories.CourseRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -9,4 +12,16 @@ import org.springframework.stereotype.Service;
public class CourseService { public class CourseService {
@Autowired @Autowired
private CourseRepository repo; private CourseRepository repo;
public Course getCourseByName(String name) {
return this.repo.findByName(name);
}
public List<Course> getAllCourses() {
return this.repo.findAll();
}
public void save(Course course) {
this.repo.save(course);
}
} }

View File

@ -1,5 +1,8 @@
package com.plannaplan.services; package com.plannaplan.services;
import java.util.List;
import com.plannaplan.entities.Groups;
import com.plannaplan.repositories.GroupRepository; import com.plannaplan.repositories.GroupRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -9,4 +12,19 @@ import org.springframework.stereotype.Service;
public class GroupService { public class GroupService {
@Autowired @Autowired
private GroupRepository repo; private GroupRepository repo;
public GroupService() {
}
public Groups find(int time, int capacity, String room) {
return this.repo.find(time, room, capacity);
}
public List<Groups> getGroupsByCourse(Long id) {
return this.repo.getByCourse(id);
}
public void save(Groups group) {
this.repo.save(group);
}
} }

View File

@ -1,5 +1,6 @@
package com.plannaplan.services; package com.plannaplan.services;
import com.plannaplan.entities.Lecturer;
import com.plannaplan.repositories.LecturerRepository; import com.plannaplan.repositories.LecturerRepository;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -9,4 +10,12 @@ import org.springframework.stereotype.Service;
public class LecturerService { public class LecturerService {
@Autowired @Autowired
private LecturerRepository repo; private LecturerRepository repo;
public Lecturer getLecturer(String title, String name, String surname) {
return repo.find(title, name, surname);
}
public void save(Lecturer lecturer) {
repo.save(lecturer);
}
} }

View File

@ -8,4 +8,13 @@ public enum WeekDay {
private WeekDay(int label) { private WeekDay(int label) {
this.label = label; this.label = label;
} }
public static WeekDay getDay(int index) {
for (WeekDay d : values()) {
if (d.label == index) {
return d;
}
}
return null;
}
} }

View File

@ -0,0 +1,21 @@
package com.plannaplan.configutils;
import static org.junit.Assert.assertTrue;
import java.io.InputStream;
import com.plannaplan.models.FileData;
import org.junit.Test;
public class FileReaderTest {
@Test
public void shoulReturnNull() {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
FileReader r = new FileReader(inputStream);
FileData d = r.read();
assertTrue(d.getRows().next().getCell(0).toString().equals("1.0"));
assertTrue(d.getKeys().size() == 22);
assertTrue(d != null);
}
}

View File

@ -0,0 +1,19 @@
package com.plannaplan.configutils;
import java.io.InputStream;
import com.plannaplan.models.FileData;
import org.junit.Test;
public class FileToDatabaseMigratorTest {
@Test
public void shouldInsertToDatabase() {
// FileToDatabaseMigrator migrator = new FileToDatabaseMigrator();
// InputStream inputStream =
// getClass().getClassLoader().getResourceAsStream("Zajecia.xlsx");
// FileReader r = new FileReader(inputStream);
// FileData d = r.read();
// migrator.migrate(d);
}
}

Binary file not shown.

View File

@ -1,6 +1,10 @@
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.datasource.url=jdbc:mysql://172.20.0.2:3306/test spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=yes&characterEncoding=UTF-8
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=example spring.datasource.password=example
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.open-in-view=true
spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.hibernate.ddl-auto=create-drop
spring.jackson.serialization.fail-on-empty-beans=false
server.port=1285

56
docs/api.md Normal file
View File

@ -0,0 +1,56 @@
# Dokumetacja API
| Api | Zadania tej klasy |
| ---------------------------------------------- | ---------------------------------------------------------------- |
| [/config](#config) | Załadowanie konfiguracji startowej do aplikacji PlanNaPlan |
| [/getCoursesWithGroups](#getCoursesWithGroups) | Zwrócenie wszytskich kursów (ćwiczenia, wykłady) razem z grupami |
| [/getCourseGroups](#getCourseGroups) | Zwrócenie grup dla danego kursu |
## config
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/ConfigController.java)
```
POST /config
```
#### Description
Endpoint konfigurujacy caly system i importujacy dane do bazy.
#### Parameters
| Type | Name | Consumes | Description | Type |
| ---- | ----------------------- | ------------------- | ------------------------------- | ---- |
| Body | **file** </br> required | multipart/form-data | Plik .xlsx z potrzebnymi danymi | file |
## getCoursesWithGroups
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/getCoursesWithGroups.java)
```
GET /getCoursesWithGroups
```
#### Description
Zwraca wszystkie dostepne kursy wraz z lista grup dla poszczegolnych kursow.
## getCourseGroups
Source code: [link](../restservice/src/main/java/com/plannaplan/controllers/GroupController.java)
```
GET /getCourseGroups
```
#### Description
Endpoint konfigurujacy caly system i importujacy dane do bazy.
#### Parameters
| Type | Name | Consumes | Description | Type |
| ----------- | --------------------- | -------- | ----------------------------------------- | ---- |
| Query Param | **id** </br> required | - | id kursu dla ktorego chcemy zwrocic grupy | int |
| Query Param | **capacity** </br> | - | czy ma zwrocic pole pojemnosci grupy | bool |

1
init.sql Normal file
View File

@ -0,0 +1 @@
CREATE DATABASE IF NOT EXISTS test;

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,7 @@
<artifactId>backend</artifactId> <artifactId>backend</artifactId>
<groupId>com.plannaplan</groupId> <groupId>com.plannaplan</groupId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
</parent> </parent>
<groupId>com.plannaplan</groupId> <groupId>com.plannaplan</groupId>
@ -19,6 +20,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<start-class>com.plannaplan.App</start-class>
</properties> </properties>
<dependencies> <dependencies>
@ -54,7 +56,8 @@
</dependencies> </dependencies>
<build> <build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <pluginManagement>
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins> <plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin> <plugin>

View File

@ -7,7 +7,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
public class App { public class App {
public static void main(String[] args) { public static void main(String[] args) {
System.out.println("Hello World!"); Logo logo = new Logo("beta");
System.out.println(logo.getLogo());
System.out.println("|=============================================================================================|");
SpringApplication.run(App.class, args); SpringApplication.run(App.class, args);
} }
} }

View File

@ -0,0 +1,33 @@
package com.plannaplan;
public class Logo {
public static final String ANSI_RESET = "\u001B[0m";
public static final String ANSI_YELLOW = "\u001B[33m";
public static final String ANSI_BLUE = "\u001B[34m";
public static final String ANSI_BLACK = "\u001B[30m";
private String version;
public Logo(String version){
this.version = version;
}
public String getLogo(){
String result = ANSI_YELLOW +
" .,,,,, \n"+
" .,,,,,,,,,,,,, \n" +
" .,,,,,,,,,,,,,,,,,,,,, \n" +
" .,,,,,,,(,,,,,,,,,,,,,,,,,,,,, \n" +
" ,,,,,,,(,,,,,,,,,,,,,,,,,,,,,,,,,,,,. \n" +
" ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,. " + ANSI_RESET + " _ _ \n"+
" * " + ANSI_YELLOW +",,,,,,,,,,,,,,,,,,,,. " + ANSI_RESET + " | | | | \n" +
" * " + ANSI_BLUE + "%%%. " + ANSI_YELLOW +",,,,,,,,,,,,. "+ ANSI_BLUE+"(%%# " + ANSI_RESET + " _ __ | | __ _ _ __ _ __ __ _ _ __ | | __ _ _ __ \n" +
" * " + ANSI_BLUE + "%%%%%%%. " + ANSI_YELLOW + ",,,,. "+ ANSI_BLUE +"#%%%%%%# " + ANSI_RESET + "| '_ \\| |/ _` | '_ \\| '_ \\ / _` | '_ \\| |/ _` | '_ \\ \n" +
" * " + ANSI_BLUE +"%%%%%%%%%%%#%%%%%%%%%%# " + ANSI_RESET + "| |_) | | (_| | | | | | | | (_| | |_) | | (_| | | | |\n" +
" * " + ANSI_BLUE +"/%%%%%%%%%%%%%%%%%%% " + ANSI_RESET + "| .__/|_|\\__,_|_| |_|_| |_|\\__,_| .__/|_|\\__,_|_| |_|\n" +
" ( / " + ANSI_BLUE +"#%%%%%%%%%%%. " + ANSI_RESET + "| | | | "+ ANSI_BLUE +"(" +this.version + ")" +"\n" + ANSI_BLUE +
" %%%%/ " + ANSI_RESET + "|_| |_| \n" +
ANSI_RESET;
return result;
}
}

View File

@ -1,14 +0,0 @@
package com.plannaplan;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@CrossOrigin
public class TestController {
@GetMapping("/")
public String xd() {
return "<h1>xd</h1>";
}
}

View File

@ -0,0 +1,36 @@
package com.plannaplan.controllers;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import com.plannaplan.Controller;
import com.plannaplan.models.ConfigData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
@RestController
@CrossOrigin
public class ConfigController {
@Autowired
private Controller contrl;
@PostMapping("/config")
public ResponseEntity<String> configApp(@RequestParam("file") MultipartFile file) {
try {
ConfigData data = new ConfigData(null, null, file.getInputStream());
this.contrl.config(data);
return new ResponseEntity<>("Sucess", HttpStatus.OK);
} catch (IOException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -0,0 +1,66 @@
package com.plannaplan.controllers;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
import com.plannaplan.entities.Course;
import com.plannaplan.entities.Groups;
import com.plannaplan.services.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.GetMapping;
@RestController
@CrossOrigin
public class CoursesController {
@Autowired
private CourseService courseService;
@GetMapping("/getCourses")
public ResponseEntity<List<Dictionary<String,Object>>> getMethodName() {
List<Course> courses = this.courseService.getAllCourses();
List<Dictionary<String,Object>> response = new ArrayList<>();
for(Course c : courses){
Dictionary<String, Object> element = new Hashtable<>();
element.put("id", c.getId());
element.put("name",c.getName());
response.add(element);
}
return new ResponseEntity<>(response, HttpStatus.OK);
}
@GetMapping("/getCoursesWithGroups")
public ResponseEntity<List<Dictionary<String,Object>>> getCoursesWithGroups() {
List<Course> courses = this.courseService.getAllCourses();
List<Dictionary<String,Object>> response = new ArrayList<>();
for(Course c : courses){
Dictionary<String, Object> element = new Hashtable<>();
element.put("id", c.getId());
element.put("name",c.getName());
List<Dictionary<String,Object>> groups = new ArrayList<>();
for(Groups g : c.getGroups()){
Dictionary<String,Object> group = new Hashtable<>();
group.put("id", g.getId());
group.put("day", g.getDay().label);
group.put("time", g.getTimeString());
group.put("lecturer", g.getLecturer().toString());
group.put("room", g.getRoom());
group.put("type", g.getType());
groups.add(group);
}
element.put("groups", groups);
response.add(element);
}
return new ResponseEntity<>(response, HttpStatus.OK);
}
}

View File

@ -0,0 +1,48 @@
package com.plannaplan.controllers;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
import com.plannaplan.entities.Groups;
import com.plannaplan.services.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@CrossOrigin
public class GroupController {
@Autowired
private GroupService groupService;
@GetMapping("/getCourseGroups")
public ResponseEntity<List<Dictionary<String, Object>>> getCourses(@RequestParam("id") Long id, @RequestParam(name="capacity", defaultValue="true") Boolean capacity){
List<Groups> groups = this.groupService.getGroupsByCourse(id);
List<Dictionary<String, Object>> response = new ArrayList<>();
for (Groups g : groups) {
Dictionary<String, Object> group = new Hashtable<>();
group.put("id", g.getId());
group.put("day", g.getDay().label);
group.put("time", g.getTimeString());
group.put("lecturer", g.getLecturer().toString());
group.put("room", g.getRoom());
if (capacity) {
group.put("capacity", g.getCapacity());
}
group.put("type", g.getType());
response.add(group);
}
return new ResponseEntity<>(response, HttpStatus.OK);
}
}

View File

@ -5,6 +5,9 @@ services:
db: db:
image: mariadb image: mariadb
restart: always restart: always
command: --init-file /data/application/init.sql
volumes:
- ./init.sql:/data/application/init.sql
environment: environment:
MYSQL_ROOT_PASSWORD: example MYSQL_ROOT_PASSWORD: example
expose: expose: