Commit 559d62ce authored by Naren Medarametla's avatar Naren Medarametla

Merge branch 'shiva_demo_branch' into 'master'

[EPE-001] Added a service  to get all offers from the database.

See merge request !1
parents 92934983 d78c4936
9
README.md,8/e/8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d
<
build.gradle,f/0/f07866736216be0ee2aba49e392191aeae700a35
e
5src/main/java/com/nisum/epe/demo/DemoApplication.java,e/b/ebe90d1bc78bfc48f6e90bcf80a57a32a5102e55
\ No newline at end of file
...@@ -16,6 +16,8 @@ dependencies { ...@@ -16,6 +16,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'com.h2database:h2' runtimeOnly 'com.h2database:h2'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') { testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
} }
......
package com.nisum.epe.demo.controller;
import com.nisum.epe.demo.model.Offer;
import com.nisum.epe.demo.service.OfferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class OfferDemoController {
@Autowired
private OfferService offerService;
@GetMapping("/getOffers")
public List<Offer> getAllOffers(){
return offerService.getAllOffers();
}
}
package com.nisum.epe.demo.dao;
import com.nisum.epe.demo.model.Offer;
import org.springframework.data.repository.CrudRepository;
public interface OfferRepo extends CrudRepository<Offer, String> {
}
package com.nisum.epe.demo.model;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldDefaults;
@Data
@AllArgsConstructor
@NoArgsConstructor
@FieldDefaults(makeFinal = false,level = AccessLevel.PRIVATE)
public class Offer {
String offerId;
String offerName;
String offerDescription;
Integer usageLimit;
}
package com.nisum.epe.demo.service;
import com.nisum.epe.demo.dao.OfferRepo;
import com.nisum.epe.demo.model.Offer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
@Service
public class OfferService {
@Autowired
private OfferRepo offerRepo;
public List<Offer> getAllOffers() {
List<Offer> offers = new ArrayList<>();
offerRepo.findAll().forEach(t -> offers.add(t));
return offers;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment