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

🔖 Migrate code from dev repository - PWr-API 1.2.0 #30

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
91 changes: 70 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
<version>2.6.7</version>
<relativePath/>
</parent>
<groupId>dev.wms</groupId>
Expand All @@ -14,9 +14,23 @@
<name>pwr-api</name>
<description>Unofficial PWr's api that provides access to all internal university systems at your fingertips.</description>
<properties>
<java.version>11</java.version>
</properties>
<java.version>17</java.version>
<maven.compiler.release>17</maven.compiler.release>
</properties>
<dependencies>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-spring-boot-starter</artifactId>
<version>6.13.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
Expand All @@ -28,17 +42,22 @@
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.0.1-jre</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -49,6 +68,10 @@
<artifactId>spring-jdbc</artifactId>
<version>5.3.21</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
Expand Down Expand Up @@ -107,12 +130,14 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
Expand All @@ -130,7 +155,31 @@
<artifactId>json-schema-validator</artifactId>
<version>5.1.1</version>
</dependency>
</dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
<dependency>
<groupId>org.commonmark</groupId>
<artifactId>commonmark</artifactId>
<version>0.21.0</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>2021.0.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
Expand All @@ -152,17 +201,17 @@
</runtime>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/dev/wms/pwrapi/PwrApiApplication.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package dev.wms.pwrapi;

import java.io.IOException;

import com.fasterxml.jackson.core.exc.StreamWriteException;
import com.fasterxml.jackson.databind.DatabindException;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.servers.Server;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.scheduling.annotation.EnableAsync;

