Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Alfex4936/chulbong-kr into …
Browse files Browse the repository at this point in the history
…develop
  • Loading branch information
2YH02 committed Jun 27, 2024
2 parents 62e53ee + 5446e78 commit a7c15e5
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 58 deletions.
3 changes: 2 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ fonts/logo-text.png
markers.bleve
service/marker_facility_service.go
marker_rss.xml
deploy.ps1
deploy.ps1
marker_facility_service.go
46 changes: 46 additions & 0 deletions backend/service/marker_facility_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package service
import (
"errors"
"fmt"
"io"
"net/http"
"regexp"
"strconv"
"strings"
"time"

"github.com/goccy/go-json"
Expand Down Expand Up @@ -285,6 +288,49 @@ func (s *MarkerFacilityService) FetchRegionFromAPI(latitude, longitude float64)
return doc.AddressName, nil // Address data is empty but no error occurred
}

// FetchEnglishAddress fetches the English address for a given Korean address from the website.
func (s *MarkerFacilityService) FetchEnglishAddress(koreanAddress string) (string, error) {
// URL encode the Korean address
encodedAddress := strings.ReplaceAll(koreanAddress, " ", "+")
reqURL := fmt.Sprintf("https://www.jusoen.com/addreng.asp?p1=%s", encodedAddress)

req, err := http.NewRequest(http.MethodGet, reqURL, nil)
if err != nil {
return "", fmt.Errorf("creating request: %w", err)
}

req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36")
// Create a new HTTP request

resp, err := s.HTTPClient.Do(req)
if err != nil {
return "", fmt.Errorf("error making HTTP request: %w", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}

// Read the response body
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("error reading response body: %w", err)
}

// Use regex to find the English address in the response body
re := regexp.MustCompile(`<strong>([^<]+)</strong>`)
matches := re.FindStringSubmatch(string(body))
if len(matches) < 2 {
return "", fmt.Errorf("could not find English address in response")
}

// Remove commas from the address
englishAddress := strings.ReplaceAll(matches[1], ",", "")

return englishAddress, nil
}

