Skip to content

Commit

Permalink
Added method to fetch all companies
Browse files Browse the repository at this point in the history
  • Loading branch information
Gugi-Games committed Oct 24, 2024
1 parent 69f5bd1 commit e3bd4cc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/MeetMate/company/CompanyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.MeetMate.user.User;
import jakarta.persistence.EntityNotFoundException;
import lombok.RequiredArgsConstructor;
import org.hibernate.mapping.Array;
import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.ContextValue;
import org.springframework.graphql.data.method.annotation.MutationMapping;
Expand All @@ -16,6 +17,7 @@

import java.lang.reflect.InaccessibleObjectException;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping(path = "api/company")
Expand Down Expand Up @@ -43,6 +45,17 @@ public Company getCompany(@Argument long id) {
}
}

@QueryMapping
public List<Company> getCompanies() {
try {
return companyService.getCompanies();

} catch (Throwable t) {
Class<? extends Throwable> tc = t.getClass();
return List.of(new Company(-1, "error", "error", -1));
}

}
@MutationMapping
public ResponseEntity<?> createCompany(
@Argument String companyName,
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/MeetMate/company/CompanyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
Expand All @@ -37,6 +38,10 @@ public Company getCompany(long id) throws IllegalArgumentException {
.orElseThrow(() -> new EntityNotFoundException("Company not found"));
}

public List<Company> getCompanies() {
return companyRepository.findAll();
}

@Transactional
public void createCompany(String companyName, String ownerEmail, String ownerName, String ownerPassword) {
long companyId = companySequenceService.getCurrentValue();
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/graphql/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ type Query {
#Company Queries
getCompany(id: ID!): Company

getCompanies: [Company]

getMember(memberId: ID!): GetResponse

getAllMembers: [GetResponse]
Expand Down

0 comments on commit e3bd4cc

Please sign in to comment.