@SpringBootApplication
@OpenAPIDefinition(servers = @Server(url = "/", description = "Default Server URL"))
@EnableAsync(proxyTargetClass = true)
@EnableFeignClients
public class PwrApiApplication {

public static void main(String[] args) {
Expand Down
59 changes: 59 additions & 0 deletions src/main/java/dev/wms/pwrapi/api/DevelopersAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package dev.wms.pwrapi.api;

import dev.wms.pwrapi.service.internationalization.LocalizedMessageService;
import dev.wms.pwrapi.service.internationalization.SupportedLanguage;
import dev.wms.pwrapi.service.user.ApiUserService;
import dev.wms.pwrapi.utils.config.SentryReporter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirements;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/developers")
@RequiredArgsConstructor
@SecurityRequirements
public class DevelopersAPI {

private final SentryReporter sentryReporter;
private final ApiUserService userService;
private final LocalizedMessageService msgService;

@PostMapping("/feedback")
@Operation(summary = "Send feedback to API Developers! Or request help with exception", description = "Wanna send feedback to us? Just simply" +
" invoke this POST request! Every successfull response is us getting notified about your message :) Leave " +
"your contact details there, if you want us to contact you about your feedback. You can also paste you supportCode " +
"so we can investigate your issue faster")
public ResponseEntity<String> sendFeedback(@RequestParam(required = false) String email,
@RequestParam(required = false) String name,
@RequestParam(required = false) String errorId,
String feedback) {
sentryReporter.captureFeedback(feedback, email, name, errorId);
return ResponseEntity.ok("Thank you for your feedback!");
}

@PostMapping("/register")
public ResponseEntity<String> registerUser(@RequestParam String email) {
userService.registerUser(email);

return ResponseEntity.ok(msgService.getMessage(
"msg.mail.subject.registration",
SupportedLanguage.EN)
);
}


@GetMapping("/confirm-email")
@Operation(summary = "Confirm email of the user using token", description = "This endpoint is used in email when " +
"user is prompted to confirm the email address. The method is GET as POST is sometimes restricted by email " +
"clients. If used twice will REMOVE previous api keys from user account")
public ResponseEntity<String> confirmEmail(@RequestParam String token) {
userService.confirmEmail(token);

return ResponseEntity.ok(msgService.getMessageWithArgs(
"msg.mail.subject.generated-api-key",
SupportedLanguage.EN)
);
}
}
15 changes: 6 additions & 9 deletions src/main/java/dev/wms/pwrapi/api/EdukacjaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import java.util.List;

import dev.wms.pwrapi.entity.edukacja.Subject;
import dev.wms.pwrapi.scrapper.edukacja.EduScrapperServices;
import dev.wms.pwrapi.scrapper.edukacja.EdukacjaScrapperService;
import dev.wms.pwrapi.service.edukacja.EduService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -17,14 +17,11 @@

@RestController
@RequestMapping(value = "/api/edukacja", produces = "application/json")
@RequiredArgsConstructor
public class EdukacjaAPI {

private EduService edukacjaService;

@Autowired
public EdukacjaAPI(EduService edukacjaService){
this.edukacjaService = edukacjaService;
}
private final EduService edukacjaService;
private final EdukacjaScrapperService scrapperService;

@GetMapping("/wektor")
@Operation(summary = "Return available group for user's most recent enrollments",
Expand All @@ -39,6 +36,6 @@ public ResponseEntity<List<Subject>> getAvailableGroups(@RequestParam("login") S
@Operation(summary = "Checks if login and password can be used to login to edukacja.cl",
description = "Just a simple endpoint. You can use it to validate data and save it for later")
public void loginToEdukacja(@RequestParam("login") String login, @RequestParam("password") String password) throws IOException{
EduScrapperServices.fetchHTMLConnectionDetails(login, password);
scrapperService.fetchHTMLConnectionDetails(login, password);
}
}
37 changes: 13 additions & 24 deletions src/main/java/dev/wms/pwrapi/api/EportalAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import java.io.IOException;
import java.util.List;

import com.fasterxml.jackson.core.JsonProcessingException;

import dev.wms.pwrapi.entity.eportal.MarkSummary;
import dev.wms.pwrapi.entity.eportal.calendar.CalendarMonth;
import dev.wms.pwrapi.dto.eportal.sections.EportalSection;
import dev.wms.pwrapi.service.eportal.EportalService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -27,60 +26,50 @@

@RestController
@RequestMapping(value = "/api/eportal", produces = "application/json")
@RequiredArgsConstructor
public class EportalAPI {

private EportalService eService;

@Autowired
public EportalAPI(EportalService eService){
this.eService = eService;
}
private final EportalService eportalService;

@GetMapping()
@GetMapping
@Operation(summary = "Validates ePortal login data", description = "Can be used to cache login and password for later API usage")
public void getEportalData(@RequestParam String login, @RequestParam String password) throws JsonProcessingException, IOException, LoginException {
eService.getEportalData(login, password);
public void getEportalData(@RequestParam String login, @RequestParam String password) throws LoginException {
eportalService.getEportalData(login, password);
}

@GetMapping("/kursy")
@Operation(summary = "Returns all courses of the given user")
public ResponseEntity<String> getEportalKursy(@RequestParam String login, @RequestParam String password) throws IOException, LoginException {

String result = eService.getEportalKursy(login, password);

return ResponseEntity.status(HttpStatus.OK).body(result);
return ResponseEntity.status(HttpStatus.OK).body(eportalService.getEportalKursy(login, password));
}

@GetMapping("/kurs/{id}/sekcje")
@Operation(summary = "Returns all sections for the given course", description = "You can fetch the course ID using /kursy endpoint")
public ResponseEntity<List<EportalSection>> getEportalSekcje(@RequestParam String login, @RequestParam String password, @PathVariable int id) throws JsonProcessingException, IOException, LoginException, WrongCourseIdException {
public ResponseEntity<List<EportalSection>> getEportalSekcje(@RequestParam String login, @RequestParam String password, @PathVariable int id) throws IOException, LoginException, WrongCourseIdException {

return ResponseEntity.status(HttpStatus.OK).body(eService.getEportalSekcje(login, password, id));
return ResponseEntity.status(HttpStatus.OK).body(eportalService.getEportalSekcje(login, password, id));
}


@GetMapping("/kursy/{id}/oceny")
@Operation(summary = "Returns all marks for the given course", description = "You can fetch the course ID using /kursy endpoint")
public ResponseEntity<List<MarkSummary>> getEportalOceny(@RequestParam String login, @RequestParam String password, @PathVariable int id) throws JsonProcessingException {

return ResponseEntity.status(HttpStatus.OK).body(eService.getEportalOceny(login, password, id));
public ResponseEntity<List<MarkSummary>> getEportalOceny(@RequestParam String login, @RequestParam String password, @PathVariable int id) {
return ResponseEntity.status(HttpStatus.OK).body(eportalService.getEportalOceny(login, password, id));
}


@GetMapping("/kalendarz")
@Operation(summary = "Returns events that take place in month with offset", description = "Max offset is from -10 to 10")
public ResponseEntity<CalendarMonth> getEportalKalendarzMiesiac(@RequestParam String login, @RequestParam String password,
@RequestParam(defaultValue = "0") @Min(-10) @Max(10) int offset) throws IOException {

return ResponseEntity.status(HttpStatus.OK).body(eService.getEportalKalendarzOffset(login, password, offset));
return ResponseEntity.status(HttpStatus.OK).body(eportalService.getEportalKalendarzOffset(login, password, offset));
}


@GetMapping("/kalendarz/pobierz")
@Operation(summary = "Returns calendar in ICS format", description = "Calendar range is 60 days back and forth")
public ResponseEntity<String> getEportalICS(@RequestParam String login, @RequestParam String password) throws IOException {

return ResponseEntity.status(HttpStatus.OK).body(eService.getEportalKalendarzIcsLink(login, password));
return ResponseEntity.status(HttpStatus.OK).body(eportalService.getEportalKalendarzIcsLink(login, password));
}

}
36 changes: 36 additions & 0 deletions src/main/java/dev/wms/pwrapi/api/EventsAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package dev.wms.pwrapi.api;


import dev.wms.pwrapi.dto.events.EventDto;
import dev.wms.pwrapi.service.events.EventsService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.Month;
import java.util.Optional;
import java.util.Set;


@RestController
@RequestMapping(value = "api/events")
@RequiredArgsConstructor
public class EventsAPI {

private final EventsService eventsService;


@GetMapping
@Operation(summary = "returns list of events in PWr from given month and year (both optional)",
description = "endpoint gets events from site: https://pwr.edu.pl/uczelnia/przed-nami with given month and year" +
" By default month and year are current. When events are duplicated, it returns it merged")
public ResponseEntity<Set<EventDto>> getEventsOfTheMonth(
@RequestParam Optional<Month> month, @RequestParam Optional<Integer> year){
return ResponseEntity.ok(eventsService.getEventsOfMonth(month, year));
}

}
Loading