Commit Graph

137 Commits

Author SHA1 Message Date
SlimusMinus
838e4aa6d5 Merge pull request #60 from SlimusMinus/ci-github_actions
All checks were successful
deploy-backend / deploy (push) Successful in 1m22s
Add GitHub Actions CI: run gradle tests on PRs to master
2026-10-21 22:36:51 +03:00
SlimusMinus
d6c88f9e57 Add GitHub Actions CI: run gradle tests on PRs to master
Runs ./gradlew test (Temurin 25, Gradle cache, Testcontainers on the
runner's Docker) on every pull request to master and on push to master,
uploading build/reports/tests when tests fail. gradlew gets the
executable bit in git. The gitea deploy workflow is unchanged. README
describes the check and recommends making it required for master.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 22:27:59 +03:00
SlimusMinus
f660e6828b Merge pull request #59 from SlimusMinus/add_tests
All checks were successful
deploy-backend / deploy (push) Successful in 1m14s
added tests
2026-10-21 00:17:25 +03:00
SlimusMinus
0dba36f3aa added tests 2026-10-21 00:15:54 +03:00
SlimusMinus
7766fb0b07 Merge pull request #58 from SlimusMinus/fix-posts_api_stage2
All checks were successful
deploy-backend / deploy (push) Successful in 1m25s
Posts API stage 2: /posts/{id} is one post, drop userEmail and /posts…
2026-10-21 00:10:42 +03:00
SlimusMinus
d782bee645 Posts API stage 2: /posts/{id} is one post, drop userEmail and /posts/search
- GET /api/v1/posts/{id} returns a single post (owner-only for unpublished);
  /detail/{id} stays as an alias; user posts live at /api/v1/users/{userId}/posts
- POST /api/v1/posts Location points to /api/v1/posts/{id}
- PostResponse.userEmail removed (use userLogin); unused DialogResponse removed
- GET /api/v1/posts/search?city= removed (same filter: GET /api/v1/posts?city=)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 00:03:39 +03:00
SlimusMinus
13d09d0073 Merge pull request #57 from SlimusMinus/fix-posts_api_contract
All checks were successful
deploy-backend / deploy (push) Successful in 1m32s
Posts API: user posts page, 201 on create, userLogin, deprecate old r…
2026-10-20 22:58:32 +03:00
SlimusMinus
ee5fb4e0e0 Posts API: user posts page, 201 on create, userLogin, deprecate old routes
- GET /api/v1/users/{userId}/posts returns Page<PostResponse> (owner sees unpublished)
- POST /api/v1/posts returns 201 with the created PostResponse and Location
- PostResponse.userLogin; userEmail kept with the same value as deprecated
- GET /api/v1/posts/{userId} and /search?city= marked deprecated; search is paged
- CORS exposes Retry-After and Location to the frontend

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 11:50:05 +03:00
SlimusMinus
248b4de752 Merge pull request #56 from SlimusMinus/claude/backend-review-80c5df
Claude/backend review 80c5df
2026-10-20 01:50:51 +03:00
SlimusMinus
ba6935bb1f Document multi-instance setup, rate limits and the new ad flow
README: new environment variables, ShedLock jobs and the multi-instance
section, rate limits and login lockout, profile privacy and token reissue,
WebSocket fan-out, 429 errors, tests and the updated limitations.
docs/advertising.md: serve -> impression -> click with signed tokens,
per-campaign daily caps, stats endpoint, campaign auto-finish, ads.* settings.
docs/redis.md: all new keys, pub/sub, locks, rate limiting, failure modes.
docs/images-storage.md: uploads outside transactions and orphan cleanup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:46:18 +03:00
SlimusMinus
4ff61d8eda Delete orphan files from the image bucket nightly
OrphanFileCleanupService (03:30, ShedLock) lists the bucket and deletes objects
older than 24 hours that no images.url or users.avatar_url points to (full
URLs in legacy rows are normalised to keys), at most 5000 per run. Such files
appear when an upload via POST /api/v1/files is never attached or a request
fails between upload and save. Deleted files stay recoverable for 30 days as
noncurrent versions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:42:39 +03:00
SlimusMinus
3dcd27d08a Keep network calls out of post transactions; cache and throttle geocoding
- PostService.create/update geocode and upload photos before opening the DB
  transaction (TransactionTemplate); uploaded files are removed if the
  transaction fails, so a DB connection is no longer held while waiting for
  Nominatim or MinIO.
- GeocodingService: configurable URL and User-Agent (geocoding.*), results
  cached in Redis for 30 days by coordinates rounded to ~11 m, and a
  cluster-wide 1 request/s slot (geo:throttle) as the public Nominatim policy
  requires; city/district are cut to the column sizes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:41:03 +03:00
SlimusMinus
85a2773f60 Build the chat list with batch queries instead of five queries per chat
Interlocutors, posts, last messages (one subquery by max id) and unread counts
(one GROUP BY) are loaded per list. The last message is now picked by id:
createdAt is written in the sender's time zone and is not monotonic between
users in different zones.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:38:33 +03:00
SlimusMinus
2f52e6df70 Rework ad serving: signed impression tokens, per-campaign daily caps, stats
Follows the usual ad-server flow (serve -> impression -> click):
- GET /api/ads/next returns an impressionToken: HMAC-signed (ads.tracking.secret,
  defaults to jwt.secret) ad id, campaign id, subject and nonce, valid 1 hour.
  /impression and /click accept it, verify the signature, count each nonce once
  (Redis SET NX) and take the user/session from the token, so impressions
  cannot be forged or replayed. Requests without a token keep working until
  ads.tracking.require-token is switched on after the frontend update.
- The frequency cap is per campaign and calendar day (ads.timezone) and grows
  on real impressions, not on serving: ad:cap:<subject>:<campaign>:<yyyyMMdd>.
- Selection reads a 30-second in-memory snapshot of eligible ads (projection,
  invalidated locally on admin changes), filters capped campaigns with one
  MGET, picks by weight and then sets the cooldown atomically. The weighted
  sort drew random numbers inside the comparator, breaking its contract.
- Campaigns past endDate are finished every 10 minutes (ShedLock).
- GET /api/v1/admin/campaigns/{id}/stats: impressions, clicks and CTR per ad
  for a date range; composite indexes on impression/click (changelog 021).
- Removed unused cascade collections on Campaign/Advertising, the unused
  FullscreenAdActivateRequestDto and the /api/ads/impression/beacon rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:37:32 +03:00
SlimusMinus
477737c161 Hide private profile data and reissue tokens when users change their login
- GET /api/v1/users/{id} returns email and phone only to the user themself
  and to admins.
- When a user changes their own login, the PUT response carries a new token
  pair (login is the JWT subject, so the old tokens stop matching); old
  refresh tokens fail on their own because the stored login differs.
- The old avatar is deleted only after the profile is saved; login length is
  checked against the column size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:32:13 +03:00
SlimusMinus
48351398b5 Add Redis rate limiting, login lockout, password policy and health probes
- RateLimitFilter: fixed-window counters in Redis (Lua INCR+PEXPIRE) per
  client IP for login, registration, refresh, check-login, post creation,
  uploads, chat start and public ad endpoints; 429 with Retry-After; fails
  open when Redis is down. Rules live in rate-limit.* in application.yaml.
- Login is blocked for an account after 10 failed attempts in 15 minutes,
  independent of the client IP.
- Registration requires a password of at least 8 characters.
- server.forward-headers-strategy=native so the client IP survives a reverse
  proxy; graceful shutdown.
- /actuator/health with liveness/readiness probes is public (no details).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:31:12 +03:00
SlimusMinus
a696a21a1f Run safely with several instances: ShedLock jobs, Redis WebSocket fan-out
- Scheduled jobs (nightly cleanup, moderation, search dictionary rebuild) take
  a ShedLock lock in Redis, so only one instance runs each; the moderation run
  stops before its lock can expire.
- STOMP events (chat messages, unread counters, transcoding status) are
  published to the Redis channel ws:broadcast and every instance hands them to
  its local simple broker, so subscribers on other instances receive them.
  Falls back to local delivery if Redis is down; app.websocket.cluster-broadcast
  switches it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:31:12 +03:00
SlimusMinus
83270a8ece Rewrite README and add docs for advertising, Redis and image storage
README described Spring Boot 3.2.5/Java 21, an open /api/v1/test, the removed
MapCacheService and a single smoke test. It now matches the code: setup,
environment variables, architecture, packages, security rules, API, WebSocket
topics, post lifecycle, errors, tests, deploy and known limitations.

docs/advertising.md, docs/redis.md and docs/images-storage.md describe the
subsystems with references to the classes. .env.example lists the remaining
optional variables.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:15:37 +03:00
SlimusMinus
7b81c18614 Give STOMP sessions a principal so /user/queue/errors is delivered
ChatWebSocketController reports send errors with convertAndSendToUser, but
CONNECT never set a user on the session, so those messages had no recipient.
The interceptor now sets a principal named after the user id on the message's
own accessor and allows subscriptions to /user/queue/** (resolved per session
by Spring, so it cannot reach another user's queue).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:09:57 +03:00
SlimusMinus
6b647e0bbf Add tests for the review fixes and make the context test runnable
- ReFoundApplicationTests runs on PostgreSQL via Testcontainers with a test
  profile holding test-only JWT/Redis/MinIO values; it previously failed
  without JWT_SECRET. The test also checks Liquibase + ddl validate.
- Unit tests: JWT access/refresh separation, refresh rotation, admin
  authority, exception mapping, image signature checks, ad media Range
  responses, post deletion after commit, moderation races, campaign status,
  ad selection without HttpSession and with Redis down, target URL rules.
- resolveRange rejects ranges that start past the end of the file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:08:29 +03:00
SlimusMinus
3fd045131c Use ai.retry settings, add AI connect timeout, stop logging post text
AiRetryProperties was bound but @Retryable had hard-coded values, so
ai.retry.* in application.yaml had no effect. WebClient had no connect
timeout (Netty default 30 s per attempt). TextModerationProcessor logged the
whole moderation context, including post text, at INFO.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:04:30 +03:00
SlimusMinus
a909b1f08b Fix advertising admin flows, tracking endpoints and ffmpeg timeout
- createAdvertising saved an IMAGE ad without mediaKey and only then answered
  400; validation now happens first. Target URLs must be absolute http(s)
  (they end up in href on the client), DTOs get @NotNull/@NotBlank.
- confirm-upload accepted any sourceKey; the transcoder deletes the source
  afterwards, so another ad's finished video could be deleted. Keys must now
  belong to the ad's own sources/ prefix.
- Activating a fullscreen ad could hit uq_fullscreen_ad_single_active because
  Hibernate may flush the new ACTIVE row first; the old one is flushed first.
- Campaign status change answered with the previous status (bulk UPDATE vs
  stale entity).
- Impression/click used getReferenceById, so unknown ids failed with 500 on
  the FK at commit; session ids are trimmed to the 64-char column.
- /api/ads/next created a Tomcat HttpSession for every client without
  X-Session-Id and failed with 500 when Redis was down; it now falls back to
  the client IP and returns 204 on Redis errors.
- ffmpeg output was read before waitFor, so the 5-minute timeout never fired;
  output goes to a temp log and its tail is logged on failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:04:10 +03:00
SlimusMinus
6e001fbc41 Fix post deletion, moderation races and cache leftovers
- PostService.delete did not remove favorites (FK without cascade -> 500 once a
  post was favorited) or chat links; owner, admin and nightly cleanup now share
  PostDeletionService, which deletes MinIO files only after commit. The nightly
  job also removes the images of expired posts.
- Moderation reads a snapshot in a short transaction, calls AI outside of it and
  applies the verdict only if the post is still in MODERATION and unchanged, so
  an edit made during a check can no longer go live unmoderated. Storage/AI
  outages keep the post in MODERATION instead of rejecting it.
- Posts without a category broke PostMapper with an NPE; title/phone/reward and
  address are checked against column sizes; a long address no longer overflows
  posts.city; Nominatim outages fall back to the address instead of 503.
- Favorites list hides posts that are back in moderation or rejected.
- Statistics counters use atomic UPDATEs instead of read-modify-write.
- Removed MapCacheService: its version key was bumped but never read.
- hibernate.default_batch_fetch_size=50 removes N+1 on images/users; show-sql
  is off by default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 01:02:12 +03:00
SlimusMinus
98e6789b7e Validate image signatures, stream ad media with Range, keep live files in MinIO
- Uploaded images are checked by magic bytes; the key extension and stored
  Content-Type come from the detected format, not from the client's filename
  (an .html file sent as image/png was stored as <uuid>.html).
- /api/v1/ads-media streams from MinIO instead of loading whole videos into
  the heap, answers Range requests with 206 (iOS Safari needs it for video)
  and sets a long public Cache-Control for immutable keys.
- The bucket lifecycle rule expired every object after 180 days, including
  avatars and images of live posts; now only noncurrent versions expire.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 00:58:56 +03:00
SlimusMinus
5cd60b6318 Harden auth: separate access/refresh JWT, atomic refresh rotation, admin checks
- Refresh JWT carried no role but was accepted by JwtAuthenticationFilter and
  the STOMP CONNECT as an access token; tokens now carry a typ claim and the
  filters accept only access tokens (legacy tokens are told apart by role).
- Refresh rotation uses GETDEL, so one refresh token cannot be spent twice;
  refresh tokens are no longer written to logs.
- isCurrentUserAdmin and file deletion compared authorities with "ADMIN"
  instead of "ROLE_ADMIN", so admins were never recognised.
- getCurrentUser answers 401 for anonymous requests; profile update keeps the
  login when the field is not sent; registration rejects empty login/password.
- GlobalExceptionHandler turned AccessDenied, BadCredentials, EntityNotFound,
  Spring MVC 4xx errors and upload limits into 500.
- Presigned URL TTL is capped at 7 days.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 00:56:38 +03:00
SlimusMinus
71e69c4af8 Merge pull request #55 from SlimusMinus/fix/ai-moderation-mapping
All checks were successful
deploy-backend / deploy (push) Successful in 1m29s
fix AI moderation response mapping and long post text
2026-10-20 00:35:17 +03:00
SlimusMinus
a68b89981c fix AI moderation response mapping and long post text
The AI service returns snake_case JSON, so detectedLabels was always null
and blocked posts carried no labels. Map it with @JsonProperty("detected_labels").

Post text longer than the service limit (5000 chars) got 422, which became
AiBadRequestException and the post was rejected. Text is now sent in
overlapping chunks within ai.text-max-length; blank text is skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 00:33:31 +03:00
SlimusMinus
d63a3309fa Merge pull request #54 from SlimusMinus/image-optimization
All checks were successful
deploy-backend / deploy (push) Successful in 1m30s
compress uploaded images and cache proxied files
2026-10-19 23:45:03 +03:00
SlimusMinus
a564e6f97d compress uploaded images and cache proxied files
Photos from iPhone (3-10 MB, 12-24 MP) were stored and served as-is, so the
feed loaded slowly on first open. Images are now downscaled to 1600px,
rotated by EXIF and re-encoded as progressive JPEG on upload. The
/api/v1/files proxy now sends Cache-Control instead of Spring Security's
no-store, so images are not re-downloaded on every app open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 23:43:07 +03:00
SlimusMinus
91ceafe75b Merge pull request #53 from SlimusMinus/fix-empty_advert
All checks were successful
deploy-backend / deploy (push) Successful in 1m17s
fixed empty advertising
2026-10-19 01:22:52 +03:00
SlimusMinus
057cdddff6 fixed empty advertising 2026-10-19 01:22:08 +03:00
SlimusMinus
72486a54f7 Merge pull request #52 from SlimusMinus/full-text-search
All checks were successful
deploy-backend / deploy (push) Successful in 2m18s
fixed search and add hints
2026-10-18 23:48:33 +03:00
SlimusMinus
96b4be5e6f fixed search and add hints 2026-10-18 23:46:13 +03:00
SlimusMinus
c1b14da7b9 Merge pull request #51 from SlimusMinus/image-caching
All checks were successful
deploy-backend / deploy (push) Successful in 1m28s
fixed image caching
2026-10-15 01:32:56 +03:00
SlimusMinus
307c4ae432 fixed image caching 2026-10-15 01:32:17 +03:00
SlimusMinus
4d9cb9946d Merge pull request #50 from SlimusMinus/fix-ai_timeout
All checks were successful
deploy-backend / deploy (push) Successful in 1m29s
fixed ai image timeout
2026-10-15 00:49:40 +03:00
SlimusMinus
c83d41a036 fixed ai image timeout 2026-10-15 00:48:58 +03:00
SlimusMinus
13bb0c8503 Merge pull request #49 from SlimusMinus/add-adr_post
All checks were successful
deploy-backend / deploy (push) Successful in 2m9s
fixed address for map
2026-10-15 00:14:02 +03:00
SlimusMinus
03e2b36c8d fixed address for map 2026-10-15 00:13:19 +03:00
SlimusMinus
f8ccb15185 Merge pull request #48 from SlimusMinus/fix-address
All checks were successful
deploy-backend / deploy (push) Successful in 1m57s
fixed address for map
2026-10-15 00:02:58 +03:00
SlimusMinus
01ac227bdb fixed address for map 2026-10-15 00:02:10 +03:00
SlimusMinus
9eae82f6df Merge pull request #47 from SlimusMinus/chat-on-first-message
All checks were successful
deploy-backend / deploy (push) Successful in 1m23s
create chats only together with the first message
2026-10-13 01:50:06 +03:00
SlimusMinus
cd0d2a4081 create chats only together with the first message
- GET /api/v1/chats/with/{otherUserId}?postId= finds an existing chat
  (404 if there is none) and never creates one
- POST /api/v1/chats/with/{otherUserId}/messages?postId= with {content}
  finds or creates the chat and saves the first message in one
  transaction; same participant/post checks as before, WebSocket events
  still sent after commit
- the old POST /with/{otherUserId} that created empty chats is removed
- chat list hides chats without messages (existing empty rows stay in DB)
- empty messages are rejected with 400

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-13 01:45:18 +03:00
SlimusMinus
73463f6c5b Merge pull request #46 from SlimusMinus/fix-chat-per-post
All checks were successful
deploy-backend / deploy (push) Successful in 1m21s
Fix chat per post
2026-10-13 01:34:17 +03:00
SlimusMinus
da7d68c31a add ChatService tests for creating a chat about an ad
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-13 01:31:33 +03:00
SlimusMinus
45c4273ea8 fix chats: one chat per ad, ordering, delivery after commit, errors
A chat was unique per user pair, so contacting the same author about a
second ad returned the old chat with the old post_id, and the chat list
showed the other ad's title and image.

- chats are unique per (user_one_id, user_two_id, post_id); migration 015
  drops the old pair constraint whatever its name and adds the new one
- getOrCreateChat looks the chat up by users and post, and checks that the
  other user exists and the post belongs to one of the participants
- chat list is sorted by last message time (chat creation as fallback)
- WebSocket message and unread events are sent only after commit
- chat errors are ApiException: 404 not found, 403 not a participant,
  400 validation; messages are limited to 4000 characters
- Post.images ordered by id so the cover image is stable everywhere

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-13 01:23:09 +03:00
SlimusMinus
008852c781 Merge pull request #45 from SlimusMinus/fix-feed-pagination
All checks were successful
deploy-backend / deploy (push) Successful in 1m23s
fix feed pagination order, moderation reject and cache invalidation
2026-10-13 01:10:47 +03:00
SlimusMinus
d19f03d412 fix feed pagination order, moderation reject and cache invalidation
- getFeed: add id DESC as tie-breaker so posts with equal createdAt
  are not duplicated or lost between pages
- moderation: AI verdict false now sets REJECTED instead of ACTIVE
- nightly cleanup: invalidate feed and map caches after deleting posts

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-13 01:07:26 +03:00
SlimusMinus
5ea7b438f5 Merge pull request #44 from SlimusMinus/fix-get_image
All checks were successful
deploy-backend / deploy (push) Successful in 1m27s
fixed getting image from minio
2026-10-13 00:43:45 +03:00
SlimusMinus
9dbf2dd043 fixed getting image from minio 2026-10-13 00:43:06 +03:00