Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
1615f8e
create Word class and controller
AlbertProfe Jan 10, 2025
55f09b9
add repository and application.properties
AlbertProfe Jan 10, 2025
17056d0
create controller word method get all words
AlbertProfe Jan 10, 2025
4116bbd
spring boot rest controller docs
AlbertProfe Jan 10, 2025
8f2660e
renaming files
AlbertProfe Jan 10, 2025
5cbb18b
renaming files
AlbertProfe Jan 10, 2025
656ac27
WordController comments
AlbertProfe Jan 16, 2025
0b15c36
test with JUnit to word entity
AlbertProfe Jan 16, 2025
b5c117a
spring docs-resources images project structure
AlbertProfe Jan 16, 2025
aa68930
spring docs-resources test JUnit word
AlbertProfe Jan 16, 2025
0eb0b0f
db local
AlbertProfe Jan 17, 2025
557b0d6
new folder Test Junit
AlbertProfe Jan 17, 2025
f596df5
basic wordController CRUD
AlbertProfe Jan 17, 2025
8fd89c9
H2 local db and word controller
AlbertProfe Jan 17, 2025
8fdc1ad
move md
AlbertProfe Jan 17, 2025
6c6a27e
doc: containers and pronunciationApp-v0.1
AlbertProfe Jan 23, 2025
50b30db
feat: refactor controller and repository
AlbertProfe Jan 23, 2025
052eeef
doc: spring boot for 5yo
AlbertProfe Jan 23, 2025
bc9c5ee
fix: getWordByPhoneticSpelling at WordRepository pronunciation fields…
AlbertProfe Jan 23, 2025
c4bc3db
feat: createWords and deleteAllWords
AlbertProfe Jan 23, 2025
52be154
doc: styling docs
AlbertProfe Jan 23, 2025
04dde27
doc: annotations
AlbertProfe Jan 24, 2025
7685ec5
doc: add mock-data script
AlbertProfe Jan 24, 2025
eea3805
doc: image h2 with mock data
AlbertProfe Jan 24, 2025
90e659a
feat: refactor with ResponseEntity, headers and optional
AlbertProfe Jan 24, 2025
ec64ac1
doc: import .csv to H2 DB
AlbertProfe Jan 24, 2025
d6590ad
doc: mock Server postman
AlbertProfe Jan 29, 2025
0313b8c
doc: update mock Server Postman
AlbertProfe Jan 29, 2025
e9fc851
doc: java faker
AlbertProfe Jan 30, 2025
b297b2a
doc: jpa
AlbertProfe Jan 30, 2025
072c3e2
feat: refactor WordController, implement WordService and create Healt…
AlbertProfe Jan 30, 2025
39a3371
doc: pronunciationApp-v0.2.d and spring 5yo
AlbertProfe Jan 30, 2025
530bbd3
feat: add PID, java version to HealthController
AlbertProfe Jan 30, 2025
84dc48f
doc: check health image
AlbertProfe Jan 30, 2025
113cb56
doc: create jpa folder
AlbertProfe Jan 30, 2025
2b07bc0
fix: check jpa folder typo
AlbertProfe Jan 30, 2025
2c1b472
doc: dal dao and model 0.2
AlbertProfe Jan 30, 2025
4f5d97c
doc: JPA queries
AlbertProfe Jan 31, 2025
a37c883
doc: update pronunciationApp-v0.2-model.md
AlbertProfe Jan 31, 2025
018aa40
doc: update jpa.md
AlbertProfe Jan 31, 2025
2a562e2
feat: new entity StageWord and controller service
AlbertProfe Jan 31, 2025
5157d71
doc: backend model v2.0
AlbertProfe Feb 7, 2025
8564464
doc: update backend model
AlbertProfe Feb 7, 2025
5a0eae9
doc: PronunciationApp Backend v0.3.md
AlbertProfe Feb 13, 2025
45a3a67
doc: update PronunciationApp Backend v0.3.md
AlbertProfe Feb 13, 2025
d253477
feat: Pronunciation entity and repo, onetomany word-pronunciation and…
AlbertProfe Feb 13, 2025
de41b66
doc: JPA one to many docs and images
AlbertProfe Feb 13, 2025
4924a83
doc: update pronunciationApp-v0.3
AlbertProfe Feb 13, 2025
b970d60
doc: update pronunciationApp-v0.3
AlbertProfe Feb 13, 2025
3ca4c14
doc: update pronunciationApp-v0.3
AlbertProfe Feb 13, 2025
75d2049
doc: update pronunciationApp-v0.3
AlbertProfe Feb 13, 2025
c9a6d11
doc: update pronunciationApp-v0.3
AlbertProfe Feb 13, 2025
257a16d
doc: enum
AlbertProfe Feb 14, 2025
9c2af16
doc: add unidirectional to pronunciationApp-v0.3
AlbertProfe Feb 14, 2025
2a78ced
doc: table summary word-pronunciation pronunciationApp-v0.3
AlbertProfe Feb 14, 2025
dd8f449
doc: craete pronunciationApp-v0.4.md
AlbertProfe Feb 20, 2025
ffc07de
feat: appUser and GameProgress entity
AlbertProfe Feb 20, 2025
9323a68
doc: cli spring, images jpa, annotations xml
AlbertProfe Feb 20, 2025
ffa2592
fix: typos
AlbertProfe Feb 20, 2025
aaa292a
feat: update service and repository
AlbertProfe Feb 21, 2025
759df00
Add files via upload
AlbertProfe Feb 21, 2025
538542e
Rename userAppBorrowBook - Copy.png to userAppBorrowBook-2
AlbertProfe Feb 21, 2025
24e56b8
Rename userAppBorrowBook-2 to userAppBorrowBook-2.png
AlbertProfe Feb 21, 2025
43c27b3
Update pronunciationApp-v0.4.md
AlbertProfe Feb 21, 2025
5e2722a
Update pronunciationApp-v0.4.md
AlbertProfe Feb 21, 2025
312c086
doc: update pronunciationApp-v0.4.md
AlbertProfe Feb 24, 2025
b4832d3
doc: mock-data insert sql
AlbertProfe Mar 7, 2025
690aeb7
feat: add repository and model classes for Level, Stage, and Category
Antonicv Mar 9, 2025
d991ac5
refactor: clean up code and add comments for clarity in model and con…
Antonicv Mar 10, 2025
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
5 changes: 5 additions & 0 deletions backend/pronunciationAppBack/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.pronunciationAppBack;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package dev.pronunciationAppBack.controller;

