Skip to content

Commit

Permalink
Merge pull request #14 from jaeseong-kim/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jaeseong-kim authored Oct 26, 2023
2 parents 8a8e3e9 + 69bad1d commit 7d26174
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 23 deletions.
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
email : [email protected]
password : subwhere0011

홈페이지 : [무슨역이Now](ec2-13-209-106-121.ap-northeast-2.compute.amazonaws.com:8083)
서비스 이용 : [무슨역이Now](http://ec2-13-209-106-121.ap-northeast-2.compute.amazonaws.com:8083)
노션 : [무슨역이Now](https://river-stool-2c7.notion.site/Now-cc118ca4f35c4d74be5391d2afcb28cc?pvs=4)

## 프로젝트 소개
내가 탄 지하철을 선택해서 지하철이 현재 무슨 역에 있는지 알 수 있는 서비스입니다.
지하철에 사람이 많아 무슨 역인지 보기 힘들어서 개발하게 되었습니다.
내가 탄 지하철을 선택해서 지하철이 현재 무슨 역에 있는지 알 수 있는 서비스입니다.
지하철을 탔을 때 차내 전광판 광고로 인해 역명이 안보이거나 플랫폼의 역명이 차체로 인해 안 보여서 개발하게 되었습니다.

## Stacks
### 환경
<img src="https://img.shields.io/badge/Github-181717?style=flat&logo=Github&logoColor=white">

### 개발
<img src="https://img.shields.io/badge/Java-lightgrey?style=flat"/> <img src="https://img.shields.io/badge/Spring Boot-grenn?style=flat&logo=Spring Boot&logoColor=6DB33F"/> <img src="https://img.shields.io/badge/MariaDB-003545?style=flat&logo=MariaDB&logoColor=white"/> <img src="https://img.shields.io/badge/Thymeleaf-005F0F?style=flat&logo=Thymeleaf&logoColor=white"/>
<img src="https://img.shields.io/badge/Java-lightgrey?style=flat"/> <img src="https://img.shields.io/badge/Spring Boot-grenn?style=flat&logo=Spring Boot&logoColor=6DB33F"/> <img src="https://img.shields.io/badge/Thymeleaf-005F0F?style=flat&logo=Thymeleaf&logoColor=white"/>

### DB
<img src="https://img.shields.io/badge/Amazon RDS-527FFF?logo=Amazon RDS&style=flat"/>
<img src="https://img.shields.io/badge/MariaDB-003545?style=flat&logo=MariaDB&logoColor=white"/> <img src="https://img.shields.io/badge/Amazon RDS-527FFF?logo=Amazon RDS&style=flat"/>

### OAuth
<img src="https://img.shields.io/badge/Google-4285F4?logo=Google&style=flat"/> <img src="https://img.shields.io/badge/Naver-03C75A?logo=Naver&style=flat"/>
Expand All @@ -32,5 +32,23 @@ password : subwhere0011
<img src="https://img.shields.io/badge/서울 지하철 실시간 위치-A6A9AA?style=flat&logoColor=white">

## DB ERD
![subwhere_ERD](https://github.com/jaeseong-kim/Subwhere/assets/61345774/f4a646cb-413b-49ea-9476-e637461b26bf)

## APPLICATION ARCHITECTURE
### member 테이블
간편 로그인한 회원 정보 저장

### my_train 테이블
탑승한 지하철 정보를 저장

## Sequence Diagram
### 지하철 탑승 페이지
![지하철_리스트_페이지](https://github.com/jaeseong-kim/Subwhere/assets/61345774/a04fc8ba-6da6-44f4-a7cc-3f09ad43a2f4)

### 지하철 탑승
![지하철_탑승](https://github.com/jaeseong-kim/Subwhere/assets/61345774/26c805cc-a81a-453a-a754-2791699b33a8)

### 내 지하철 저장
![내_지하철_저장](https://github.com/jaeseong-kim/Subwhere/assets/61345774/1be712d9-8ef6-407d-9d7b-ec324d1baac3)

### 지하철 하차
![지하철_하차](https://github.com/jaeseong-kim/Subwhere/assets/61345774/e8b4f22b-be99-4f0c-8335-916eed6bf628)
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.servlet.http.HttpSession;

@Controller
public class MainController {

@GetMapping("/")
public String index(Model model, HttpSession httpSession) {

SessionUser user = (SessionUser) httpSession.getAttribute("user");
public String index(Model model, @SessionAttribute(name = "user", required = false) SessionUser user) {

if (user != null) {
model.addAttribute("name", user.getName());
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/com/example/subwhere/controller/SubwayController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.subwhere.controller;

import com.example.subwhere.config.auth.SessionUser;
import com.example.subwhere.dto.JsonDto;
import com.example.subwhere.dto.TrainSaveDto;
import com.example.subwhere.dto.TrainViewDto;
import com.example.subwhere.service.SubwayService;
Expand All @@ -11,7 +10,6 @@
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -24,14 +22,22 @@ public class SubwayController {
private final SubwayService subwayService;

@GetMapping("/subway/line")
public String lineSelect() {
public String lineSelect(@SessionAttribute(name = "user", required = false) SessionUser user, Model model) {

if (user != null) {
model.addAttribute("name", user.getName());
}

return "subway/line-select";
}

@GetMapping("/subway/line/{lineName}")
public String trainList(@PathVariable String lineName, Model model) {
public String trainList(@PathVariable String lineName, @SessionAttribute(name = "user", required = false) SessionUser user,
Model model) {

log.info("lineName = {}", lineName);
if (user != null) {
model.addAttribute("name", user.getName());
}

model.addAttribute("trains", subwayService.getTrains(lineName));
model.addAttribute("subwayNm", lineName);
Expand All @@ -40,27 +46,25 @@ public String trainList(@PathVariable String lineName, Model model) {
}

@PostMapping("/user/train")
public String saveMyTrain(@ModelAttribute TrainSaveDto train, HttpSession httpSession) {

log.info("train.trainNo = {}, train.subwayNm = {}, httpSession.user = {}", train.getTrainNo(), train.getSubwayNm(),
httpSession.getAttribute("user"));
public String saveMyTrain(@ModelAttribute TrainSaveDto train, @SessionAttribute(name = "user", required = true) SessionUser user) {

SessionUser user = (SessionUser) httpSession.getAttribute("user");

if(!subwayService.alreadySaved(train.getTrainNo(), user.getEmail())){
if (!subwayService.alreadySaved(train.getTrainNo(), user.getEmail())) {
subwayService.saveTrain(train, user.getEmail());
}

return "redirect:/user/train";
}

@GetMapping("/user/train")
public String myTrainPage(Model model, HttpSession httpSession) {
public String myTrainPage(Model model, @SessionAttribute(name = "user", required = true) SessionUser user) {

SessionUser user = (SessionUser) httpSession.getAttribute("user");
if (user != null) {
model.addAttribute("name", user.getName());
}

List<String> myLineNames = subwayService.getMyLineName(user.getEmail());
if(myLineNames == null){
if (myLineNames == null) {
return "user/my-train";
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/example/subwhere/service/SubwayService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
Expand Down Expand Up @@ -127,4 +128,9 @@ public String deleteTrain(String trainNo, String email) {

return "선택한 지하철에서 내렸습니다.";
}

@Scheduled(cron="0 0 2 ? * SUN-SAT")
public void clearTrains(){
myTrainRepository.deleteAll();
}
}

0 comments on commit 7d26174

Please sign in to comment.