Skip to content

Development #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Images/already_has_been_added.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/brand_os_version.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/device_brand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/getAll.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/mobile_device_table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/os_type_not_defined.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/post_error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/post_success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/saveAll_post.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/save_post.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion README.md

This file was deleted.

36 changes: 36 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# CodeChallenge
Tüm veriler veri tabanına eklendi ve başarı mesajı döndürüldü

![Success Message From Post Method](https://github.com/fehimecapar/CodeChallenge/blob/development/Images/saveAll_post.png)

Tek veri veritabanına eklendi ve başarı mesajı döndürüldü

![error Message From Post Method](https://github.com/fehimecapar/CodeChallenge/blob/development/Images/save_post.png)

Tüm veriler ekranda gösterildi

![Message From get Method](https://github.com/fehimecapar/CodeChallenge/blob/development/Images/getAll.png)

İşletim sisteminin IOS ya da Android olması şartı eklendi. Yanlış veri ekleme durumunda hata mesajı gönderildi

![Message From get Method](https://github.com/fehimecapar/CodeChallenge/blob/development/Images/post_error.png)

Eklemeye çalışılan verinin daha önce veri tabanına kaydedilip kaydedilmediği kontrolü yapıldı. Eğer veri varsa ve eklemeye çalışıyorsak hata değerini ve eklemeye çalıştığımız data değerini döndürdü

![Message From brand Method](https://github.com/fehimecapar/CodeChallenge/blob/development/Images/already_has_been_added.png)

url: .../device?brand=apple

![Message From brand Method](https://github.com/fehimecapar/CodeChallenge/blob/development/Images/device_brand.png)


url: http://localhost:8080/md/devices?brand=Apple&osVersion=12.4.1&page=1&size=5

![Message From brand Method](https://github.com/fehimecapar/CodeChallenge/blob/development/Images/brand_os_version.png)

Mobile Device Tablosu

![Message From brand Method](https://github.com/fehimecapar/CodeChallenge/blob/development/Images/mobile_device_table.png)



7 changes: 6 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
package com.example.demo.controller;

import com.example.demo.model.MobileDeviceModel;
import com.example.demo.service.MobileDeviceServiceImp;
import com.example.demo.results.DataResult;
import com.example.demo.service.MobileDeviceService;
import com.example.demo.web.dto.MobileDeviceDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.HashSet;
import java.util.List;

@RequestMapping("/md")
@RestController
public class MobileDeviceController {

@Autowired
MobileDeviceServiceImp mobileDeviceServiceImp;
MobileDeviceService mobileDeviceService;

@PostMapping("/")
public void addMobileDevice(@RequestBody MobileDeviceModel model){
mobileDeviceServiceImp.addMobileDevice(model);
public MobileDeviceController(MobileDeviceService mobileDeviceService) {
this.mobileDeviceService = mobileDeviceService;
}
@GetMapping("/getall")
public HashSet<MobileDeviceModel> getAllMobileDevice(){
return mobileDeviceServiceImp.getAllMobileDevice();

@GetMapping("/getAll") // get all data
public DataResult<List<MobileDeviceDto>> getAllMobileDevice(){
return mobileDeviceService.getAllMobileDevice();
}

@GetMapping("/device") // fetch data by brand
public DataResult<List<MobileDeviceDto>> brandFilter(@RequestParam("brand") String brand){
return mobileDeviceService.brandFilter(brand);
}
@GetMapping("/devices") // fetch data by brand and osVersion
public DataResult<List<MobileDeviceDto>> brandAndOsVersionFilter(@RequestParam("brand") String brand, @RequestParam("osVersion")String osVersion,
@RequestParam("page") int page, @RequestParam("size") int size){
return mobileDeviceService.brandAndOsVersionFilter(brand, osVersion, page, size);
}

@PostMapping("/post")// save all data and multiple data
public DataResult addMobileDevices(@RequestBody List<MobileDeviceDto> modelDeviceDto) throws Exception {
return mobileDeviceService.addMobileDevices(modelDeviceDto);
}
@PostMapping("/save")//save just one data
public DataResult addMobileDevice(@RequestBody MobileDeviceDto modelDeviceDto) throws Exception {
return mobileDeviceService.addMobileDevice(modelDeviceDto);
}

}
23 changes: 15 additions & 8 deletions src/main/java/com/example/demo/model/MobileDeviceModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,32 @@

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import java.util.Objects;

//@Entity
@Entity
@Getter
@Setter
@NoArgsConstructor
@Table(name = "MobileDeviceTable")//table name
public class MobileDeviceModel {
/*

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
* */
@NotNull @NotEmpty
private String brand;
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="id")
public int id;

@Column(name="model")
@NotNull @NotEmpty
private String model;

@Column(name="brand")
@NotNull @NotEmpty
private String brand;

@Column(name="os")
@NotNull @NotEmpty
private String os;

@Column(name="osVersion")
@NotNull @NotEmpty
private String osVersion;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.demo.repository;

import com.example.demo.model.MobileDeviceModel;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface MobileDeviceRepository extends JpaRepository<MobileDeviceModel, Integer> {

List<MobileDeviceModel> findMobileDeviceModelsByBrand(String brand); // fetch data by brand name
List<MobileDeviceModel> findMobileDeviceModelsByBrandAndOsVersion(String brand, String osVersion, Pageable page); // fetch data by brand osVersion and page number


}
17 changes: 17 additions & 0 deletions src/main/java/com/example/demo/results/DataResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.demo.results;

public class DataResult<T> extends Result{
private T data;

public DataResult(T data, boolean success, String message) {
super(success,message);
this.data = data;
}
public DataResult(T data, boolean success) {
super(success);
this.data = data;
}
public T getData() {
return this.data;
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/example/demo/results/ErrorDataResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.demo.results;

public class ErrorDataResult<T> extends DataResult<T>{
public ErrorDataResult(T data, String message) {
super(data,false,message);
}

public ErrorDataResult(T data) {
super(data,false);
}

public ErrorDataResult(String message) {
super(null,false,message);
}

public ErrorDataResult() {
super(null,false);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/example/demo/results/ErrorResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.demo.results;

public class ErrorResult extends Result{

public ErrorResult() {
super(false);
}

public ErrorResult(String message) {
super(false,message);
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/example/demo/results/Result.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.demo.results;

public class Result {
private boolean success;
private String message;

public Result(boolean success) {
this.success = success;
}

public Result(boolean success, String message) {
this(success);
this.message = message;
}

public boolean isSuccess() {
return this.success;
}

public String getMessage() {
return this.message;
}
}
19 changes: 19 additions & 0 deletions src/main/java/com/example/demo/results/SuccessDataResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.demo.results;

public class SuccessDataResult<T> extends DataResult<T>{
public SuccessDataResult(T data, String message) {
super(data,true,message);
}

public SuccessDataResult(T data) {
super(data,true);
}

public SuccessDataResult(String message) {
super(null,true,message);
}

public SuccessDataResult() {
super(null,true);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/example/demo/results/SuccessResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.demo.results;

public class SuccessResult extends Result{

public SuccessResult() {
super(true);
}

public SuccessResult(String message) {
super(true,message);
}
}
12 changes: 8 additions & 4 deletions src/main/java/com/example/demo/service/MobileDeviceService.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.example.demo.service;

import com.example.demo.model.MobileDeviceModel;
import com.example.demo.results.DataResult;
import com.example.demo.web.dto.MobileDeviceDto;

import java.util.HashSet;
import java.util.List;

public interface MobileDeviceService {
DataResult<List<MobileDeviceDto>> getAllMobileDevice(); //get all data from MobileDevice table
DataResult<List<MobileDeviceDto>> addMobileDevices(List<MobileDeviceDto> mdlist) throws Exception; //add all datas or multiple data to MobileDevice table from devices.json file
DataResult<MobileDeviceDto> addMobileDevice(MobileDeviceDto md) throws Exception; //save one data to MobileDevice table

void addMobileDevice(MobileDeviceModel md); //add data to MobileDevice table
HashSet<MobileDeviceModel> getAllMobileDevice(); //get data from MobileDevice table
DataResult<List<MobileDeviceDto>> brandFilter(String brand); // for device?brand=any type url
DataResult<List<MobileDeviceDto>> brandAndOsVersionFilter(String brand, String osVersion, int page, int size); //for devices?brand=Apple&osVersion=12.4.1&page=1&size=5

}
Loading