import dev.pronunciationAppBack.service.WordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
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.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/health")
public class HealthController {

@Autowired
private WordService wordService;

// Endpoint per comprovar l'estat de salut de l'aplicació
@GetMapping
public ResponseEntity<Map<String, Object>> healthCheck() {
Map<String, Object> healthStatus = new HashMap<>();
healthStatus.put("status", "UP");
healthStatus.put("timestamp", new Date());
healthStatus.put("wordCount", wordService.getWordCount());

// Verificar connexió a la base de dades
boolean databaseConnection = checkDatabaseConnection();
healthStatus.put("database", databaseConnection ? "Connected" : "Disconnected");

// Afegir més comprovacions de salut segons sigui necessari
healthStatus.put("memoryUsage", getMemoryUsage());
healthStatus.put("diskSpace", getDiskSpace());

// Afegir PID, versió de Java i altra informació del procés
healthStatus.put("pid", ProcessHandle.current().pid());
healthStatus.put("javaVersion", System.getProperty("java.version"));
healthStatus.put("javaVendor", System.getProperty("java.vendor"));
healthStatus.put("osName", System.getProperty("os.name"));
healthStatus.put("osVersion", System.getProperty("os.version"));

HttpHeaders headers = getCommonHeaders("Health check endpoint");
HttpStatus status = databaseConnection ? HttpStatus.OK : HttpStatus.SERVICE_UNAVAILABLE;

return new ResponseEntity<>(healthStatus, headers, status);
}

// Mètode per comprovar la connexió a la base de dades
private boolean checkDatabaseConnection() {
try {
wordService.getAllWords();
return true;
} catch (Exception e) {
return false;
}
}

// Mètode per obtenir l'ús de memòria
private Map<String, Long> getMemoryUsage() {
Runtime runtime = Runtime.getRuntime();
Map<String, Long> memoryInfo = new HashMap<>();
memoryInfo.put("total", runtime.totalMemory());
memoryInfo.put("free", runtime.freeMemory());
memoryInfo.put("used", runtime.totalMemory() - runtime.freeMemory());
return memoryInfo;
}

// Mètode per obtenir l'espai de disc
private Map<String, Long> getDiskSpace() {
java.io.File root = new java.io.File("/");
Map<String, Long> diskInfo = new HashMap<>();
diskInfo.put("total", root.getTotalSpace());
diskInfo.put("free", root.getFreeSpace());
diskInfo.put("usable", root.getUsableSpace());
return diskInfo;
}

// Mètode per obtenir capçaleres comunes per a les respostes HTTP
private HttpHeaders getCommonHeaders(String description) {
HttpHeaders headers = new HttpHeaders();
headers.add("desc", description);
headers.add("content-type", "application/json");
headers.add("date", new Date().toString());
headers.add("server", "Spring Boot");
headers.add("version", "1.0.0");
return headers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package dev.pronunciationAppBack.controller;

import dev.pronunciationAppBack.model.StageWord;
import dev.pronunciationAppBack.service.StageWordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/stagewords")
public class StageWordController {

@Autowired
private StageWordService stageWordService;

// Endpoint per obtenir totes les paraules d'etapa
@GetMapping
public ResponseEntity<List<StageWord>> getAllStageWords() {
List<StageWord> stageWords = stageWordService.getAllStageWords();
HttpHeaders headers = getCommonHeaders("Get all stage words");

return !stageWords.isEmpty()
? new ResponseEntity<>(stageWords, headers, HttpStatus.OK)
: new ResponseEntity<>(headers, HttpStatus.NOT_FOUND);
}

// Endpoint per obtenir una paraula d'etapa per ID
@GetMapping("/{id}")
public ResponseEntity<StageWord> getStageWordById(@PathVariable String id) {
Optional<StageWord> stageWord = stageWordService.getStageWordById(id);
HttpHeaders headers = getCommonHeaders("Get stage word by ID");

return stageWord.map(value -> new ResponseEntity<>(value, headers, HttpStatus.OK))
.orElseGet(() -> new ResponseEntity<>(headers, HttpStatus.NOT_FOUND));
}

// Endpoint per crear una nova paraula d'etapa
@PostMapping("/createStageWord")
public ResponseEntity<StageWord> createStageWord(@RequestBody StageWord stageWord) {
StageWord createdStageWord = stageWordService.createStageWord(stageWord);
HttpHeaders headers = getCommonHeaders("Create a new stage word");

return new ResponseEntity<>(createdStageWord, headers, HttpStatus.CREATED);
}

// Endpoint per actualitzar una paraula d'etapa existent
@PutMapping("/{id}")
public ResponseEntity<StageWord> updateStageWord(@PathVariable String id, @RequestBody StageWord stageWord) {
StageWord updatedStageWord = stageWordService.updateStageWord(stageWord);
HttpHeaders headers = getCommonHeaders("Update a stage word");

return new ResponseEntity<>(updatedStageWord, headers, HttpStatus.OK);
}

// Endpoint per eliminar una paraula d'etapa per ID
@DeleteMapping("/{id}")
public ResponseEntity<String> deleteStageWord(@PathVariable("id") String idToDelete) {
HttpHeaders headers = getCommonHeaders("Delete a stage word");

if (stageWordService.existsById(idToDelete)) {
stageWordService.deleteStageWord(idToDelete);
return new ResponseEntity<>("Stage word deleted", headers, HttpStatus.OK);
} else {
return new ResponseEntity<>("Stage word not found", headers, HttpStatus.NOT_FOUND);
}
}

// Endpoint per eliminar totes les paraules d'etapa
@DeleteMapping
public ResponseEntity<String> deleteAllStageWords() {
stageWordService.deleteAllStageWords();
HttpHeaders headers = getCommonHeaders("Delete all stage words");
return new ResponseEntity<>("All stage words deleted", headers, HttpStatus.OK);
}

// Mètode per obtenir capçaleres comunes per a les respostes HTTP
private HttpHeaders getCommonHeaders(String description) {
HttpHeaders headers = new HttpHeaders();
headers.add("desc", description);
headers.add("content-type", "application/json");
headers.add("date", new Date().toString());
headers.add("server", "Spring Boot");
headers.add("version", "1.0.0");
headers.add("stage-word-count", String.valueOf(stageWordService.getStageWordCount()));
headers.add("object", "stage-words");
return headers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package dev.pronunciationAppBack.controller;

import dev.pronunciationAppBack.model.Word;
import dev.pronunciationAppBack.service.WordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/api/words")
public class WordController {

@Autowired
private WordService wordService;

// Endpoint per obtenir totes les paraules
@GetMapping
public ResponseEntity<List<Word>> getAllWords() {
List<Word> words = wordService.getAllWords();
HttpHeaders headers = getCommonHeaders("Get all words");

return !words.isEmpty()
? new ResponseEntity<>(words, headers, HttpStatus.OK)
: new ResponseEntity<>(headers, HttpStatus.NOT_FOUND);
}

// Endpoint per obtenir una paraula per ID
@GetMapping("/{id}")
public ResponseEntity<Word> getWordById(@PathVariable String id) {
Optional<Word> word = wordService.getWordById(id);
HttpHeaders headers = getCommonHeaders("Get word by ID");

return word.map(value -> new ResponseEntity<>(value, headers, HttpStatus.OK))
.orElseGet(() -> new ResponseEntity<>(headers, HttpStatus.NOT_FOUND));
}

// Endpoint per crear una nova paraula
@PostMapping("/createWord")
public ResponseEntity<Word> createWord(@RequestBody Word word) {
Word createdWord = wordService.createWord(word);
HttpHeaders headers = getCommonHeaders("Create a new word");

return new ResponseEntity<>(createdWord, headers, HttpStatus.CREATED);
}

// Endpoint per actualitzar una paraula existent
@PutMapping("/{id}")
public ResponseEntity<Word> updateWord(@PathVariable String id, @RequestBody Word word) {
Word updatedWord = wordService.updateWord(word);
HttpHeaders headers = getCommonHeaders("Update a word");

return new ResponseEntity<>(updatedWord, headers, HttpStatus.OK);
}

// Endpoint per eliminar una paraula per ID
@DeleteMapping("/{id}")
public ResponseEntity<String> deleteWord(@PathVariable("id") String idToDelete) {
HttpHeaders headers = getCommonHeaders("Delete a word");

if (wordService.existsById(idToDelete)) {
wordService.deleteWord(idToDelete);
return new ResponseEntity<>("Word deleted", headers, HttpStatus.OK);
} else {
return new ResponseEntity<>("Word not found", headers, HttpStatus.NOT_FOUND);
}
}

// Endpoint per eliminar totes les paraules
@DeleteMapping
public ResponseEntity<String> deleteAllWords() {
wordService.deleteAllWords();
HttpHeaders headers = getCommonHeaders("Delete all words");
return new ResponseEntity<>("All words deleted", headers, HttpStatus.OK);
}

// Mètode per obtenir capçaleres comunes per a les respostes HTTP
private HttpHeaders getCommonHeaders(String description) {
HttpHeaders headers = new HttpHeaders();
headers.add("desc", description);
headers.add("content-type", "application/json");
headers.add("date", new Date().toString());
headers.add("server", "Spring Boot");
headers.add("version", "1.0.0");
headers.add("word-count", String.valueOf(wordService.getWordCount()));
headers.add("object", "words");
return headers;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.pronunciationAppBack.model;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AppUser {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")
private String id;

private String userName;
private int age;
private String email;
private String password;
private int totalScore;
private boolean isActive;

@OneToOne(mappedBy = "appUser", cascade = CascadeType.ALL)
private GameProgress gameProgress;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package dev.pronunciationAppBack.model;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;

@ManyToMany(mappedBy = "categories")
private List<Word> words;
}
Loading