Skip to content

Commit

Permalink
Changed Company fetching from access token to id and added own id seq…
Browse files Browse the repository at this point in the history
…uence for companies
  • Loading branch information
Gugi-Games committed Jun 20, 2024
1 parent 0563d83 commit 1650117
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/main/java/com/MeetMate/company/Company.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.MeetMate.enums.BusinessType;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

Expand Down
7 changes: 0 additions & 7 deletions src/main/java/com/MeetMate/company/CompanyRepository.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.MeetMate.company;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;
Expand All @@ -14,8 +11,4 @@ public interface CompanyRepository extends MongoRepository<Company, Long> {
Optional<Company> findCompanyByOwnerEmail(String ownerEmail);

Optional<Company> findCompanyById(long id);

// @Modifying
// @Query("{ 'ownerEmail': :#{#ownerEmail} }")
// Company updateByOwnerEmail(String ownerEmail);
}
12 changes: 2 additions & 10 deletions src/main/java/com/MeetMate/company/CompanyService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.MeetMate.company;

import com.MeetMate.company.sequence.CompanySequence;
import com.MeetMate.company.sequence.SequenceService;
import com.MeetMate.enums.BusinessType;
import com.MeetMate.enums.UserRole;
import com.MeetMate.security.JwtService;
import com.MeetMate.user.UserController;
import com.MeetMate.user.UserRepository;
import jakarta.persistence.EntityNotFoundException;
Expand All @@ -25,7 +23,6 @@ public class CompanyService {
private final UserController userController;
private final UserRepository userRepository;
private final CompanyRepository companyRepository;
private final JwtService jwtService;
private final MongoTemplate mongoTemplate;
private final SequenceService sequenceService;

Expand All @@ -52,18 +49,13 @@ public void createCompany(String companyName, String ownerEmail, String ownerNam

userController.registerNewUser(ownerData);

long companyId = sequenceService.getCurrentValue();
long companyId = sequenceService.getAndIncrementCurrentValue();
companyRepository.save(new Company(companyId, companyName, ownerEmail));
}

@Transactional
public void editCompany(String token, String companyName, String description, String businessType) {
Company company = getCompanyWithToken(token);
String ownerEmail = jwtService.extractUserEmail(token);
// if(companyName != null) company.setName(companyName);
// if(description != null) company.setDescription(description);
// if(businessType != null) company.setBusinessType(BusinessType.valueOf(businessType));
// companyRepository.save(company);
String ownerEmail = getCompanyWithToken(token).getOwnerEmail();

Query query = new Query(Criteria.where("ownerEmail").is(ownerEmail));
Update update = new Update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void incrementId() {
mongoTemplate.updateFirst(query, update, CompanySequence.class);
}

public long getCurrentValue(){
public long getAndIncrementCurrentValue(){
Query query = new Query(Criteria.where("_id").is("company_sequence"));
CompanySequence sequence = mongoTemplate.findOne(query, CompanySequence.class);
long value = sequence.getValue();
Expand Down

0 comments on commit 1650117

Please sign in to comment.