fix: error when no content response
This commit is contained in:
parent
22760ba661
commit
56f0d20b06
5 changed files with 66 additions and 49 deletions
|
|
@ -9,6 +9,7 @@ import net.beetechgroup.beetask.frameworks.persistence.mapper.OrganizationEntity
|
||||||
import net.beetechgroup.beetask.usecase.repository.OrganizationRepository;
|
import net.beetechgroup.beetask.usecase.repository.OrganizationRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
|
|
@ -28,6 +29,12 @@ public class OrganizationRepositoryImpl implements OrganizationRepository, Panac
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Organization> search(String query) {
|
public List<Organization> search(String query) {
|
||||||
|
if (Objects.isNull(query) || query.isBlank()) {
|
||||||
|
return findAll().list().stream()
|
||||||
|
.map(OrganizationEntityMapper::toDomain)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
return find("name like ?1", "%" + query + "%").stream()
|
return find("name like ?1", "%" + query + "%").stream()
|
||||||
.map(OrganizationEntityMapper::toDomain)
|
.map(OrganizationEntityMapper::toDomain)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import jakarta.ws.rs.PATCH;
|
||||||
import jakarta.ws.rs.Path;
|
import jakarta.ws.rs.Path;
|
||||||
import jakarta.ws.rs.PathParam;
|
import jakarta.ws.rs.PathParam;
|
||||||
import jakarta.ws.rs.QueryParam;
|
import jakarta.ws.rs.QueryParam;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
import net.beetechgroup.beetask.usecase.organization.create.CreateOrganizationInput;
|
import net.beetechgroup.beetask.usecase.organization.create.CreateOrganizationInput;
|
||||||
import net.beetechgroup.beetask.usecase.organization.create.CreateOrganizationOutput;
|
import net.beetechgroup.beetask.usecase.organization.create.CreateOrganizationOutput;
|
||||||
import net.beetechgroup.beetask.usecase.organization.create.CreateOrganizationUseCase;
|
import net.beetechgroup.beetask.usecase.organization.create.CreateOrganizationUseCase;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
package net.beetechgroup.beetask.usecase.organization.search;
|
package net.beetechgroup.beetask.usecase.organization.search;
|
||||||
|
|
||||||
import net.beetechgroup.beetask.entities.organization.Organization;
|
|
||||||
import net.beetechgroup.beetask.usecase.repository.OrganizationRepository;
|
import net.beetechgroup.beetask.usecase.repository.OrganizationRepository;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class SearchOrganizationsUseCase {
|
public class SearchOrganizationsUseCase {
|
||||||
private final OrganizationRepository organizationRepository;
|
private final OrganizationRepository organizationRepository;
|
||||||
|
|
@ -14,9 +12,8 @@ public class SearchOrganizationsUseCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SearchOrganizationOutput> execute(String query) {
|
public List<SearchOrganizationOutput> execute(String query) {
|
||||||
List<Organization> results = organizationRepository.search(query);
|
return organizationRepository.search(query).stream()
|
||||||
return results.stream()
|
|
||||||
.map(org -> new SearchOrganizationOutput(org.getId(), org.getName()))
|
.map(org -> new SearchOrganizationOutput(org.getId(), org.getName()))
|
||||||
.collect(Collectors.toList());
|
.toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,10 @@ export async function apiFetch<T>(path: string, options: RequestOptions = {}) {
|
||||||
: body,
|
: body,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const text = await response.text()
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const message = await response.text()
|
throw new Error(text || 'Nao foi possivel concluir a requisicao.')
|
||||||
throw new Error(message || 'Nao foi possivel concluir a requisicao.')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (await response.json()) as T
|
return text ? (JSON.parse(text) as T) : (undefined as T)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,49 +1,51 @@
|
||||||
import React, { useState } from 'react'
|
import React, { useState } from "react";
|
||||||
import { motion } from 'framer-motion'
|
import { motion } from "framer-motion";
|
||||||
import { Search, Building2, Send, CheckCircle2 } from 'lucide-react'
|
import { Search, Building2, Send, CheckCircle2 } from "lucide-react";
|
||||||
import { organizationService } from '../services/organizationService'
|
import { organizationService } from "../services/organizationService";
|
||||||
|
|
||||||
interface OrgResult {
|
interface OrgResult {
|
||||||
id: number
|
id: number;
|
||||||
name: string
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const JoinOrganizationPage: React.FC = () => {
|
export const JoinOrganizationPage: React.FC = () => {
|
||||||
const [query, setQuery] = useState('')
|
const [query, setQuery] = useState("");
|
||||||
const [results, setResults] = useState<OrgResult[]>([])
|
const [results, setResults] = useState<OrgResult[] | null>(null);
|
||||||
const [isLoading, setIsLoading] = useState(false)
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [requestedId, setRequestedId] = useState<number | null>(null)
|
const [requestedId, setRequestedId] = useState<number | null>(null);
|
||||||
|
|
||||||
const handleSearch = async (e: React.FormEvent) => {
|
const handleSearch = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault();
|
||||||
if (!query) return
|
if (!query) return;
|
||||||
setIsLoading(true)
|
setIsLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await organizationService.search(query)
|
const data = await organizationService.search(query);
|
||||||
setResults(data)
|
setResults(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Search failed', error)
|
console.error("Search failed", error);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false)
|
setIsLoading(false);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleJoinRequest = async (id: number) => {
|
const handleJoinRequest = async (id: number) => {
|
||||||
try {
|
try {
|
||||||
await organizationService.requestJoin(id)
|
await organizationService.requestJoin(id);
|
||||||
setRequestedId(id)
|
setRequestedId(id);
|
||||||
alert('Solicitação enviada! Aguarde a aprovação do dono da organização.')
|
alert("Solicitação enviada! Aguarde a aprovação do dono da organização.");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Join request failed', error)
|
console.error("Join request failed", error);
|
||||||
alert(error instanceof Error ? error.message : 'Erro ao enviar solicitação.')
|
alert(
|
||||||
}
|
error instanceof Error ? error.message : "Erro ao enviar solicitação.",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-app-bg flex items-center justify-center p-4 relative overflow-hidden font-sans">
|
<div className="min-h-screen bg-app-bg flex items-center justify-center p-4 relative overflow-hidden font-sans">
|
||||||
<div className="absolute top-0 left-0 w-full h-full overflow-hidden pointer-events-none opacity-50">
|
<div className="absolute top-0 left-0 w-full h-full overflow-hidden pointer-events-none opacity-50">
|
||||||
<div className="absolute top-0 right-0 w-[40%] h-[40%] bg-accent/15 blur-[100px] rounded-full" />
|
<div className="absolute top-0 right-0 w-[40%] h-[40%] bg-brand/15 blur-[100px] rounded-full" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<motion.div
|
<motion.div
|
||||||
|
|
@ -53,57 +55,65 @@ export const JoinOrganizationPage: React.FC = () => {
|
||||||
>
|
>
|
||||||
<div className="bg-surface border border-border-soft p-10 rounded-[2.5rem] shadow-panel">
|
<div className="bg-surface border border-border-soft p-10 rounded-[2.5rem] shadow-panel">
|
||||||
<div className="flex flex-col items-center mb-10 text-center">
|
<div className="flex flex-col items-center mb-10 text-center">
|
||||||
<div className="w-14 h-14 bg-accent text-white rounded-2xl flex items-center justify-center mb-6 shadow-lg shadow-accent/20">
|
<div className="w-14 h-14 bg-brand text-white rounded-2xl flex items-center justify-center mb-6 shadow-lg shadow-brand/20">
|
||||||
<Search size={28} />
|
<Search size={28} />
|
||||||
</div>
|
</div>
|
||||||
<h1 className="text-3xl font-black text-text-main tracking-tight mb-3">Buscar Organização</h1>
|
<h1 className="text-3xl font-black text-text-main tracking-tight mb-3">
|
||||||
<p className="text-text-muted font-medium">Encontre uma organização pelo nome</p>
|
Buscar Organização
|
||||||
|
</h1>
|
||||||
|
<p className="text-text-muted font-medium">
|
||||||
|
Encontre uma organização pelo nome
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form onSubmit={handleSearch} className="flex gap-3 mb-8">
|
<form onSubmit={handleSearch} className="flex gap-3 mb-8">
|
||||||
<div className="relative flex-1 group">
|
<div className="relative flex-1 group">
|
||||||
<div className="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none">
|
<div className="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none">
|
||||||
<Building2 className="h-5 w-5 text-text-muted group-focus-within:text-accent transition-colors" />
|
<Building2 className="h-5 w-5 text-text-muted group-focus-within:text-brand transition-colors" />
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={query}
|
value={query}
|
||||||
onChange={(e) => setQuery(e.target.value)}
|
onChange={(e) => setQuery(e.target.value)}
|
||||||
className="block w-full pl-12 pr-4 py-3.5 bg-surface-muted/50 border border-border-soft rounded-2xl text-text-main placeholder-text-muted/60 focus:outline-none focus:ring-4 focus:ring-accent/10 focus:border-accent transition-all font-medium"
|
className="block w-full pl-12 pr-4 py-3.5 bg-surface-muted/50 border border-border-soft rounded-2xl text-text-main placeholder-text-muted/60 focus:outline-none focus:ring-4 focus:ring-brand/10 focus:border-brand transition-all font-medium"
|
||||||
placeholder="Nome da organização..."
|
placeholder="Nome da organização..."
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
className="bg-accent hover:bg-accent/90 text-white font-bold px-8 rounded-2xl transition-all shadow-lg shadow-accent/20 active:scale-[0.98] flex items-center gap-2"
|
className="bg-brand hover:bg-brand-strong text-white font-bold px-8 rounded-2xl transition-all shadow-lg shadow-brand/20 active:scale-[0.98] flex items-center gap-2"
|
||||||
>
|
>
|
||||||
{isLoading ? <div className="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin" /> : 'Buscar'}
|
{isLoading ? (
|
||||||
|
<div className="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin" />
|
||||||
|
) : (
|
||||||
|
"Buscar"
|
||||||
|
)}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
{results.length > 0 ? (
|
{results && results.length > 0 ? (
|
||||||
results.map((org) => (
|
results.map((org) => (
|
||||||
<div
|
<div
|
||||||
key={org.id}
|
key={org.id}
|
||||||
className="flex items-center justify-between p-5 bg-surface-muted/30 border border-border-soft rounded-2xl hover:border-accent/50 transition-all"
|
className="flex items-center justify-between p-5 bg-surface-muted/30 border border-border-soft rounded-2xl hover:border-brand/50 transition-all"
|
||||||
>
|
>
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
<div className="w-10 h-10 bg-accent/10 text-accent rounded-lg flex items-center justify-center">
|
<div className="w-10 h-10 bg-brand/10 text-brand rounded-lg flex items-center justify-center">
|
||||||
<Building2 size={20} />
|
<Building2 size={20} />
|
||||||
</div>
|
</div>
|
||||||
<span className="font-bold text-text-main">{org.name}</span>
|
<span className="font-bold text-text-main">{org.name}</span>
|
||||||
</div>
|
</div>
|
||||||
{requestedId === org.id ? (
|
{requestedId === org.id ? (
|
||||||
<div className="flex items-center gap-2 text-green-500 font-bold text-sm bg-green-500/10 px-4 py-2 rounded-xl">
|
<div className="flex items-center gap-2 text-success font-bold text-sm bg-success/10 px-4 py-2 rounded-xl">
|
||||||
<CheckCircle2 size={16} />
|
<CheckCircle2 size={16} />
|
||||||
Solicitado
|
Solicitado
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<button
|
<button
|
||||||
onClick={() => handleJoinRequest(org.id)}
|
onClick={() => handleJoinRequest(org.id)}
|
||||||
className="flex items-center gap-2 text-accent font-bold text-sm hover:bg-accent hover:text-white px-4 py-2 rounded-xl border border-accent/20 transition-all"
|
className="flex items-center gap-2 text-brand font-bold text-sm hover:bg-brand hover:text-white px-4 py-2 rounded-xl border border-brand/20 transition-all"
|
||||||
>
|
>
|
||||||
<Send size={16} />
|
<Send size={16} />
|
||||||
Solicitar entrada
|
Solicitar entrada
|
||||||
|
|
@ -111,12 +121,14 @@ export const JoinOrganizationPage: React.FC = () => {
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
) : query && !isLoading ? (
|
) : results && results.length === 0 ? (
|
||||||
<p className="text-center text-text-muted py-10 font-medium">Nenhuma organização encontrada.</p>
|
<p className="text-center text-text-muted py-10 font-medium">
|
||||||
|
Nenhuma organização encontrada.
|
||||||
|
</p>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
</div>
|
</div>
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue