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 java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@ApplicationScoped
|
||||
|
|
@ -28,6 +29,12 @@ public class OrganizationRepositoryImpl implements OrganizationRepository, Panac
|
|||
|
||||
@Override
|
||||
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()
|
||||
.map(OrganizationEntityMapper::toDomain)
|
||||
.toList();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import jakarta.ws.rs.PATCH;
|
|||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
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.CreateOrganizationOutput;
|
||||
import net.beetechgroup.beetask.usecase.organization.create.CreateOrganizationUseCase;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
package net.beetechgroup.beetask.usecase.organization.search;
|
||||
|
||||
import net.beetechgroup.beetask.entities.organization.Organization;
|
||||
import net.beetechgroup.beetask.usecase.repository.OrganizationRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SearchOrganizationsUseCase {
|
||||
private final OrganizationRepository organizationRepository;
|
||||
|
|
@ -14,9 +12,8 @@ public class SearchOrganizationsUseCase {
|
|||
}
|
||||
|
||||
public List<SearchOrganizationOutput> execute(String query) {
|
||||
List<Organization> results = organizationRepository.search(query);
|
||||
return results.stream()
|
||||
return organizationRepository.search(query).stream()
|
||||
.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,
|
||||
})
|
||||
|
||||
const text = await response.text()
|
||||
if (!response.ok) {
|
||||
const message = await response.text()
|
||||
throw new Error(message || 'Nao foi possivel concluir a requisicao.')
|
||||
throw new Error(text || '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 { motion } from 'framer-motion'
|
||||
import { Search, Building2, Send, CheckCircle2 } from 'lucide-react'
|
||||
import { organizationService } from '../services/organizationService'
|
||||
import React, { useState } from "react";
|
||||
import { motion } from "framer-motion";
|
||||
import { Search, Building2, Send, CheckCircle2 } from "lucide-react";
|
||||
import { organizationService } from "../services/organizationService";
|
||||
|
||||
interface OrgResult {
|
||||
id: number
|
||||
name: string
|
||||
id: number;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export const JoinOrganizationPage: React.FC = () => {
|
||||
const [query, setQuery] = useState('')
|
||||
const [results, setResults] = useState<OrgResult[]>([])
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [requestedId, setRequestedId] = useState<number | null>(null)
|
||||
const [query, setQuery] = useState("");
|
||||
const [results, setResults] = useState<OrgResult[] | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [requestedId, setRequestedId] = useState<number | null>(null);
|
||||
|
||||
const handleSearch = async (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!query) return
|
||||
setIsLoading(true)
|
||||
e.preventDefault();
|
||||
if (!query) return;
|
||||
setIsLoading(true);
|
||||
|
||||
try {
|
||||
const data = await organizationService.search(query)
|
||||
setResults(data)
|
||||
const data = await organizationService.search(query);
|
||||
setResults(data);
|
||||
} catch (error) {
|
||||
console.error('Search failed', error)
|
||||
console.error("Search failed", error);
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleJoinRequest = async (id: number) => {
|
||||
try {
|
||||
await organizationService.requestJoin(id)
|
||||
setRequestedId(id)
|
||||
alert('Solicitação enviada! Aguarde a aprovação do dono da organização.')
|
||||
await organizationService.requestJoin(id);
|
||||
setRequestedId(id);
|
||||
alert("Solicitação enviada! Aguarde a aprovação do dono da organização.");
|
||||
} catch (error) {
|
||||
console.error('Join request failed', error)
|
||||
alert(error instanceof Error ? error.message : 'Erro ao enviar solicitação.')
|
||||
}
|
||||
console.error("Join request failed", error);
|
||||
alert(
|
||||
error instanceof Error ? error.message : "Erro ao enviar solicitação.",
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<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 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>
|
||||
|
||||
<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="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} />
|
||||
</div>
|
||||
<h1 className="text-3xl font-black text-text-main tracking-tight mb-3">Buscar Organização</h1>
|
||||
<p className="text-text-muted font-medium">Encontre uma organização pelo nome</p>
|
||||
<h1 className="text-3xl font-black text-text-main tracking-tight mb-3">
|
||||
Buscar Organização
|
||||
</h1>
|
||||
<p className="text-text-muted font-medium">
|
||||
Encontre uma organização pelo nome
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<form onSubmit={handleSearch} className="flex gap-3 mb-8">
|
||||
<div className="relative flex-1 group">
|
||||
<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>
|
||||
<input
|
||||
type="text"
|
||||
value={query}
|
||||
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..."
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
type="submit"
|
||||
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>
|
||||
</form>
|
||||
|
||||
<div className="space-y-3">
|
||||
{results.length > 0 ? (
|
||||
{results && results.length > 0 ? (
|
||||
results.map((org) => (
|
||||
<div
|
||||
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="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} />
|
||||
</div>
|
||||
<span className="font-bold text-text-main">{org.name}</span>
|
||||
</div>
|
||||
{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} />
|
||||
Solicitado
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
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} />
|
||||
Solicitar entrada
|
||||
|
|
@ -111,12 +121,14 @@ export const JoinOrganizationPage: React.FC = () => {
|
|||
)}
|
||||
</div>
|
||||
))
|
||||
) : query && !isLoading ? (
|
||||
<p className="text-center text-text-muted py-10 font-medium">Nenhuma organização encontrada.</p>
|
||||
) : results && results.length === 0 ? (
|
||||
<p className="text-center text-text-muted py-10 font-medium">
|
||||
Nenhuma organização encontrada.
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue