-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
modules added for city&area management
- Loading branch information
Showing
18 changed files
with
864 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/example/foodOrderApp/conroller/AreaController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.example.foodOrderApp.conroller; | ||
|
||
import com.example.foodOrderApp.entity.Area; | ||
import com.example.foodOrderApp.service.AreaService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/area-rest") | ||
public class AreaController { | ||
|
||
@Autowired | ||
private AreaService areaService; | ||
|
||
@PostMapping("/add") | ||
public ResponseEntity addAreas(@RequestBody List<Area> areaList){ | ||
areaService.addAreas(areaList); | ||
return new ResponseEntity(HttpStatus.OK); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/example/foodOrderApp/conroller/CityController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.foodOrderApp.conroller; | ||
|
||
import com.example.foodOrderApp.entity.City; | ||
import com.example.foodOrderApp.service.CityService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/city-rest") | ||
public class CityController { | ||
|
||
@Autowired | ||
private CityService cityService; | ||
|
||
@PostMapping("/add-list") | ||
public ResponseEntity addCities(@RequestBody List<City> cities){ | ||
cityService.addCities(cities); | ||
return new ResponseEntity(HttpStatus.CREATED); | ||
} | ||
|
||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/example/foodOrderApp/conroller/DashboardController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,55 @@ | ||
package com.example.foodOrderApp.conroller; | ||
|
||
import com.example.foodOrderApp.entity.Area; | ||
import com.example.foodOrderApp.entity.City; | ||
import com.example.foodOrderApp.service.AreaService; | ||
import com.example.foodOrderApp.service.CityService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
|
||
import java.util.List; | ||
|
||
@Controller | ||
public class DashboardController { | ||
|
||
@Autowired | ||
private CityService cityService; | ||
|
||
@Autowired | ||
private AreaService areaService; | ||
@GetMapping("/login") | ||
public String loginPage(){ | ||
return "login"; | ||
} | ||
|
||
@GetMapping("/index") | ||
public String index(){ | ||
return "index"; | ||
} | ||
|
||
@GetMapping("/city") | ||
public String mangeCity(Model model){ | ||
List<City> cityList = cityService.getAllCities(); | ||
model.addAttribute("cities",cityList); | ||
return "cityTable :: citytable"; | ||
} | ||
|
||
@GetMapping("/area") | ||
public String mageArea(Model model){ | ||
List<Area> areaList = areaService.getAreas(); | ||
model.addAttribute("areas",areaList); | ||
return "areaTable :: areatable"; | ||
} | ||
|
||
@GetMapping("/add-area") | ||
public String addArea(){ | ||
return "addArea :: areaform"; | ||
} | ||
|
||
@GetMapping("/add-city") | ||
public String addCity(){ | ||
return "addCity :: cityform"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.foodOrderApp.entity; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.*; | ||
|
||
@Entity | ||
@Builder | ||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Area { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private long id; | ||
|
||
private String areaName; | ||
|
||
private String cityName; | ||
private String description; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.example.foodOrderApp.entity; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.*; | ||
|
||
@Entity | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
public class City { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private long id; | ||
|
||
private String cityName; | ||
|
||
private String description; | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/example/foodOrderApp/repository/AreaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.foodOrderApp.repository; | ||
|
||
import com.example.foodOrderApp.entity.Area; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface AreaRepository extends JpaRepository<Area,Long> { | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/foodOrderApp/repository/CityRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.example.foodOrderApp.repository; | ||
|
||
import com.example.foodOrderApp.entity.City; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CityRepository extends JpaRepository<City,Long> { | ||
|
||
City findCityByCityName(String name); | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/example/foodOrderApp/service/AreaService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.example.foodOrderApp.service; | ||
|
||
import com.example.foodOrderApp.entity.Area; | ||
|
||
import java.util.List; | ||
|
||
public interface AreaService { | ||
|
||
void addAreas(List<Area> areaList); | ||
List<Area> getAreas(); | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/example/foodOrderApp/service/AreaServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.example.foodOrderApp.service; | ||
|
||
import com.example.foodOrderApp.entity.Area; | ||
import com.example.foodOrderApp.repository.AreaRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class AreaServiceImpl implements AreaService{ | ||
|
||
@Autowired | ||
private AreaRepository areaRepository; | ||
@Override | ||
public void addAreas(List<Area> areaList) { | ||
areaRepository.saveAll(areaList); | ||
} | ||
|
||
@Override | ||
public List<Area> getAreas() { | ||
return areaRepository.findAll(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/example/foodOrderApp/service/CityService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.example.foodOrderApp.service; | ||
|
||
import com.example.foodOrderApp.entity.City; | ||
|
||
import java.util.List; | ||
|
||
public interface CityService { | ||
|
||
void addCities(List<City> cities); | ||
List<City> getAllCities(); | ||
City addCity(City city); | ||
|
||
City updateCity(City city); | ||
void deleteCity(City city); | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/example/foodOrderApp/service/CityServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.example.foodOrderApp.service; | ||
|
||
import com.example.foodOrderApp.entity.City; | ||
import com.example.foodOrderApp.repository.CityRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
public class CityServiceImpl implements CityService{ | ||
|
||
@Autowired | ||
private CityRepository cityRepository; | ||
|
||
@Override | ||
public void addCities(List<City> cities) { | ||
cityRepository.saveAll(cities); | ||
} | ||
|
||
@Override | ||
public List<City> getAllCities() { | ||
return cityRepository.findAll(); | ||
} | ||
|
||
@Override | ||
public City addCity(City city) { | ||
return cityRepository.save(city); | ||
} | ||
|
||
@Override | ||
public City updateCity(City city) { | ||
City temp = cityRepository.findById(city.getId()).orElseThrow(); | ||
temp.setCityName(city.getCityName()); | ||
temp.setDescription(city.getDescription()); | ||
return cityRepository.save(temp); | ||
} | ||
|
||
@Override | ||
public void deleteCity(City city) { | ||
cityRepository.delete(city); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
server: | ||
port: 8081 | ||
|
||
spring: | ||
datasource: | ||
driver-class-name: org.postgresql.Driver | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" lang="en"> | ||
|
||
<form class="card" th:fragment="areaform" > | ||
<div class="card-header"> | ||
<h3 class="card-title">Add Area</h3> | ||
</div> | ||
<div class="card-body"> | ||
<div class="mb-3"> | ||
<label class="form-label required">City Name</label> | ||
<div class="ts-wrapper form-select multi"><div class="ts-control"><input tabindex="0" role="combobox" aria-haspopup="listbox" aria-expanded="false" aria-controls="select-tags-ts-dropdown" id="select-tags-ts-control" placeholder="Select City" type="select-multiple"></div></div> | ||
</div> | ||
<div class="mb-3"> | ||
<label class="form-label required">Area Name</label> | ||
<div> | ||
<input type="text" class="form-control" aria-describedby="emailHelp" placeholder="Enter city name"> | ||
</div> | ||
</div> | ||
<div class="mb-3"> | ||
<label class="form-label required">Area Description</label> | ||
<div> | ||
<textarea class="form-control" name="example-textarea-input" rows="1" placeholder="Add city discription" data-lt-tmp-id="lt-900098" spellcheck="false" data-gramm="false"></textarea> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="card-footer text-end"> | ||
<button type="submit" class="btn btn-primary">Save</button> | ||
</div> | ||
</form> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" lang="en"> | ||
|
||
<form class="card" th:fragment="cityform"> | ||
<div class="card-header"> | ||
<h3 class="card-title">Add City</h3> | ||
</div> | ||
<div class="card-body"> | ||
<div class="mb-3"> | ||
<label class="form-label required">City Name</label> | ||
<div> | ||
<input type="text" class="form-control" aria-describedby="emailHelp" placeholder="Enter city name"> | ||
</div> | ||
</div> | ||
<div class="mb-3"> | ||
<label class="form-label required">City Description</label> | ||
<div> | ||
<textarea class="form-control" name="example-textarea-input" rows="1" placeholder="Add city discription" data-lt-tmp-id="lt-900098" spellcheck="false" data-gramm="false"></textarea> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="card-footer text-end"> | ||
<button type="submit" class="btn btn-primary">Save</button> | ||
</div> | ||
</form> | ||
|
||
</html> |
Oops, something went wrong.