My learning diary

File Upload to Spring Boot

Implementing file uploads through GraphQL was something I never managed to succeed in. Got embroiled in type incompatibilities. And eventually, I gave up and implemented a separate but simple API endpoint just for file uploads. So here’s the design: The user clicks “Submit”. The files get uploaded first. Upon upload, the server returns IDs. And the rest of the form data plus the returned IDs are sent to the GraphQL endpoint.

Continue reading "File Upload to Spring Boot"

Spring Boot Interceptors

A neat trick to log HTTP requests and responses in a Spring Boot project is through interceptors. To log requests and responses between the client and the server, I use the HandlerInterceptor (Introduction to Spring MVC HandlerInterceptor). To create this interceptor, simply extend the HandlerInterceptor interface. By overriding the various methods available, you can intercept the request and/or response at different points of time. For example, preHandle is executed before the request is executed (i.

Continue reading "Spring Boot Interceptors"

Truncating Strings With CSS

A few days ago, I would not have realised truncating strings by number of lines with CSS was possible. I was beginning to sweat when I received a request to truncate strings by number of lines instead of number of characters. To be fair, only SWEs would think of truncating by number of characters instead of line numbers… My teammate shared an answer he found at CSS-Tricks. If I recall, it didn’t work out for me because of the way the containers were styled.

Continue reading "Truncating Strings With CSS"

Reach Router Match

I use Reach Router. I have a component which isn’t a child of Router, so it does not have the useLocation hook. But I need to access the current URL in that component. Here’s how I did it after seeing Jacek’s hint: <div> <Match path="/*"> {(props) => ( <MyComponent path="/*" match={props.match ?? ''} /> )} </Match> <Router> ... </Router> </div> interface Props { match: any; } export const MyComponent: FC<Props> = (props: Props) => { const pathname = props.

Continue reading "Reach Router Match"

Numerical IDs in MongoDB

Auto-generated IDs in MongoDB are “strange” strings. I quote “strange” because they are actually derived not out of nowhere despite looking like they had nothing to do with anything. But to users, these IDs are strange. I had a collection of documents with a name property. Originally, name was annotated with @Id. But it meant that I could not change the value of name. name was also annotated with regex validation (@Pattern(.

Continue reading "Numerical IDs in MongoDB"