// FetchWeatherFromAddress
func (s *MarkerFacilityService) FetchWeatherFromAddress(latitude, longitude float64) (*kakao.WeatherRequest, error) {
wcongnamul := util.ConvertWGS84ToWCONGNAMUL(latitude, longitude)
Expand Down
8 changes: 4 additions & 4 deletions backend/service/report_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *ReportService) GetAllReports() ([]dto.MarkerReportResponse, error) {
const query = `
SELECT r.ReportID, r.MarkerID, r.UserID, ST_X(r.Location) AS Latitude, ST_Y(r.Location) AS Longitude,
ST_X(r.NewLocation) AS NewLatitude, ST_Y(r.NewLocation) AS NewLongitude,
r.Description, r.CreatedAt, r.Status, COALESCE(p.PhotoURL, '')
r.Description, r.CreatedAt, r.Status, r.DoesExist, COALESCE(p.PhotoURL, '')
FROM Reports r
LEFT JOIN ReportPhotos p ON r.ReportID = p.ReportID
ORDER BY r.CreatedAt DESC
Expand All @@ -48,7 +48,7 @@ func (s *ReportService) GetAllReports() ([]dto.MarkerReportResponse, error) {
url string
)
if err := rows.Scan(&r.ReportID, &r.MarkerID, &r.UserID, &r.Latitude, &r.Longitude,
&r.NewLatitude, &r.NewLongitude, &r.Description, &r.CreatedAt, &r.Status, &url); err != nil {
&r.NewLatitude, &r.NewLongitude, &r.Description, &r.CreatedAt, &r.Status, &r.DoesExist, &url); err != nil {
return nil, err
}
// Check if the URL is not empty before appending
Expand Down Expand Up @@ -139,8 +139,8 @@ func (s *ReportService) CreateReport(report *dto.MarkerReportRequest, form *mult
defer tx.Rollback() // Ensure the transaction is rolled back in case of error

// Insert the main report record
const reportQuery = `INSERT INTO Reports (MarkerID, UserID, Location, NewLocation, Description) VALUES (?, ?, ST_PointFromText(?, 4326), ST_PointFromText(?, 4326), ?)`
res, err := tx.Exec(reportQuery, report.MarkerID, report.UserID, fmt.Sprintf("POINT(%f %f)", report.Latitude, report.Longitude), fmt.Sprintf("POINT(%f %f)", report.NewLatitude, report.NewLongitude), report.Description)
const reportQuery = `INSERT INTO Reports (MarkerID, UserID, Location, NewLocation, Description, DoesExist) VALUES (?, ?, ST_PointFromText(?, 4326), ST_PointFromText(?, 4326), ?, ?)`
res, err := tx.Exec(reportQuery, report.MarkerID, report.UserID, fmt.Sprintf("POINT(%f %f)", report.Latitude, report.Longitude), fmt.Sprintf("POINT(%f %f)", report.NewLatitude, report.NewLongitude), report.Description, report.DoesExist)
if err != nil {
return fmt.Errorf("failed to insert report: %w", err)
}
Expand Down
43 changes: 4 additions & 39 deletions backend/service/user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"sort"
"strings"
"time"

"github.com/Alfex4936/chulbong-kr/dto"
"github.com/Alfex4936/chulbong-kr/model"
Expand Down Expand Up @@ -141,7 +139,7 @@ func (s *UserService) GetAllReportsByUser(userID int) ([]dto.MarkerReportRespons
const query = `
SELECT r.ReportID, r.MarkerID, r.UserID, ST_X(r.Location) AS Latitude, ST_Y(r.Location) AS Longitude,
ST_X(r.NewLocation) AS NewLatitude, ST_Y(r.NewLocation) AS NewLongitude,
r.Description, r.CreatedAt, r.Status, p.PhotoURL
r.Description, r.CreatedAt, r.Status, r.DoesExist, p.PhotoURL
FROM Reports r
LEFT JOIN ReportPhotos p ON r.ReportID = p.ReportID
WHERE r.UserID = ?
Expand All @@ -160,7 +158,7 @@ func (s *UserService) GetAllReportsByUser(userID int) ([]dto.MarkerReportRespons
url sql.NullString // Use sql.NullString to handle possible NULL values from PhotoURL
)
if err := rows.Scan(&r.ReportID, &r.MarkerID, &r.UserID, &r.Latitude, &r.Longitude,
&r.NewLatitude, &r.NewLongitude, &r.Description, &r.CreatedAt, &r.Status, &url); err != nil {
&r.NewLatitude, &r.NewLongitude, &r.Description, &r.CreatedAt, &r.Status, &r.DoesExist, &url); err != nil {
return nil, err
}
if report, exists := reportMap[r.ReportID]; exists {
Expand Down Expand Up @@ -201,6 +199,7 @@ func (s *UserService) GetAllReportsForMyMarkersByUser(userID int) ([]dto.MarkerR
r.Description,
r.CreatedAt,
r.Status,
r.DoesExist,
rp.PhotoURL
FROM
Reports r
Expand All @@ -224,7 +223,7 @@ func (s *UserService) GetAllReportsForMyMarkersByUser(userID int) ([]dto.MarkerR
url sql.NullString // Use sql.NullString to handle possible NULL values from PhotoURL
)
if err := rows.Scan(&r.ReportID, &r.MarkerID, &r.UserID, &r.Latitude, &r.Longitude,
&r.NewLatitude, &r.NewLongitude, &r.Description, &r.CreatedAt, &r.Status, &url); err != nil {
&r.NewLatitude, &r.NewLongitude, &r.Description, &r.CreatedAt, &r.Status, &r.DoesExist, &url); err != nil {
return nil, err
}
if report, exists := reportMap[r.ReportID]; exists {
Expand Down Expand Up @@ -346,37 +345,3 @@ func fetchNewUser(tx *sqlx.Tx, userID int64) (*model.User, error) {
}
return &newUser, nil
}

func mapToSliceWithSorting(reportMap map[int][]dto.MarkerReportResponse) []dto.MarkerReportResponse {
// Create a slice to hold all the reports grouped by markers
type markerWithReports struct {
MarkerID int
Reports []dto.MarkerReportResponse
Latest time.Time
}

markerReports := make([]markerWithReports, 0, len(reportMap))
for markerID, reports := range reportMap {
// Since reports are already sorted by CreatedAt DESC within each marker group,
// the first report's CreatedAt will be the latest report time.
latestTime := reports[0].CreatedAt
markerReports = append(markerReports, markerWithReports{
MarkerID: markerID,
Reports: reports,
Latest: latestTime,
})
}

// Sort marker groups by the latest report's CreatedAt DESC
sort.Slice(markerReports, func(i, j int) bool {
return markerReports[i].Latest.After(markerReports[j].Latest)
})

// Flatten the sorted marker groups into a single slice
reports := make([]dto.MarkerReportResponse, 0)
for _, mr := range markerReports {
reports = append(reports, mr.Reports...)
}

return reports
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ const ReportList = ({ id, count, reports }: Props) => {
const [toggle, setToggle] = useState(false);

if (!data)
return <Skeleton className="bg-black-light-2 mb-4 p-2 rounded-sm" />;
return (
<Skeleton className="bg-black-light-2 mb-4 w-full h-20 rounded-sm" />
);

return (
<Fragment>
<button
className="flex items-center justify-between text-left w-full bg-black-light-2 mb-4 p-3 rounded-sm"
className={`flex items-center justify-between text-left w-full bg-black-light-2 mb-4 p-3 rounded-sm`}
onClick={() => setToggle((prev) => !prev)}
>
<div className="w-full">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ interface Props {

const ReportListContainer = ({ data }: Props) => {
const reportItems = Object.entries(data.markers).map(([key, reports]) => (
<div key={key} className="">
<ReportList id={Number(key)} count={reports.length} reports={reports}/>
<div key={key}>
<ReportList id={Number(key)} count={reports.length} reports={reports} />
</div>
));
return <div>{reportItems}</div>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const MyreportClient = () => {
}
}

if (isLoading) <Skeleton className="bg-black-light-2 mb-4 p-2 rounded-sm" />;
if (isLoading) <Skeleton className="bg-black-light-2 mb-4 w-full h-20 rounded-sm" />;

if (!data) return <div className="text-center">받은 요청이 없습니다.</div>;

Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/(navbar)/mypage/myreport/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import instance from "@/api/instance";
import BlackSideBody from "@/components/atom/BlackSideBody";
import PrevHeader from "@/components/atom/PrevHeader";
import {
HydrationBoundary,
QueryClient,
dehydrate,
HydrationBoundary,
QueryClient,
dehydrate,
} from "@tanstack/react-query";
import { cookies } from "next/headers";
import MyreportClient from "./myreportClient";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const ReviewList = ({ markerId }: Props) => {
}

return (
<div>
<div className="min-h-40 pb-4">
{review?.pages[0].comments.length === 0 && (
<div>등록된 리뷰가 없습니다.</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/(navbar)/pullup/[id]/pullupClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ const PullupClient = ({ markerId }: Props) => {

{tabName === "review" && (
<div className="flex flex-col justify-center items-center fixed bottom-0 left-0 bg-black h-14 w-full px-9 z-50
mo:bottom-16">
mo:bottom-[70px]">
<div className="flex items-center justify-center w-full h-10 bg-black-light-2 px-3 rounded-3xl">
<input
type="text"
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/atom/PrevHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const PrevHeader = ({ url, text, back = false }: Props) => {
>
<ArrowLeftIcon />
</button>
{text && <span>{text}</span>}
{text && <span className="truncate">{text}</span>}
</div>
);
}
Expand All @@ -43,7 +43,7 @@ const PrevHeader = ({ url, text, back = false }: Props) => {
>
<ArrowLeftIcon />
</Link>
{text && <span>{text}</span>}
{text && <span className="truncate">{text}</span>}
</div>
);
}
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/layout/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const Navigation = () => {

return (
<div
className="w-16 h-screen bg-black-light shadow-xl p-4 z-20 mo:w-screen mo:h-16 mo:fixed mo:bottom-0 mo:flex
mo:items-center mo:pl-0 mo:pr-0 mo:border-t mo:border-solid"
className="w-16 h-screen bg-black-light shadow-xl p-4 z-20 mo:w-screen mo:fixed mo:bottom-0 mo:flex mo:flex-col
mo:items-center mo:justify-center mo:border-t mo:border-solid mo:p-0 mo:h-[70px]"
>
<div
className="flex flex-col items-center mo:flex-row mo:max-w-[430px] mo:w-full
Expand Down Expand Up @@ -92,6 +92,7 @@ const Navigation = () => {
/>
</div>
</div>
<div className="w-full h-4 web:hidden" />
</div>
);
};
Expand Down

0 comments on commit a7c15e5

Please sign in to comment.