Skip to content

Commit

Permalink
new update
Browse files Browse the repository at this point in the history
Add files via upload
  • Loading branch information
ohthias authored Nov 19, 2024
2 parents 927814d + e0bb2ad commit 1afa3c3
Show file tree
Hide file tree
Showing 93 changed files with 3,535 additions and 4,698 deletions.
20 changes: 0 additions & 20 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"liveServer.settings.port": 5503
"liveServer.settings.port": 5501
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@
*/

import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.*;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import com.example.Astro.Model.User;
Expand Down Expand Up @@ -64,7 +60,7 @@ public String sign(){
return "sign";
}

@GetMapping("/home")
@GetMapping("/astro")
public String home(@RequestParam("token") String token, Model model) {
// Busca o usuário usando o token
User user = userService.getUserByToken(token);
Expand All @@ -74,21 +70,29 @@ public String home(@RequestParam("token") String token, Model model) {
} else {
model.addAttribute("error", "Usuário não encontrado");
}

return "home"; // Nome da página HTML que será exibida
return "astro"; // Nome da página HTML que será exibida
}

@GetMapping("/artist")
public String artist() { return "artist";}

@GetMapping("/playlist")
public String playlist() {return "playlist";}

@GetMapping("/album")
public String album() {return "album";}
@GetMapping("/{page}")
public ResponseEntity<Map<String, String>> getContent(@PathVariable String page) {
Map<String, String> content = new HashMap<>();

// Define o conteúdo de cada página
switch (page) {
case "home":
case "busca":
case "album":
case "artist":
case "playlist":
case "user":
default:
content.put("title", "Erro");
content.put("body", "Conteúdo não encontrado.");
}

@GetMapping("/busca")
public String busca() {return "busca";}
// Retorna o conteúdo como JSON
return ResponseEntity.ok(content);
}

