Skip to content

Commit

Permalink
begin updating to release 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
anasabbal committed Feb 27, 2023
1 parent 96fa380 commit dc6ab01
Show file tree
Hide file tree
Showing 23 changed files with 117 additions and 82 deletions.
7 changes: 0 additions & 7 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions config-server/src/main/resources/bootstrap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ spring:
config:
server:
git:
uri: https://github.com/anasabbal/mini-uber-microservice/tree/master/config-server
default-label: master
uri: https://github.com/anasabbal/config-repo.git
4 changes: 2 additions & 2 deletions customer-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ spring:
password: guest
queue: customer.queue
template:
exchange: customer.exchange
exchange: amq.direct
routing-key: customer.routingkey
jpa:
properties:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
ddl-auto: create-drop
ddl-auto: update
show-sql: true
application:
name: customer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class DriverConfig {
@Bean
public DatabaseReader databaseReader() throws Exception {
File database = new File("/Users/anas/Downloads/mini-uber-microservice/driver-location-service/src/main/resources/GeoLite2-City_20221230/GeoLite2-City.mmdb");
File database = new File("/Users/anas/IdeaProjects/mini-uber-microservice/driver-location-service/src/main/resources/GeoLite2-City_20221230/GeoLite2-City.mmdb");
return new DatabaseReader.Builder(database)
.build();
}
Expand Down
2 changes: 1 addition & 1 deletion driver-location-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ spring:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
ddl-auto: create-drop
ddl-auto: update
show-sql: true
datasource:
driverClassName: org.postgresql.Driver
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;

@Entity
Expand All @@ -18,7 +20,8 @@ public class Address extends BaseEntity{
private String street;
private String city;
private String country;
@ManyToOne(optional = false)

@ManyToOne(cascade = CascadeType.ALL ,fetch = FetchType.EAGER)
private Driver driver;

public static <S extends AddressCommand> Address create(final S addressCommand){
Expand Down
4 changes: 2 additions & 2 deletions driver-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spring:
queue: customer.queue
template:
routing-key: customer.routingkey
exchange: customer.exchange
exchange: amq.direct

devtools:
livereload:
Expand All @@ -23,7 +23,7 @@ spring:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
ddl-auto: create-drop
ddl-auto: update
show-sql: true
datasource:
driverClassName: org.postgresql.Driver
Expand Down
4 changes: 2 additions & 2 deletions payment-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ spring:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
ddl-auto: create-drop
ddl-auto: update
show-sql: true
datasource:
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/bank
url: jdbc:postgresql://localhost:5432/payment
username: postgres
password: postgres

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
@SpringBootApplication
@EnableJpaAuditing
@EnableDiscoveryClient
@LoadBalancerClient(name = "RATING")
public class RatingServiceApplication {
public static void main(String[] args) {
SpringApplication.run(RatingServiceApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
public class RatingCommand {
private Integer ratingScore;
private String userId;
private String driverId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@


import com.nas.rating.command.RatingCommand;
import com.nas.rating.models.Rating;
import com.nas.rating.models.RatingEntity;
import com.nas.rating.service.RatingService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand All @@ -23,17 +21,24 @@ public class RatingController {
private final RatingService ratingService;

@PostMapping
public ResponseEntity<Rating> create(@RequestBody final RatingCommand ratingCommand){
final Rating rating = ratingService.createRating(ratingCommand);
public ResponseEntity<RatingEntity> create(@RequestBody final RatingCommand ratingCommand){
final RatingEntity rating = ratingService.createRating(ratingCommand);
final URI uri = fromCurrentRequest().path("/{id}").buildAndExpand(rating.getId()).toUri();
return ResponseEntity.created(uri).body(rating);
}
@GetMapping("/{id}")
public ResponseEntity<RatingEntity> getOneAndCreate(@PathVariable("id") final String id){
final RatingEntity rating = ratingService.getOneAndCreate(id);
final URI uri = fromCurrentRequest().path("/{id}").buildAndExpand(rating.getId()).toUri();
return ResponseEntity.created(uri).body(rating);
}
/*
@GetMapping
public ResponseEntity<Page<Rating>> getRatings(Pageable pageable){
return ResponseEntity.ok(ratingService.getRatings(pageable));
}
@GetMapping(DRIVERS + "/{driverId}")
public ResponseEntity<Rating> getByDriverId(@PathVariable("driverId") final String driverId){
return ResponseEntity.ok(ratingService.findRatingByDriverId(driverId));
}
}*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.nas.rating.models;


import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class CustomerRating {
private String id;

public CustomerRating(String id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.nas.rating.models;


import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class DriverRating {
private String id;

public DriverRating(String id) {
this.id = id;
}
}
32 changes: 0 additions & 32 deletions rating-service/src/main/java/com/nas/rating/models/Rating.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.nas.rating.models;


import com.nas.rating.command.RatingCommand;
import lombok.*;

import javax.persistence.*;

@Entity
@Getter
@Setter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class RatingEntity extends BaseEntity{

@Column(name = "USER_ID")
private String userId;

@Column(name = "USER_ID_FEEDBACK")
private String userIdFeedback = "";
@Column(name = "SCORE")
private Integer ratingScore = null;

public static RatingEntity create(final RatingCommand ratingCommand){
final RatingEntity rating = new RatingEntity();

return rating;
}
public static RatingEntity getOneAndCreate(final String userId){
final RatingEntity rating = new RatingEntity();

rating.userId = userId;
return rating;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.nas.rating.repository;

import com.nas.rating.models.Rating;
import com.nas.rating.models.RatingEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;


@Repository
public interface RatingRepository extends JpaRepository<Rating, String> {
Rating findRatingByUserId(String id);
public interface RatingRepository extends JpaRepository<RatingEntity, String> {
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.nas.rating.service;

import com.nas.rating.command.RatingCommand;
import com.nas.rating.models.Rating;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import com.nas.rating.models.RatingEntity;

public interface RatingService {
Rating createRating(final RatingCommand ratingCommand);
Page<Rating> getRatings(Pageable pageable);
Rating findById(String ratingId);
Rating findRatingByDriverId(String driverId);
RatingEntity createRating(final RatingCommand ratingCommand);
RatingEntity getOneAndCreate(final String accountId);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.nas.rating.service;


import com.nas.core.exception.BusinessException;
import com.nas.core.exception.ExceptionPayloadFactory;
import com.nas.core.util.JSONUtil;
import com.nas.rating.command.RatingCommand;
import com.nas.rating.models.Rating;
import com.nas.rating.models.RatingEntity;
import com.nas.rating.repository.RatingRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
Expand All @@ -22,13 +18,22 @@ public class RatingServiceImpl implements RatingService{


@Override
public Rating createRating(RatingCommand ratingCommand) {
public RatingEntity createRating(RatingCommand ratingCommand) {
log.info("[+] Begin creating Rating with payload {}", JSONUtil.toJSON(ratingCommand));
final Rating rating = Rating.create(ratingCommand);
final RatingEntity rating = RatingEntity.create(ratingCommand);
log.info("[+] Rating with id {} created successfully", rating.getId());
return ratingRepository.save(rating);
}

@Override
public RatingEntity getOneAndCreate(final String accountId){
log.info("[+] Begin creating Rating for account id {}", accountId);
final RatingEntity rating = RatingEntity.getOneAndCreate(accountId);
log.info("[+] Rating with id {} created successfully", rating.getId());
return ratingRepository.save(rating);
}

/*
@Override
public Page<Rating> getRatings(Pageable pageable) {
return ratingRepository.findAll(pageable);
Expand All @@ -49,5 +54,5 @@ public Rating findRatingByDriverId(String driverId) {
final Rating rating = ratingRepository.findRatingByUserId(driverId);
log.info("[+] Rating with id {} fetched successfully", rating.getId());
return rating;
}
}*/
}
2 changes: 1 addition & 1 deletion rating-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spring:
hibernate:
dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate:
ddl-auto: create-drop
ddl-auto: update
show-sql: true
datasource:
driverClassName: org.postgresql.Driver
Expand Down
4 changes: 0 additions & 4 deletions wallet-service/src/main/java/com/nas/wallet/model/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class Wallet extends BaseEntity{





@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Balance balance;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
@RequiredArgsConstructor
@Slf4j
public class WalletServiceImpl implements WalletService{

private final WalletRepository walletRepository;
private final RestTemplate restTemplate;


@Override
public Wallet create(String accountId) {
log.info("[+] Begin Fetching account with id {} ", accountId);
final Wallet wallet = Wallet.create(accountId);
log.info("[+] Account with id {} set successfully", accountId);
return walletRepository.save(wallet);
walletRepository.save(wallet);
restTemplate.getForObject(
"http://RATING:2018/v1/ratings/" + accountId, String.class, accountId
);
return wallet;
}

@Override
Expand Down
Loading

0 comments on commit dc6ab01

Please sign in to comment.