@GetMapping("/setting")
public String setting() {return "setting";}
Expand Down Expand Up @@ -152,17 +156,32 @@ public String getArtistDetails(@PathVariable("id") String artistId, @RequestPara
@PostMapping("/register")
public String insertUser(@RequestParam String username,
@RequestParam String email,
@RequestParam String hashWord) {
@RequestParam String hashWord,
Model model) {

BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
String clienteHashword = encoder.encode(hashWord);
User userExist = repository.findByUsername(username);
User emailExist = repository.findByEmail(email);

if (userExist != null) {
model.addAttribute("errorMessage", "Esse usuário já está sendo usado");
return "sign";
}

if (emailExist != null) {
model.addAttribute("errorMessage", "Esse email já está sendo usado por um usuário");
return "sign";
}

String token = tokenService.generateToken(username, email);

LocalDate currentDate = LocalDate.now();

User usuario = new User(null, email, clienteHashword, username, currentDate, token);
User usuario = new User(null, email, clienteHashword, username, currentDate , token, "defaultTheme");
repository.save(usuario);
return "redirect:/home?token=" + token;
String theme = usuario.getTheme();
return "redirect:/astro?token=" + token + "&theme=" + theme;
}

@PostMapping("/login-user")
Expand Down Expand Up @@ -190,8 +209,11 @@ public String readUser(@RequestParam String username,

// Gerar token e redirecionar com o token na URL
String token = tokenService.generateToken(username, user.getEmail());
user.setToken(token);
repository.save(user);
String theme = user.getTheme();

return "redirect:/home?token=" + token;
return "redirect:/astro?token=" + token + "&theme=" + theme;
} catch (Exception e) {
e.printStackTrace();
model.addAttribute("errorMessage", "Erro ao processar o login");
Expand All @@ -203,7 +225,6 @@ public String readUser(@RequestParam String username,
@GetMapping("/logout")
public String logout() {
// O token é removido no frontend (no JavaScript), aqui só redirecionamos para a tela de login.
return "redirect:/login";
return "redirect:/astro";
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.Astro.Controller;

import com.example.Astro.Model.Playlist;
import com.example.Astro.Service.PlaylistService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/playlists")
public class PlaylistController {
private final PlaylistService playlistService;

public PlaylistController(PlaylistService playlistService) {
this.playlistService = playlistService;
}

@GetMapping("/user/{userId}")
public ResponseEntity<List<Playlist>> getPlaylistsByUser(@PathVariable Long userId) {
return ResponseEntity.ok(playlistService.getPlaylistsByUser(userId));
}

@PostMapping
public ResponseEntity<Playlist> createPlaylist(@RequestBody Playlist playlist) {
return ResponseEntity.ok(playlistService.createPlaylist(playlist));
}

@PutMapping("/{id}")
public ResponseEntity<Playlist> updatePlaylist(@PathVariable Long id, @RequestBody Playlist updatedPlaylist) {
return ResponseEntity.ok(playlistService.updatePlaylist(id, updatedPlaylist));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.example.Astro.Controller;

import com.example.Astro.Model.User;
import com.example.Astro.Repository.UserRepository;
import com.example.Astro.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api")
public class ThemeController {

@Autowired
private UserService userService; // Serviço para gerenciar usuários
@Autowired
private UserRepository repository;

@PostMapping("/save-theme")
public ResponseEntity<String> saveTheme(@RequestBody Map<String, String> request, @RequestHeader("Authorization") String token) {
String theme = request.get("theme");

if (theme == null || theme.isEmpty()) {
return ResponseEntity.badRequest().body("Tema não fornecido.");
}

// Remove o prefixo "Bearer " do token
token = token.replace("Bearer ", "");
System.out.println("token: \n" +token);

// Busca o usuário pelo token
User user = userService.getUserByToken(token);
if (user == null) {
System.out.println("\nUsuário não encontrado\n");
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Usuário não autenticado.");
}

// Atualiza o tema no banco de dados
user.setTheme(theme); // Supondo que você tenha um campo `theme` na entidade `User`
repository.save(user); // Salva o usuário atualizado no banco de dados

return ResponseEntity.ok("Tema salvo com sucesso!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ public User getUserById(@PathVariable Long id) {
return userRepository.findById(id)
.orElseThrow(() -> new RuntimeException("Usuário não encontrado"));
}


}
66 changes: 66 additions & 0 deletions Astro/src/main/java/com/example/Astro/Model/Playlist.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.example.Astro.Model;

import jakarta.persistence.*;

import java.time.LocalDate;

@Entity
@Table(name ="playlists")
public class Playlist {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idPlaylists")
private long idPlaylists;

@Column(name = "Name")
private String name;

@Column(name = "Update_At")
private LocalDate updateAt;

@Column(name = "Public")
private Boolean publicPlay;

@Column(name = "id_User_Details")
private Long idUserDetails;

public void setIdPlaylists(long idPlaylists) {
this.idPlaylists = idPlaylists;
}

public void setName(String name) {
this.name = name;
}

public void setUpdateAt(LocalDate updateAt) {
this.updateAt = updateAt;
}

public void setPublicPlay(Boolean publicPlay) {
this.publicPlay = publicPlay;
}

public void setIdUserDetails(Long idUserDetails) {
this.idUserDetails = idUserDetails;
}

public LocalDate getUpdateAt() {
return updateAt;
}

public Boolean getPublicPlay() {
return publicPlay;
}

public Long getIdUserDetails() {
return idUserDetails;
}

public String getName() {
return name;
}

public long getIdPlaylists() {
return idPlaylists;
}
}
12 changes: 11 additions & 1 deletion Astro/src/main/java/com/example/Astro/Model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ public class User {
@Column(name = "last_access")
private LocalDate lastAccess;

@Column(name = "theme")
private String theme;

public User() {
super();
}

public User(Long idUserDetails, String email, String password, String username, LocalDate lastAccess, String token) {
public User(Long idUserDetails, String email, String password, String username, LocalDate lastAccess, String token, String theme) {
super();
this.idUserDetails = idUserDetails;
this.email = email;
this.password = password;
this.username = username;
this.lastAccess = lastAccess;
this.token = token;
this.theme = theme;
}

// Getters e Setters
Expand Down Expand Up @@ -90,4 +94,10 @@ public LocalDate getLastAccess() {
public void setLastAccess(LocalDate lastAccess) {
this.lastAccess = lastAccess;
}

public void setTheme(String theme){this.theme = theme;}

public String getTheme() {
return theme;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.Astro.Repository;

import com.example.Astro.Model.Playlist;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface PlaylistRepository extends JpaRepository<Playlist, Long> {
List<Playlist> findByIdUserDetails(Long userId); // Para buscar playlists de um usuário específico
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
public interface UserRepository extends JpaRepository<User, Long> {
User findByUsername(String username);
User findByToken(String token);
User findByEmail(String email);
}
Loading

0 comments on commit 1afa3c3

Please sign in to comment.